================
@@ -1881,15 +1881,53 @@ 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_decl_statement
+                                  : diag::ext_c2y_decl_statement)
+          << (CK == Sema::ConditionKind::Switch);
   };
 
+  if (!getLangOpts().CPlusPlus) {
+    if (isDeclarationStatement() && !isCXXSimpleDeclaration(false)) {
----------------
AaronBallman wrote:

I actually wonder if we should add `isIfDeclarationStatement()` (or similar) 
kind of like how we have `isForInitDeclaration()`? I would expect we would not 
need the `Tok.is(tok::semi)` block below because this one should be able to 
cover both scenarios.

I actually worry the attribute parsing happening here will be problematic; my 
expectation was that we'd be letting `ParseDeclaration` do all the heavy 
lifting for us, so that we'd get the right behavior for things like 
`__extension__` but that should also handle attribute parsing. And tentative 
parsing does consider attributes, so I'm a bit worried about us parsing them 
and then checking `isDeclarationStatement()` or similar because those may be 
using the attribute tokens to quickly determine something is or is not a 
declaration.

https://github.com/llvm/llvm-project/pull/198244
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to