[clang] afffa0d - [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (#148552)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 14 05:20:04 PDT 2025
Author: Corentin Jabot
Date: 2025-07-14T14:20:00+02:00
New Revision: afffa0d334bf33c89f1f921ef950e14744e0f0e4
URL: https://github.com/llvm/llvm-project/commit/afffa0d334bf33c89f1f921ef950e14744e0f0e4
DIFF: https://github.com/llvm/llvm-project/commit/afffa0d334bf33c89f1f921ef950e14744e0f0e4.diff
LOG: [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (#148552)
Fix a false positve warning which was introduced by #146234.
Added:
Modified:
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 099207727c8c8..60a9aee2d41e7 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