[clang] [clang][C2x] Remove confusing diagnostic auto storage class specifier in C23 (PR #68710)
Guillot Tony via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 10 07:10:50 PDT 2023
https://github.com/to268 created https://github.com/llvm/llvm-project/pull/68710
When declaring `auto int` at local or file scope, we emit a warning intended for C++11 and later, which is incorrect and confusing in C23.
See [Godbolt example](https://godbolt.org/z/j1acGhecd).
Now this diagnostic does not show up in C23.
>From 89dd9eaa7c7d6f3a2a91ccc4f96656f8e0266a07 Mon Sep 17 00:00:00 2001
From: Guillot Tony <tony.guillot at protonmail.com>
Date: Tue, 10 Oct 2023 15:34:55 +0200
Subject: [PATCH] Removed diagnostic auto storage class specifier in C23
---
clang/lib/Parse/ParseDecl.cpp | 2 +-
clang/test/C/C2x/n3007.c | 4 ++++
clang/test/Sema/c2x-auto.c | 1 +
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index bcc70c04dec91ba..14a28e5a31c57db 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4042,7 +4042,7 @@ void Parser::ParseDeclarationSpecifiers(
if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
PrevSpec, DiagID, Policy);
- if (!isInvalid)
+ if (!isInvalid && !getLangOpts().C23)
Diag(Tok, diag::ext_auto_storage_class)
<< FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
} else
diff --git a/clang/test/C/C2x/n3007.c b/clang/test/C/C2x/n3007.c
index 1fd20332ceb4715..34ec419b71b271d 100644
--- a/clang/test/C/C2x/n3007.c
+++ b/clang/test/C/C2x/n3007.c
@@ -3,6 +3,10 @@
/* WG14 N3007: Yes
* Type Inference for object definitions
*/
+void test_auto_int(void) {
+ auto int auto_int = 12;
+}
+
void test_qualifiers(int x, const int y, int * restrict z) {
const auto a = x;
auto b = y;
diff --git a/clang/test/Sema/c2x-auto.c b/clang/test/Sema/c2x-auto.c
index 916c179adcf3182..7cbd1db31315aef 100644
--- a/clang/test/Sema/c2x-auto.c
+++ b/clang/test/Sema/c2x-auto.c
@@ -4,6 +4,7 @@ void test_basic_types(void) {
auto undefined; // expected-error {{declaration of variable 'undefined' with deduced type 'auto' requires an initializer}}
auto auto_int = 4;
auto auto_long = 4UL;
+ auto int auto_int_ts = 12;
signed auto a = 1L; // expected-error {{'auto' cannot be signed or unsigned}}
_Static_assert(_Generic(auto_int, int : 1));
More information about the cfe-commits
mailing list