Skip to content
Merged
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
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,10 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) {
if (!FD->hasAttr<NoReturnAttr>() && !FD->hasAttr<InferredNoReturnAttr>() &&
isKnownToAlwaysThrow(FD)) {
NonConstFD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context));

// Emit a diagnostic suggesting the function being marked [[noreturn]].
S.Diag(FD->getLocation(), diag::warn_suggest_noreturn_function)
<< /*isFunction=*/0 << FD;
}
}

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
@@ -0,0 +1,23 @@
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -Wmissing-noreturn -verify %s

namespace std {
class string {
public:
string(const char*);
};
class runtime_error {
public:
runtime_error(const string&);
};
}

// This function always throws. Suggest [[noreturn]].
void throwError(const std::string& msg) { // expected-warning {{function 'throwError' could be declared with attribute 'noreturn'}}
throw std::runtime_error(msg);
}

// The non-void caller should not warn about missing return.
int ensureZero(int i) {
if (i == 0) return 0;
throwError("ERROR"); // no-warning
}
Loading