[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 17 13:57:37 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL316030: [CFG] Relax Wexceptions warning on rethrow  (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D39013?vs=119383&id=119386#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39013

Files:
  cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
  cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp


Index: cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,13 +239,30 @@
   } 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}}
Index: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
@@ -289,14 +289,14 @@
 
 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()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39013.119386.patch
Type: text/x-patch
Size: 2064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171017/1621e3b7/attachment-0001.bin>


More information about the cfe-commits mailing list