Skip to content

Commit 0d989b2

Browse files
authored
[clang] Avoid warnings about enum mismatch in ternary expressions. NFC. (#159338)
This avoids the following kind of warning when built with GCC: ../../clang/lib/Sema/SemaStmtAttr.cpp: In function ‘clang::Attr* ProcessStmtAttribute(clang::Sema&, clang::Stmt*, const clang::ParsedAttr&, clang::SourceRange)’: ../../clang/lib/Sema/SemaStmtAttr.cpp:677:30: warning: enumerated mismatch in conditional expression: ‘clang::diag::<unnamed enum>’ vs ‘clang::diag::<unnamed enum>’ [-Wenum-compare] 676 | S.Diag(A.getLoc(), A.isRegularKeywordAttribute() | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 677 | ? diag::err_keyword_not_supported_on_targe | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 678 | : diag::warn_unhandled_ms_attribute_ignore ) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ These enums are non-overlapping, but due they are defined in different enum scopes due to how they are generated with tablegen.
1 parent aa5558d commit 0d989b2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6839,10 +6839,11 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
68396839
// though they were unknown attributes.
68406840
if (AL.getKind() == ParsedAttr::UnknownAttribute ||
68416841
!AL.existsInTarget(S.Context.getTargetInfo())) {
6842-
if (AL.isRegularKeywordAttribute() || AL.isDeclspecAttribute()) {
6843-
S.Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
6844-
? diag::err_keyword_not_supported_on_target
6845-
: diag::warn_unhandled_ms_attribute_ignored)
6842+
if (AL.isRegularKeywordAttribute()) {
6843+
S.Diag(AL.getLoc(), diag::err_keyword_not_supported_on_target)
6844+
<< AL.getAttrName() << AL.getRange();
6845+
} else if (AL.isDeclspecAttribute()) {
6846+
S.Diag(AL.getLoc(), diag::warn_unhandled_ms_attribute_ignored)
68466847
<< AL.getAttrName() << AL.getRange();
68476848
} else {
68486849
S.DiagnoseUnknownAttribute(AL);

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,11 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
672672
!(A.existsInTarget(S.Context.getTargetInfo()) ||
673673
(S.Context.getLangOpts().SYCLIsDevice && Aux &&
674674
A.existsInTarget(*Aux)))) {
675-
if (A.isRegularKeywordAttribute() || A.isDeclspecAttribute()) {
676-
S.Diag(A.getLoc(), A.isRegularKeywordAttribute()
677-
? diag::err_keyword_not_supported_on_target
678-
: diag::warn_unhandled_ms_attribute_ignored)
675+
if (A.isRegularKeywordAttribute()) {
676+
S.Diag(A.getLoc(), diag::err_keyword_not_supported_on_target)
677+
<< A << A.getRange();
678+
} else if (A.isDeclspecAttribute()) {
679+
S.Diag(A.getLoc(), diag::warn_unhandled_ms_attribute_ignored)
679680
<< A << A.getRange();
680681
} else {
681682
S.DiagnoseUnknownAttribute(A);

0 commit comments

Comments
 (0)