[clang] [clang][Sema] Avoid warnings when mixing diagnostic categories (NFC) (PR #159316)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 17 03:30:59 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Bruno De Fraine (brunodf-snps)

<details>
<summary>Changes</summary>

These statements conditionally select between diagnostics of different categories (common vs. sema). Although the diagnostic IDs do not overlap between categories, they are organized in different enums, and this raises warnings in specific compilers. The clang warning suggest this behavior is deprecated in C++20 (the warning is ignored by default in C++17 mode). By converting the diagnostic IDs to unsigned, we avoid the issue.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+4-3) 
- (modified) clang/lib/Sema/SemaStmtAttr.cpp (+4-3) 


``````````diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 44906456f3371..12f06070a3db2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6836,9 +6836,10 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
   if (AL.getKind() == ParsedAttr::UnknownAttribute ||
       !AL.existsInTarget(S.Context.getTargetInfo())) {
     if (AL.isRegularKeywordAttribute() || AL.isDeclspecAttribute()) {
-      S.Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
-                              ? diag::err_keyword_not_supported_on_target
-                              : diag::warn_unhandled_ms_attribute_ignored)
+      S.Diag(AL.getLoc(),
+             AL.isRegularKeywordAttribute()
+                 ? (unsigned)diag::err_keyword_not_supported_on_target
+                 : (unsigned)diag::warn_unhandled_ms_attribute_ignored)
           << AL.getAttrName() << AL.getRange();
     } else {
       S.DiagnoseUnknownAttribute(AL);
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 77aa7164d4555..66785c7deee57 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -673,9 +673,10 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
         (S.Context.getLangOpts().SYCLIsDevice && Aux &&
          A.existsInTarget(*Aux)))) {
     if (A.isRegularKeywordAttribute() || A.isDeclspecAttribute()) {
-      S.Diag(A.getLoc(), A.isRegularKeywordAttribute()
-                             ? diag::err_keyword_not_supported_on_target
-                             : diag::warn_unhandled_ms_attribute_ignored)
+      S.Diag(A.getLoc(),
+             A.isRegularKeywordAttribute()
+                 ? (unsigned)diag::err_keyword_not_supported_on_target
+                 : (unsigned)diag::warn_unhandled_ms_attribute_ignored)
           << A << A.getRange();
     } else {
       S.DiagnoseUnknownAttribute(A);

``````````

</details>


https://github.com/llvm/llvm-project/pull/159316


More information about the cfe-commits mailing list