[clang] [clang-format] Fix a crash on unbalanced `?` inside nested braces (PR #199098)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Fri May 22 12:01:36 PDT 2026


================
@@ -1297,6 +1297,11 @@ class AnnotatingParser {
         next();
         return true;
       }
+      // Avoid consuming an unbalanced `}` here: it would pop a Scopes frame
+      // owned by an enclosing parseBrace and trip its `!Scopes.empty()`
+      // assertion. See Issue #199017.
+      if (CurrentToken->is(tok::r_brace))
----------------
HazardyKnusperkeks wrote:

I don't think this is the right fix.
There's one place which break an assertion, are you sure there can't be another one to break the assertion? I think one should handle the bug there, were the assert fired.

And referring here to an assert elsewhere is bound to be broken, if the code with the assert gets refactored, this comment is possibly wrong.

https://github.com/llvm/llvm-project/pull/199098


More information about the cfe-commits mailing list