================ @@ -624,8 +624,32 @@ struct CheckFallThroughDiagnostics { } }; -} // anonymous namespace +bool isKnownToAlwaysThrow(const FunctionDecl *FD) { + if (!FD->hasBody()) + return false; + const Stmt *Body = FD->getBody(); + const Stmt *OnlyStmt = nullptr; + + if (const auto *Compound = dyn_cast<CompoundStmt>(Body)) { + if (Compound->size() != 1) + return false; // More than one statement, can't be known to always throw. + OnlyStmt = *Compound->body_begin(); + } else { + OnlyStmt = Body; + } + + // Unwrap ExprWithCleanups if necessary. + if (const auto *EWC = dyn_cast<ExprWithCleanups>(OnlyStmt)) { + OnlyStmt = EWC->getSubExpr(); + } + // Check if the only statement is a throw expression. + if (isa<CXXThrowExpr>(OnlyStmt)) { + return true; // Known to always throw. + } + return false; // Not known to always throw. ---------------- zwuis wrote:
`return isa<CXXThrowExpr>(OnlyStmt);` https://github.com/llvm/llvm-project/pull/145166 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits