[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
================
@@ -137,23 +137,74 @@ constexpr auto int a1 = 0; // c23-error {{illegal storage class on file-scoped v
c17-error {{illegal storage class on file-scoped variable}} \
c17-error {{unknown type name 'constexpr'}}
-constexpr int auto a2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
+constexpr int auto a2 = 0; // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
+ c23-error {{illegal storage class on file-scoped variable}} \
c17-error {{illegal storage class on file-scoped variable}} \
c17-error {{unknown type name 'constexpr'}}
auto int b1 = 0; // c23-error {{illegal storage class on file-scoped variable}} \
c17-error {{illegal storage class on file-scoped variable}}
-int auto b2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
+int auto b2 = 0; // c23-error {{illegal storage class on file-scoped variable}} \
c17-error {{illegal storage class on file-scoped variable}}
-void f() {
+long auto long i = 0; // c23-error {{illegal storage class on file-scoped variable}} \
+ c17-error {{illegal storage class on file-scoped variable}}
+
+void t1() {
constexpr auto int c1 = 0; // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
c17-error {{use of undeclared identifier 'constexpr'}}
- constexpr int auto c2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}} \
+ constexpr int auto c2 = 0; // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
c17-error {{use of undeclared identifier 'constexpr'}}
auto int d1 = 0;
- int auto d2 = 0; // c23-error {{cannot combine with previous 'int' declaration specifier}}
+ int auto d2 = 0;
+}
+
+void t2() {
+ auto long long a1 = 0;
+ long auto long a2 = 0;
+ long long auto a3 = 0;
+
+ auto const long long b1 = 0;
+ long long const auto b2 = 0;
+ long long auto const b3 = 0;
+}
+
+void t3() {
+ const auto int a1 = 0;
+ auto const int a2 = 0;
+
+ volatile auto int a3 = 0;
+ auto volatile int a4 = 0;
+ auto volatile const int a5 = 0;
+ auto const volatile int a6 = 0;
+
+ auto restrict int a7 = 0; // expected-error {{restrict requires a pointer or reference ('int' is invalid)}}
+}
+
+void t4() {
+ static long auto long s1 = 0; // c23-error {{cannot combine with previous 'static' declaration specifier}} \
+ c17-error {{cannot combine with previous 'static' declaration specifier}}
+ extern long auto long e2; // c23-error {{cannot combine with previous 'extern' declaration specifier}} \
+ c17-error {{cannot combine with previous 'extern' declaration specifier}}
+}
+
+void t5(void) {
+ const long auto long unsigned volatile _Atomic int x = 0;
----------------
AaronBallman wrote:
This would be a good test case for global scope to ensure that `auto` is still rejected as a storage class specifier there.
https://github.com/llvm/llvm-project/pull/177865
More information about the cfe-commits
mailing list