[clang] [Clang] fix parser recovery for invalid static_assert string messages (PR #187859)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 8 02:52:03 PDT 2026


================
@@ -980,7 +980,7 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd) {
     if (getLangOpts().CPlusPlus11) {
       for (unsigned I = 0;; ++I) {
         const Token &T = GetLookAheadToken(I);
-        if (T.is(tok::r_paren))
+        if (T.isOneOf(tok::r_paren, tok::semi, tok::eof))
----------------
ojhunt wrote:

@cor3ntin That issue with `consumeClose()` returning false on semicolons (I _think_ it's more general than that) is responsible for a bunch of the bad (read: asserting) parsing failures that people have been posting ai+fuzzer "fixes" for. We have a bunch of paths through the parser that expect to be receiving either a failure or a specific ast node type, but the behavioral path they actually hit is `outernodeType(innerNodeType();` returning success and the inner node - see the terrible `asm((...)` parsing bug "fix" from a few a months ago.

The only reason I haven't sat down to actually change the behavior (towards the strict "if you don't have the expected closing paren you should not claim success" model) is my assumption that we have endless recovery paths that depend on it. Whether that's true I don't know - it's simply a story I tell myself to justify the current behavior :D



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


More information about the cfe-commits mailing list