[clang] [Sema] Avoid attaching 'noreturn' attribute to explicit function temp… (PR #150003)
Samarth Narang via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 22 04:39:25 PDT 2025
https://github.com/snarang181 created https://github.com/llvm/llvm-project/pull/150003
…late specializations
>From ff5dfd4fae47cd212a0882895396c0cb855e29a3 Mon Sep 17 00:00:00 2001
From: Samarth Narang <snarang at umass.edu>
Date: Tue, 22 Jul 2025 07:38:22 -0400
Subject: [PATCH] [Sema] Avoid attaching 'noreturn' attribute to explicit
function template specializations
---
clang/lib/Sema/SemaDecl.cpp | 8 ++++++++
clang/lib/Sema/SemaDeclAttr.cpp | 3 +++
2 files changed, 11 insertions(+)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 14403e65e8f42..bb412ef6788e7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3267,6 +3267,14 @@ void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old,
if (isa<UsedAttr>(I) || isa<RetainAttr>(I))
continue;
+ if (isa<InferredNoReturnAttr>(I)) {
+ if (auto *FD = dyn_cast<FunctionDecl>(New)) {
+ if (FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+ continue; // Don't propagate inferred noreturn attributes to explicit
+ // specializations.
+ }
+ }
+
if (mergeDeclAttribute(*this, New, I, LocalAMK))
foundAny = true;
}
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 78f4804202ddc..a61d10c166578 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1970,6 +1970,9 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) {
if (!FD)
return;
+ if (FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+ return; // Don't infer noreturn for explicit specializations.
+
auto *NonConstFD = const_cast<FunctionDecl *>(FD);
DiagnosticsEngine &Diags = S.getDiagnostics();
if (Diags.isIgnored(diag::warn_falloff_nonvoid, FD->getLocation()) &&
More information about the cfe-commits
mailing list