r316030 - [CFG] Relax Wexceptions warning on rethrow
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 17 13:57:24 PDT 2017
Author: erichkeane
Date: Tue Oct 17 13:57:24 2017
New Revision: 316030
URL: http://llvm.org/viewvc/llvm-project?rev=316030&view=rev
Log:
[CFG] Relax Wexceptions warning on rethrow
As reported here: https://bugs.llvm.org/show_bug.cgi?id=34973
"catch(...)" should catch EVERYTHING, even a rethrow. This
patch changes the order in which things are checked to ensure
that a '...' catch will get a rethrow.
Differential Revision: https://reviews.llvm.org/D39013
Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=316030&r1=316029&r2=316030&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Oct 17 13:57:24 2017
@@ -289,14 +289,14 @@ enum ThrowState {
static bool isThrowCaught(const CXXThrowExpr *Throw,
const CXXCatchStmt *Catch) {
+ const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+ if (!CaughtType)
+ return true;
const Type *ThrowType = nullptr;
if (Throw->getSubExpr())
ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
if (!ThrowType)
return false;
- const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
- if (!CaughtType)
- return true;
if (ThrowType->isReferenceType())
ThrowType = ThrowType->castAs<ReferenceType>()
->getPointeeType()
Modified: cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp?rev=316030&r1=316029&r2=316030&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp Tue Oct 17 13:57:24 2017
@@ -239,13 +239,30 @@ void n_ShouldNotDiag() noexcept {
} catch (const S &s) {
}
}
-void o_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
+// As seen in p34973, this should not throw the warning. If there is an active
+// exception, catch(...) catches everything.
+void o_ShouldNotDiag() noexcept {
try {
- throw; //expected-warning {{has a non-throwing exception specification but}}
+ throw;
} catch (...) {
}
}
+void p_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
+ try {
+ throw; //expected-warning {{has a non-throwing exception specification but}}
+ } catch (int){
+ }
+}
+
+void q_ShouldNotDiag() noexcept {
+ try {
+ throw;
+ } catch (int){
+ } catch (...){
+ }
+}
+
#define NOEXCEPT noexcept
void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing here}}
throw 1; // expected-warning {{has a non-throwing exception specification but}}
More information about the cfe-commits
mailing list