[clang] [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (PR #148552)

via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 13 15:23:08 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)

<details>
<summary>Changes</summary>

Fix a false positve warning which was introduced by #<!-- -->146234.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+1-1) 
- (modified) clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp (+22) 


``````````diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7ebb53318702c..72972221d23c5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1976,7 +1976,7 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) {
       Diags.isIgnored(diag::warn_suggest_noreturn_function, FD->getLocation()))
     return;
 
-  if (!FD->hasAttr<NoReturnAttr>() && !FD->hasAttr<InferredNoReturnAttr>() &&
+  if (!FD->isNoReturn() && !FD->hasAttr<InferredNoReturnAttr>() &&
       isKnownToAlwaysThrow(FD)) {
     NonConstFD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context));
 
diff --git a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
index 7548ba8904a71..8beffcd39e85c 100644
--- a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
+++ b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
@@ -21,3 +21,25 @@ int ensureZero(int i) {
   if (i == 0) return 0;
   throwError("ERROR"); // no-warning
 }
+
+
+template <typename Ex>
+[[noreturn]]
+void tpl_throws(Ex const& e) {
+    throw e;
+}
+
+[[noreturn]]
+void tpl_throws_test() {
+    tpl_throws(0);
+}
+
+[[gnu::noreturn]]
+int gnu_throws() {
+    throw 0;
+}
+
+[[noreturn]]
+int cxx11_throws() {
+    throw 0;
+}

``````````

</details>


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


More information about the cfe-commits mailing list