[clang] Suppress noreturn warning if last statement in a function is a throw (PR #145166)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 21 09:17:57 PDT 2025
================
@@ -681,6 +705,30 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
if (CD.diag_FallThrough_HasNoReturn)
S.Diag(RBrace, CD.diag_FallThrough_HasNoReturn) << CD.FunKind;
} else if (!ReturnsVoid && CD.diag_FallThrough_ReturnsNonVoid) {
+ // If the final statement is a call to an always-throwing function,
+ // don't warn about the fall-through.
+ if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
+ if (const auto *CS = dyn_cast<CompoundStmt>(Body)) {
+ if (!CS->body_empty()) {
+ const Stmt *LastStmt = CS->body_back();
+ // Unwrap ExprWithCleanups if necessary.
+ if (const auto *EWC = dyn_cast<ExprWithCleanups>(LastStmt)) {
+ LastStmt = EWC->getSubExpr();
+ }
+ if (const auto *CE = dyn_cast<CallExpr>(LastStmt)) {
+ if (const FunctionDecl *Callee = CE->getDirectCallee()) {
+ if (isKnownToAlwaysThrow(Callee)) {
----------------
zwuis wrote:
Ditto.
https://github.com/llvm/llvm-project/pull/145166
More information about the cfe-commits
mailing list