]> granicus.if.org Git - clang/commitdiff
[CFG] Relax Wexceptions warning on rethrow
authorErich Keane <erich.keane@intel.com>
Tue, 17 Oct 2017 20:57:24 +0000 (20:57 +0000)
committerErich Keane <erich.keane@intel.com>
Tue, 17 Oct 2017 20:57:24 +0000 (20:57 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316030 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/warn-throw-out-noexcept-func.cpp

index bdfed6ead10736de1fd92e7799fa6db6dd96f60f..7a31711e72786e08bd33a63ca8dcdff0ac52cf95 100644 (file)
@@ -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()
index 5e1c5714496ce3a49c98a63fea15b9a3b25ff981..a6c23ddc6c8fbec82b13b7e521cb706011739d3c 100644 (file)
@@ -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}}