Skip to content

Commit 4340fec

Browse files
committed
Handle direct throws in functions.
1 parent b148279 commit 4340fec

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
722722
}
723723
}
724724
}
725+
// Direct throw.
726+
if (isa<CXXThrowExpr>(LastStmt)) {
727+
return; // Don't warn about fall-through.
728+
}
725729
}
726730
}
727731
}

clang/test/SemaCXX/wreturn-always-throws.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ int ensureZero(const int i) {
2020
if (i == 0) return 0;
2121
throwError("ERROR"); // no-warning
2222
}
23+
24+
int alwaysThrows() {
25+
throw std::runtime_error("This function always throws"); // no-warning
26+
}

0 commit comments

Comments
 (0)