[clang] [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (PR #148552)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 13 15:22:40 PDT 2025
https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/148552
Fix a false positve warning which was introduced by #146234.
>From 97211f696179361a2d64d533aa727e3ec1d00b53 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Mon, 14 Jul 2025 00:13:52 +0200
Subject: [PATCH] [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is
present
Fix a false positve warning which was introduced by #146234.
---
clang/lib/Sema/SemaDeclAttr.cpp | 2 +-
.../SemaCXX/wmissing-noreturn-suggestion.cpp | 22 +++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
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;
+}
More information about the cfe-commits
mailing list