Loading
[Clang] prevent crash in delayed default-argument lambda captures (#176749)
Fixes #176534
---
This patch resolves a crash when parsing delayed default arguments that
contain lambda expressions.
```cpp
struct S {
void f(int x, int = sizeof([x] { return x; }()));
};
```
When late-parsing default arguments that contain lambdas, `Sema` builds
a `FunctionScopes` stack containing only the lambda scope
(`FunctionScopes.size()` equals 1), however, `tryCaptureVariable`
expects an enclosing function scope outside the lambda scope
https://github.com/llvm/llvm-project/blob/41e231cae38028473dd327e8de5f65792b521ffe/clang/lib/Sema/SemaExpr.cpp#L19473-L19474
https://github.com/llvm/llvm-project/blob/41e231cae38028473dd327e8de5f65792b521ffe/clang/lib/Sema/SemaExpr.cpp#L19518
Scope capture handling logic decrements `FunctionScopesIndex` to align
declaration contexts
https://github.com/llvm/llvm-project/blob/41e231cae38028473dd327e8de5f65792b521ffe/clang/lib/Sema/SemaExpr.cpp#L19696
and later relies on it when traversing and accessing outer scopes
https://github.com/llvm/llvm-project/blob/41e231cae38028473dd327e8de5f65792b521ffe/clang/lib/Sema/SemaExpr.cpp#L19522-L19524
preserving the function scope in the late-parsing path prevents invalid
traversal during lambda capture handling