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

via cfe-commits cfe-commits at lists.llvm.org
Wed May 27 12:00:26 PDT 2026


================
@@ -1881,15 +1881,47 @@ Sema::ConditionResult Parser::ParseCXXCondition(StmtResult *InitStmt,
   }
 
   ParsedAttributes attrs(AttrFactory);
-  MaybeParseCXX11Attributes(attrs);
+  bool ParsedAttrs = MaybeParseCXX11Attributes(attrs);
 
   const auto WarnOnInit = [this, &CK] {
-    Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
-                                ? diag::warn_cxx14_compat_init_statement
-                                : diag::ext_init_statement)
-        << (CK == Sema::ConditionKind::Switch);
+    if (getLangOpts().CPlusPlus)
+      Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
+                                  ? diag::warn_cxx14_compat_init_statement
+                                  : diag::ext_init_statement)
+          << (CK == Sema::ConditionKind::Switch);
+    else
+      Diag(Tok.getLocation(), getLangOpts().C2y
+                                  ? diag::warn_c2y_compat_init_statement
+                                  : diag::ext_c2y_init_statement)
+          << (CK == Sema::ConditionKind::Switch);
   };
 
+  if (!getLangOpts().CPlusPlus) {
+    if (Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
----------------
Sirraide wrote:

> This kind of special casing is a bit concerning; if C adds new kinds of declarations, we're not going to know to come update this place where we're only calling `ParseDeclaration` if there's a `static_assert` keyword.

`ParseForStmt()` already has that problem, and it doesn’t help that that function is already a total mess because it has to parse like 4 different kinds of loops... so if we want to do something about this we probably should fix that function too (expansion statements doesn’t do that; it just makes it worse)

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


More information about the cfe-commits mailing list