https://github.com/ChenMiaoi created https://github.com/llvm/llvm-project/pull/229034
Only recognize parenthesized direct initializers in C++ mode. This avoids an assertion when a malformed GNU attribute in C is followed by a parenthesized expression list: ```c int a __attribute__ ) (1, 2); ``` Fixes #225045 >From d431cf5c5f6735362ef067986834aff886b15234 Mon Sep 17 00:00:00 2001 From: Chen Miao <[email protected]> Date: Mon, 5 Oct 2026 18:10:03 +0800 Subject: [PATCH] [clang] Restrict parenthesized direct initialization to C++ Only recognize parenthesized direct initializers in C++ mode. This avoids an assertion when a malformed GNU attribute in C is followed by a parenthesized expression list: ```c int a __attribute__ ) (1, 2); ``` Fixes #225045 --- clang/lib/Parse/ParseDecl.cpp | 2 +- clang/test/Parser/attributes.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 6ab03e8a7fc4a1..9793cd19c6206d 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2536,7 +2536,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( // If a '==' or '+=' is found, suggest a fixit to '='. if (isTokenEqualOrEqualTypo()) TheInitKind = InitKind::Equal; - else if (Tok.is(tok::l_paren)) + else if (getLangOpts().CPlusPlus && Tok.is(tok::l_paren)) TheInitKind = InitKind::CXXDirect; else if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace) && (!CurParsedObjCImpl || !D.isFunctionDeclarator())) diff --git a/clang/test/Parser/attributes.c b/clang/test/Parser/attributes.c index c73505d9f547d8..a648f581cd7e67 100644 --- a/clang/test/Parser/attributes.c +++ b/clang/test/Parser/attributes.c @@ -116,3 +116,8 @@ __attribute__(()) struct t; void f5() { __attribute__(()) struct t; } + +// GH225045: attribute recovery must not parse a C++ direct initializer in C. +// expected-error@+2 {{expected '(' after 'attribute'}} +// expected-error@+1 {{expected ';' after top level declarator}} +int a __attribute__ ) (1, 2); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
