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

Osama Abdelkader via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 23 12:51:48 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}}
----------------
osamakader wrote:

wait until `DeclSpec::Finish()` approach doesn't work because:
1. When SetTypeSpecType fails due to a conflict, it returns an error but
    doesn't change TypeSpecType, so we can't detect the conflict in `Finish()`
2. We don't have access to the diagnostic ID or previous specifier in `Finish()`
3. The parser needs to emit the diagnostic, not `Finish()`

I tried that approach and it fails:
When SetTypeSpecType(int) is called after auto is set:
It returns an error, TypeSpecType remains TST_auto, so we can't tell in `Finish()` that int was attempted.

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


More information about the cfe-commits mailing list