[clang] [Clang] prevent incorrect rejection of auto with reordered declaration specifiers in C23 (PR #177865)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 28 08:08:09 PST 2026


================
@@ -4093,7 +4093,30 @@ void Parser::ParseDeclarationSpecifiers(
       break;
     case tok::kw_auto:
       if (getLangOpts().CPlusPlus11 || getLangOpts().C23) {
-        if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
+        auto IsTypeSpecifier = [&]() {
+          if (DS.hasTypeSpecifier() &&
+              DS.getTypeSpecType() != DeclSpec::TST_auto)
+            return true;
+
+          unsigned I = 1;
+          while (true) {
+            const Token &T = GetLookAheadToken(I);
+            if (isKnownToBeTypeSpecifier(T))
+              return true;
+
+            if (T.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual,
+                          tok::kw__Atomic) &&
+                GetLookAheadToken(I + 1).is(tok::l_paren))
+              return true;
----------------
AaronBallman wrote:

What happens with code like:
```
void func() {
  signed int _Atomic auto i = 12; // Accept due to valid but useless storage class specifier
}
signed int _Atomic auto j = 12; // Reject due to invalid storage class specifier
```


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


More information about the cfe-commits mailing list