Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ Improvements to Clang's diagnostics
or continue (#GH166013)
- Clang now emits a diagnostic in case `vector_size` or `ext_vector_type`
attributes are used with a negative size (#GH165463).
- Clang no longer emits ``-Wmissing-noreturn`` for virtual methods where
the function body consists of a `throw` expression (#GH167247).

Improvements to Clang's time-trace
----------------------------------
Expand Down
12 changes: 10 additions & 2 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,8 +1966,16 @@ static bool isKnownToAlwaysThrow(const FunctionDecl *FD) {
if (const auto *EWC = dyn_cast<ExprWithCleanups>(OnlyStmt)) {
OnlyStmt = EWC->getSubExpr();
}
// Check if the only statement is a throw expression.
return isa<CXXThrowExpr>(OnlyStmt);

if (isa<CXXThrowExpr>(OnlyStmt)) {
const auto *MD = dyn_cast<CXXMethodDecl>(FD);
if (MD && MD->isVirtual()) {
const auto *RD = MD->getParent();
return MD->hasAttr<FinalAttr>() || (RD && RD->isEffectivelyFinal());
}
return true;
}
return false;
}

void clang::inferNoReturnAttr(Sema &S, const Decl *D) {
Expand Down
23 changes: 23 additions & 0 deletions clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,26 @@ int gnu_throws() {
int cxx11_throws() {
throw 0;
}

namespace GH167247 {
struct S1 {
virtual ~S1() = default;
virtual void m() {
throw std::runtime_error("This method always throws");
}
};

struct S2 {
virtual ~S2() = default;

virtual void m() final { // expected-warning {{function 'm' could be declared with attribute 'noreturn'}}
throw std::runtime_error("This method always throws");
}
};

struct S3 final : S1 {
void m() { // expected-warning {{function 'm' could be declared with attribute 'noreturn'}}
throw std::runtime_error("This method always throws");
}
};
}
Loading