Skip to content

Commit 8e0060c

Browse files
committed
[Clang] suppress -Wmissing-noreturn for virtual methods with throw-only bodies
1 parent cc184e3 commit 8e0060c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ Improvements to Clang's diagnostics
417417
or continue (#GH166013)
418418
- Clang now emits a diagnostic in case `vector_size` or `ext_vector_type`
419419
attributes are used with a negative size (#GH165463).
420+
- Clang no longer emits ``-Wmissing-noreturn`` for virtual methods where
421+
the function body consists of a `throw` expression (#GH167247).
420422

421423
Improvements to Clang's time-trace
422424
----------------------------------

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,8 +1966,9 @@ static bool isKnownToAlwaysThrow(const FunctionDecl *FD) {
19661966
if (const auto *EWC = dyn_cast<ExprWithCleanups>(OnlyStmt)) {
19671967
OnlyStmt = EWC->getSubExpr();
19681968
}
1969-
// Check if the only statement is a throw expression.
1970-
return isa<CXXThrowExpr>(OnlyStmt);
1969+
1970+
const auto *MD = dyn_cast<CXXMethodDecl>(FD);
1971+
return isa<CXXThrowExpr>(OnlyStmt) && !(MD && MD->isVirtual());
19711972
}
19721973

19731974
void clang::inferNoReturnAttr(Sema &S, const Decl *D) {

clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,12 @@ int gnu_throws() {
5353
int cxx11_throws() {
5454
throw 0;
5555
}
56+
57+
namespace GH167247 {
58+
struct S {
59+
virtual ~S() = default;
60+
virtual void m() {
61+
throw std::runtime_error("This method always throws");
62+
}
63+
};
64+
}

0 commit comments

Comments
 (0)