================
@@ -4095,11 +4095,23 @@ void Parser::ParseDeclarationSpecifiers(
case tok::kw_auto:
if (getLangOpts().CPlusPlus11 || getLangOpts().C23) {
if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
- isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
- PrevSpec, DiagID, Policy);
- if (!isInvalid && !getLangOpts().C23)
- Diag(Tok, diag::ext_auto_storage_class)
- << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
+ // In C++ (not C23), 'auto' cannot be combined with a type specifier.
+ // OpenCL is excluded here because Sema emits a more specific error
+ // message for OpenCL (e.g., "does not support the 'auto' storage
+ // class specifier").
+ if (!getLangOpts().C23 && !getLangOpts().OpenCLCPlusPlus) {
+ // In C++11+, 'auto' cannot be combined with a type specifier.
+ // Don't set the storage class specifier to avoid Sema emitting a
+ // redundant error (GCC only emits one error for this case: "two or
+ // more data types in declaration").
+ isInvalid = true;
+ PrevSpec = "auto";
----------------
AaronBallman wrote:
```suggestion
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
```
https://github.com/llvm/llvm-project/pull/166004
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits