[clang] [clang] Reject 'auto' storage class with type specifier in C++ (PR #166004)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 4 12:32:52 PST 2025
================
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++23 %s
+
+// Test that 'auto' cannot be combined with a type specifier in C++.
+void f() {
+ auto int x = 1; // expected-error {{'auto' cannot be combined with a type specifier}}
----------------
AaronBallman wrote:
I think:
```
if (isKnownToBeTypeSpecifier(GetLookAheadToken(1)))
```
will need to be factored away, then. When I looked into this, the issue is that the token we get is not actually annotated because nothing calls a `TryAnnotate*()` function to turn it into an annotation token. IIRC, those functions all work off `Tok`, not a given `Token`, and they work by modifying the token stream itself (so may not work well as a lookahead function).
https://github.com/llvm/llvm-project/pull/166004
More information about the cfe-commits
mailing list