[clang] [clang] Reject 'auto' storage class with type specifier in C++ (PR #166004)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 3 05:26:20 PST 2025


================
@@ -4095,11 +4095,22 @@ 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.
+          // However, OpenCL has its own error handling for this case.
----------------
Sirraide wrote:

Can we just remove the OpenCL-specific diagnostic from the OpenCL code and emit the diagnostic for both C++ and OpenCL here instead?

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


More information about the cfe-commits mailing list