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

via cfe-commits cfe-commits at lists.llvm.org
Fri May 22 12:14:06 PDT 2026


================
@@ -1881,15 +1881,51 @@ 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 (isDeclarationStatement() && !isCXXSimpleDeclaration(false)) {
----------------
Sirraide wrote:

I think it’d be easiest to check for just `static_assert` and `_Static_assert` here (like we do in `ParseForStatement()`; all other declarations that are legal here should be handled by existing code paths I believe

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


More information about the cfe-commits mailing list