[PATCH] D133289: [C2X] N3007 Type inference for object definitions

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 4 12:18:54 PDT 2023


aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

I spotted some minor issues, but this LGTM for the initial implementation. Thank you for all your effort on this project!!

There are some outstanding issues that should be handled in a follow up, however:

  void foo() {
     auto l = (struct S { int x, y; }){ 1, 2 }; // Underspecified declaration, should diagnose
  
    _Atomic int i;
    _Static_assert(_Generic(&i, _Atomic auto *: 1)); // Gets two errors instead of just 1
  
    auto int i = 12; // At local and file scope, now gives: warning: 'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases
  
    auto __attribute__((mode(HI))) i = 12; // Gives confused diagnostics, but GCC also doesn't accept currently either
    _Static_assert(_Generic(i, short : 1)); // But if we accepted the above, this should pass. 
  }

but these all seem minor enough to be handled in follow-up work.

Do you need me to land this on your behalf? If so, I can fix up the NFC changes I found for you, but what email address would you like me to use for patch attribution?



================
Comment at: clang/lib/Sema/DeclSpec.cpp:1367-1368
+  // specifier in a pre-C++11 dialect of C++ or in a pre-C23 dialect of C.
+  if ((!S.getLangOpts().CPlusPlus11 && !S.getLangOpts().C23) &&
+      TypeSpecType == TST_auto)
     S.Diag(TSTLoc, diag::ext_auto_type_specifier);
----------------



================
Comment at: clang/lib/Sema/SemaDecl.cpp:12869
+    Diag(Range.getBegin(), diag::err_auto_not_allowed)
+        << (int)Deduced->getContainedAutoType()->getKeyword() << /* 'here' */ 23
+        << Range;
----------------
`/*in array decl*/` instead of `here`


================
Comment at: clang/test/C/C2x/n3007.c:32
+
+  _Static_assert(_Generic(&i, _Atomic auto *: 1)); // expected-error {{_Atomic cannot be applied to type 'auto' which is not trivially copyable}} \
+                                                      expected-error {{'auto' not allowed here}}
----------------
aaron.ballman wrote:
> The first error on this line isn't helpful; the second error is the only one I'd expect to see here.
To be clear, I mean this example should have one diagnostic instead of two:
```
  _Static_assert(_Generic(&i, _Atomic auto *: 1)); // expected-error {{_Atomic cannot be applied to type 'auto' in C23}} \
                                                      expected-error {{'auto' not allowed here}}
```



================
Comment at: clang/test/Sema/c2x-auto.c:110-111
+  _Static_assert(_Generic(str2, const char * : 1));
+  _Static_assert(_Generic(b, int * : 1));
+}
+
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133289/new/

https://reviews.llvm.org/D133289



More information about the cfe-commits mailing list