================
@@ -1880,16 +1880,70 @@ Sema::ConditionResult 
Parser::ParseCXXCondition(StmtResult *InitStmt,
     return Sema::ConditionError();
   }
 
+  if (!getLangOpts().CPlusPlus && Tok.is(tok::kw___extension__)) {
+    // In C, the first clause of a condition may be a declaration used as an
+    // init-statement (C2y), and that declaration may be prefixed by one or 
more
+    // __extension__ markers. Consume them up front -- mirroring 
block-statement
+    // parsing -- so the disambiguation below sees the real start of the
+    // declaration. The markers also silence extension diagnostics for the rest
+    // of the condition, including the diagnostic for the init-statement
+    // extension itself.
+    std::optional<ExtensionRAIIObject> ExtensionGuard;
+    ExtensionGuard.emplace(Diags);
+    while (TryConsumeToken(tok::kw___extension__))
+      ;
+  }
+
   ParsedAttributes attrs(AttrFactory);
-  MaybeParseCXX11Attributes(attrs);
+  bool ParsedAttrs = MaybeParseCXX11Attributes(attrs);
+  if (!getLangOpts().CPlusPlus)
----------------
AaronBallman wrote:

I think there's a GCC bug in the C implementation for `[[]]` because `[[]];` is 
a declaration (an attribute-declaration, specifically). And that makes me 
wonder if rejecting `__attribute__` in that same position is also a bug: 
https://godbolt.org/z/G1Ks5f5Yr

Another oddity that makes me think this could be a bug is that it is accepted 
in C++ mode, while `[[]];` is not: https://godbolt.org/z/nrx8nYxxd

But then again, GCC is consistent about expecting an actual declaration as 
opposed to "it was easier for the standards committee to specify the grammar if 
this is a declaration" things: https://godbolt.org/z/E1a1xjrc1 so perhaps this 
is intentional?

CC @pinskia

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