[clang] [clang] Emit diagnostic for typedef+auto missed case in C++98/pre-C23 C (PR #210141)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 17 06:23:22 PDT 2026


================
@@ -1,8 +1,16 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wc++11-compat 
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wc++11-compat
 void f() {
   auto int a; // expected-warning {{'auto' storage class specifier is redundant and incompatible with C++11}}
   int auto b; // expected-warning {{'auto' storage class specifier is redundant and incompatible with C++11}}
   auto c; // expected-warning {{C++11 extension}} expected-error {{requires an initializer}}
   static auto d = 0; // expected-warning {{C++11 extension}}
   auto static e = 0; // expected-warning {{C++11 extension}}
 }
+
+// typedef and auto storage-class-specifier cannot appear in the same
+// decl-specifier-seq ([dcl.stc] p1). This must be diagnosed in C++98 even
+// though 'auto int' (without typedef) is valid there.
+void g() {
+  typedef auto int t1;    // expected-error {{cannot combine with previous 'typedef' declaration specifier}}
----------------
AaronBallman wrote:

Aren't we solving the wrong regression?

https://godbolt.org/z/xMrh3rzfv

In 22.x we're diagnosing that you cannot combine `auto` and `int` in C++98 mode. This patch restores that behavior, but in C++98, we *can* combine `auto` and `int` (https://godbolt.org/z/K8GWKr7Yj), what we cannot combine is `auto` and `typedef`. But we dropped the diagnostic which said `'auto' not allowed in typedef`. I think that was the diagnostic we wanted to retain, wasn't it?

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


More information about the cfe-commits mailing list