[clang] d5444ab - [clang][C2x] Remove confusing diagnostic auto storage class specifier (#68710)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 11 00:51:51 PDT 2023
Author: Guillot Tony
Date: 2023-10-11T09:51:46+02:00
New Revision: d5444ab26743115e42e4abb3782bbefb0e8912d0
URL: https://github.com/llvm/llvm-project/commit/d5444ab26743115e42e4abb3782bbefb0e8912d0
DIFF: https://github.com/llvm/llvm-project/commit/d5444ab26743115e42e4abb3782bbefb0e8912d0.diff
LOG: [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.
Added:
Modified:
clang/lib/Parse/ParseDecl.cpp
clang/test/C/C2x/n3007.c
clang/test/Sema/c2x-auto.c
Removed:
################################################################################
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