[clang] [Clang][C2y] Add support for if declarations (N3356 paper) (PR #198244)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 9 02:39:08 PDT 2026


================
@@ -1970,6 +2024,13 @@ Sema::ConditionResult Parser::ParseCXXCondition(StmtResult *InitStmt,
   DeclSpec DS(AttrFactory);
   ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_condition);
 
+  // The Declarator's DeclarationAttrs only accepts [[]] and keyword attributes;
+  // move any GNU attributes onto the DeclSpec instead.
+  if (!getLangOpts().CPlusPlus)
----------------
cor3ntin wrote:

I still don't see that as a reason to have a different parse in C vs C++.
This is valid c++ https://godbolt.org/z/WM4P6vYTc  (per https://eel.is/c++draft/stmt.pre#nt:init-statement)
And we can (and do, afaict) support gnu attributes in there (ie that's outside of the scope of the standards)

`if([[]] int x; true)` is the only thing we should not support in C++ (and I'm not convinced that's not an omission in the wording frankly) 

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


More information about the cfe-commits mailing list