[clang] [clang-format] Fix '!Scopes.empty()' assertion in parseBrace (PR #199098)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 6 12:18:46 PDT 2026
================
@@ -1214,9 +1214,11 @@ class AnnotatingParser {
unsigned CommaCount = 0;
while (CurrentToken) {
- assert(!Scopes.empty());
+ if (Scopes.empty())
+ return false;
if (CurrentToken->is(tok::r_brace)) {
- assert(Scopes.back() == getScopeType(OpeningBrace));
+ if (Scopes.back() != getScopeType(OpeningBrace))
----------------
HazardyKnusperkeks wrote:
> Yes, it happens — it's not just a defensive change.
>
> hit by `enum E { { ? } a }` , outer `{` pushes ST_Enum, inner `{` pushes ST_Other. The stray `}` inside the `?` gets eaten by consumeToken's r_brace branch and pops the inner ST_Other. So when the inner parseBrace reaches its real `}`, the top is ST_Enum — wrong type, not empty — and the second assert trips.
Thanks for the reply and the analysis.
If we add to `parseConditional`
``` c++
if (CurrentToken->is(tok::r_brace))
return false;
```
That should also fix the issue and the assert can stay, right? I'd prefer that.
https://github.com/llvm/llvm-project/pull/199098
More information about the cfe-commits
mailing list