Skip to content

Commit c9a6d21

Browse files
committed
Address review comments
Add a note in the release notes about the fix for the no-return function warning
1 parent 65126bc commit c9a6d21

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +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.
656+
651657

652658
Improvements to Clang's time-trace
653659
----------------------------------

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,7 @@ bool isKnownToAlwaysThrow(const FunctionDecl *FD) {
643643
OnlyStmt = EWC->getSubExpr();
644644
}
645645
// Check if the only statement is a throw expression.
646-
if (isa<CXXThrowExpr>(OnlyStmt)) {
647-
return true; // Known to always throw.
648-
}
649-
return false; // Not known to always throw.
646+
return isa<CXXThrowExpr>(OnlyStmt);
650647
}
651648

652649
} // anonymous namespace
@@ -708,25 +705,23 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
708705
// If the final statement is a call to an always-throwing function,
709706
// don't warn about the fall-through.
710707
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
711-
if (const auto *CS = dyn_cast<CompoundStmt>(Body)) {
712-
if (!CS->body_empty()) {
713-
const Stmt *LastStmt = CS->body_back();
714-
// Unwrap ExprWithCleanups if necessary.
715-
if (const auto *EWC = dyn_cast<ExprWithCleanups>(LastStmt)) {
716-
LastStmt = EWC->getSubExpr();
717-
}
718-
if (const auto *CE = dyn_cast<CallExpr>(LastStmt)) {
719-
if (const FunctionDecl *Callee = CE->getDirectCallee()) {
720-
if (isKnownToAlwaysThrow(Callee)) {
721-
return; // Don't warn about fall-through.
722-
}
723-
}
724-
}
725-
// Direct throw.
726-
if (isa<CXXThrowExpr>(LastStmt)) {
708+
if (const auto *CS = dyn_cast<CompoundStmt>(Body);
709+
CS && !CS->body_empty()) {
710+
const Stmt *LastStmt = CS->body_back();
711+
// Unwrap ExprWithCleanups if necessary.
712+
if (const auto *EWC = dyn_cast<ExprWithCleanups>(LastStmt)) {
713+
LastStmt = EWC->getSubExpr();
714+
}
715+
if (const auto *CE = dyn_cast<CallExpr>(LastStmt)) {
716+
if (const FunctionDecl *Callee = CE->getDirectCallee();
717+
Callee && isKnownToAlwaysThrow(Callee)) {
727718
return; // Don't warn about fall-through.
728719
}
729720
}
721+
// Direct throw.
722+
if (isa<CXXThrowExpr>(LastStmt)) {
723+
return; // Don't warn about fall-through.
724+
}
730725
}
731726
}
732727
bool NotInAllControlPaths = FallThroughType == MaybeFallThrough;

0 commit comments

Comments
 (0)