================
@@ -1881,15 +1881,43 @@ 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)) {
+      WarnOnInit();
+      DeclGroupPtrTy DG;
+      SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
+      ParsedAttributes DeclSpecAttrs(AttrFactory);
+      // C2y replaces the init-statement in C++17 to be a declaration instead.
+      DG = ParseDeclaration(DeclaratorContext::SelectionInit, DeclEnd, attrs,
+                            DeclSpecAttrs);
+      *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
+      return ParseCondition(nullptr, Loc, CK, MissingOK);
+    }
+
+    if (Tok.is(tok::semi) && ParsedAttrs) {
+      // Parse if ([[...]]; true).
+      WarnOnInit();
+      *InitStmt = Actions.ActOnAttributedStmt(
+          attrs, Actions.ActOnNullStmt(ConsumeToken()).get());
+      return ParseCondition(nullptr, Loc, CK, MissingOK);
+    }
----------------
Sirraide wrote:

Actually, this has a bug: `Tok.getLocation()` won’t give you the right location 
there anymore because I moved the call to `ConsumeToken()` before it, so you 
might just want to inline the initialiser of `Null` into its uses

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