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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 13 05:30:54 PST 2026


================
@@ -3861,6 +3876,47 @@ void Parser::ParseDeclarationSpecifiers(
         goto DoneWithDeclSpec;
       }
 
+      // If 'auto' is set and this identifier is a type name, check if it's
+      // followed by declarator tokens (like '=', '(', '[', etc.). If so, this
+      // identifier is likely the variable name, not a type specifier, so we
+      // should stop parsing declaration specifiers.
+      // Also check for concept constraint syntax (C<T> auto param) where
+      // the identifier before 'auto' might be a concept, not a type conflict.
+      // Also check for template parameters (template<auto V>) and lambda
+      // parameters
+      // ([](auto c)) where the identifier is a parameter name, not a type
+      // conflict.
+      if (DS.getTypeSpecType() == DeclSpec::TST_auto && TypeRep) {
+        // Check if the next token indicates this is a declarator
+        tok::TokenKind NextKind = NextToken().getKind();
+        if (NextKind == tok::equal || NextKind == tok::l_paren ||
+            NextKind == tok::l_square || NextKind == tok::amp ||
+            NextKind == tok::ampamp || NextKind == tok::star ||
+            NextKind == tok::coloncolon || NextKind == tok::comma ||
+            NextKind == tok::semi || NextKind == tok::colon ||
+            NextKind == tok::greater || NextKind == tok::r_paren ||
+            NextKind == tok::arrow) {
----------------
AaronBallman wrote:

```suggestion
        Token Next = NextToken();
        if (Next.isOneOf(tok::equal, tok::l_paren, tok::l_square, ...)) {
```
I think this will be a cleaner way to express the list.

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


More information about the cfe-commits mailing list