[clang] [Sema] Fix crash on function declaration inside nested expansion statements (PR #211649)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 23 22:18:58 PDT 2026
ojhunt wrote:
Ok so the issue here is that we're not setting up the correct scope when entering an expansion statement.
Some component of the scope is already wrong with just a single level, which you can see with:
```cpp
int bar();
void foo1() {
void bar(); // error
}
void foo2() {
template for (auto x : {1}) {
void bar(); // should error but does not
}
}
void foo3() { // your testcase
template for (auto x : {1}) {
template for (auto y : {1}) {
void bar(); // should error but triggers an assertion
}
}
}
```
foo2 does not trip the assertion because for whatever reason isOutOfLine() returns false, resulting in the assertion branch being bypassed.
foo3 does trip the assertion because isOutOfLine() returns true and so it encounters an expansion scope when it does not expect it.
I would guess isOutOfLine() is behaving correctly, and the actual root problem is that there's some other element of the scope construction going wrong.
Regardless, the assertion is _correct_, the state is wrong.
@cor3ntin @mizvekov @AaronBallman thoughts on actual root cause?
https://github.com/llvm/llvm-project/pull/211649
More information about the cfe-commits
mailing list