Skip to content

Commit d9b3920

Browse files
committed
Make clear in the release notes and inline comments that
this is a conservative fix and not a complete solution to the no-return function analysis.
1 parent c9a6d21 commit d9b3920

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,12 @@ Improvements to Clang's diagnostics
648648
#GH69470, #GH59391, #GH58172, #GH46215, #GH45915, #GH45891, #GH44490,
649649
#GH36703, #GH32903, #GH23312, #GH69874.
650650

651-
- Clang no longer warns about missing return statements (-Wreturn-type)
652-
if the final statement of a non-void function is a `throw` expression
653-
or a call to a function that is known to always throw. This avoids
654-
false positives in code patterns where control flow is intentionally
655-
terminated via exceptions.
651+
- Clang now avoids issuing `-Wreturn-type` warnings in some cases where
652+
the final statement of a non-void function is a `throw` expression, or
653+
a call to a function that is trivially known to always throw (i.e., its
654+
body consists solely of a `throw` statement). This avoids certain
655+
false positives in exception-heavy code, though only simple patterns
656+
are currently recognized.
656657

657658

658659
Improvements to Clang's time-trace

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,11 @@ struct CheckFallThroughDiagnostics {
624624
}
625625
};
626626

627+
// FIXME: This is a shallow best-effort check. Currently, we only handle
628+
// cases where the function body consists of a single `throw` expression,
629+
// possibly wrapped in an `ExprWithCleanups`. We do not perform general
630+
// control-flow analysis or handle more complex throwing patterns.
631+
// Consider expanding this to handle more cases in the future.
627632
bool isKnownToAlwaysThrow(const FunctionDecl *FD) {
628633
if (!FD->hasBody())
629634
return false;
@@ -704,7 +709,7 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
704709
} else if (!ReturnsVoid && CD.diag_FallThrough_ReturnsNonVoid) {
705710
// If the final statement is a call to an always-throwing function,
706711
// don't warn about the fall-through.
707-
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
712+
if (const auto *FD = D->getAsFunction()) {
708713
if (const auto *CS = dyn_cast<CompoundStmt>(Body);
709714
CS && !CS->body_empty()) {
710715
const Stmt *LastStmt = CS->body_back();

0 commit comments

Comments
 (0)