[PATCH] D141177: [Clang] Don't tell people to place _Alignas on a struct in diagnostics
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 22 05:43:53 PDT 2023
aaron.ballman added inline comments.
================
Comment at: clang/lib/Sema/SemaDecl.cpp:5337-5346
+ if (AL.isC11AlignasAttribute()) {
+ // Don't use the message with placement with _Alignas.
+ // This is because C doesnt let you use _Alignas on type declarations.
+ Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
+ } else {
+ Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
+ ? diag::err_declspec_keyword_has_no_effect
----------------
I think this might be a bit more clear:
```
unsigned DiagID;
if (AL.isC11AlignasAttribute()) {
// Don't use the message with placement with _Alignas.
// This is because C doesnt let you use _Alignas on type declarations.
DiagID = diag::warn_attribute_ignored;
} else if (AL.isRegularKeywordAttribute())
DiagID = diag::err_declspec_keyword_has_no_effect;
else
DiagID = diag::warn_declspec_attribute_ignored;
Diag(AL.getLoc(), DiagID) << AL << GetDiagnosticTypeSpecifierID(DS);
```
================
Comment at: clang/test/Parser/c1x-alignas.c:12
+_Alignas(int) struct c6; // expected-warning {{'_Alignas' attribute ignored}}
+
----------------
I'd like to see a C23-specific test that does:
```
alignas(int) struct c7;
```
(the test doesn't have to be in this file, but it's to validate that we correctly handle `alignas` when it's a keyword that aliases to `_Alignas`.)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D141177/new/
https://reviews.llvm.org/D141177
More information about the cfe-commits
mailing list