Skip to content

[clang][C2x] Remove confusing diagnostic auto storage class specifier #68710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

to268
Copy link
Contributor

@to268 to268 commented Oct 10, 2023

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.
Now this diagnostic does not show up in C23.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 10, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2023

@llvm/pr-subscribers-clang

Author: Guillot Tony (to268)

Changes

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.
Now this diagnostic does not show up in C23.


Full diff: https://github.com/llvm/llvm-project/pull/68710.diff

3 Files Affected:

  • (modified) clang/lib/Parse/ParseDecl.cpp (+1-1)
  • (modified) clang/test/C/C2x/n3007.c (+4)
  • (modified) clang/test/Sema/c2x-auto.c (+1)
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));

@to268 to268 changed the title [clang][C2x] Remove confusing diagnostic auto storage class specifier in C23 [clang][C2x] Remove confusing diagnostic auto storage class specifier Oct 10, 2023
Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick patch!

@to268
Copy link
Contributor Author

to268 commented Oct 11, 2023

Can you land this patch on my behalf?

@cor3ntin
Copy link
Contributor

You should just be able to click "squash and merge", no?

@to268
Copy link
Contributor Author

to268 commented Oct 11, 2023

Nope, I can't

This branch has no conflicts with the base branch
Only those with write access to this repository can merge pull requests.

@cor3ntin cor3ntin merged commit d5444ab into llvm:main Oct 11, 2023
@to268 to268 deleted the N3007-remove-storage-class-diagnostic branch October 11, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants