[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 1 06:33:37 PDT 2023
================
@@ -5339,16 +5339,22 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
TypeSpecType == DeclSpec::TST_interface ||
TypeSpecType == DeclSpec::TST_union ||
TypeSpecType == DeclSpec::TST_enum) {
- for (const ParsedAttr &AL : DS.getAttributes())
- Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
- ? diag::err_declspec_keyword_has_no_effect
- : diag::warn_declspec_attribute_ignored)
- << AL << GetDiagnosticTypeSpecifierID(DS);
- for (const ParsedAttr &AL : DeclAttrs)
- Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
- ? diag::err_declspec_keyword_has_no_effect
- : diag::warn_declspec_attribute_ignored)
+
+ auto EmitAttributeDiagnostic = [this, &DS](const ParsedAttr &AL) {
+ unsigned DiagnosticId;
+ if (AL.isAlignas() && !getLangOpts().CPlusPlus) {
+ DiagnosticId = diag::warn_attribute_ignored;
+ } else if (AL.isRegularKeywordAttribute()) {
+ DiagnosticId = diag::err_declspec_keyword_has_no_effect;
+ } else {
+ DiagnosticId = diag::warn_declspec_attribute_ignored;
+ }
----------------
AaronBallman wrote:
```suggestion
unsigned DiagnosticId = diag::warn_declspec_attribute_ignored;
if (AL.isAlignas() && !getLangOpts().CPlusPlus)
DiagnosticId = diag::warn_attribute_ignored;
else if (AL.isRegularKeywordAttribute())
DiagnosticId = diag::err_declspec_keyword_has_no_effect;
```
Changes for our odd choice coding style and to be slightly more succinct.
https://github.com/llvm/llvm-project/pull/65638
More information about the cfe-commits
mailing list