Skip to content

Commit d5444ab

Browse files
authored
[clang][C2x] Remove confusing diagnostic auto storage class specifier (#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.
1 parent c3f67b3 commit d5444ab

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4042,7 +4042,7 @@ void Parser::ParseDeclarationSpecifiers(
40424042
if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
40434043
isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
40444044
PrevSpec, DiagID, Policy);
4045-
if (!isInvalid)
4045+
if (!isInvalid && !getLangOpts().C23)
40464046
Diag(Tok, diag::ext_auto_storage_class)
40474047
<< FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
40484048
} else

clang/test/C/C2x/n3007.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
/* WG14 N3007: Yes
44
* Type Inference for object definitions
55
*/
6+
void test_auto_int(void) {
7+
auto int auto_int = 12;
8+
}
9+
610
void test_qualifiers(int x, const int y, int * restrict z) {
711
const auto a = x;
812
auto b = y;

clang/test/Sema/c2x-auto.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ void test_basic_types(void) {
44
auto undefined; // expected-error {{declaration of variable 'undefined' with deduced type 'auto' requires an initializer}}
55
auto auto_int = 4;
66
auto auto_long = 4UL;
7+
auto int auto_int_ts = 12;
78
signed auto a = 1L; // expected-error {{'auto' cannot be signed or unsigned}}
89

910
_Static_assert(_Generic(auto_int, int : 1));

0 commit comments

Comments
 (0)