Skip to content

Commit a2125f5

Browse files
committed
Elaborate comments on why we skip explicit specializations
Add -Winvalid-noreturn diagnostic in LIT test
1 parent 0228989 commit a2125f5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,8 +1970,12 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) {
19701970
if (!FD)
19711971
return;
19721972

1973+
// Skip explicit specializations here as they may have
1974+
// a user-provided definition that may deliberately differ from the primary
1975+
// template. If an explicit specialization truly never returns, the user
1976+
// should explicitly mark it with [[noreturn]].
19731977
if (FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
1974-
return; // Don't infer noreturn for explicit specializations.
1978+
return;
19751979

19761980
auto *NonConstFD = const_cast<FunctionDecl *>(FD);
19771981
DiagnosticsEngine &Diags = S.getDiagnostics();

clang/test/SemaCXX/wreturn-always-throws.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -verify %s
1+
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -Winvalid-noreturn -verify %s
22
// expected-no-diagnostics
33

44
namespace std {

0 commit comments

Comments
 (0)