[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:02:44 PDT 2017
erichkeane updated this revision to Diff 119379.
erichkeane edited the summary of this revision.
erichkeane added a comment.
I've convinced myself that a re-throw with a catch around it should not be diagnosed, otherwise there is no way to suppress the warning in this case. It ends up being a false-positive in many cases.
https://reviews.llvm.org/D39013
Files:
lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/warn-throw-out-noexcept-func.cpp
Index: lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -293,7 +293,7 @@
if (Throw->getSubExpr())
ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
if (!ThrowType)
- return false;
+ return true;
const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
if (!CaughtType)
return true;
Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===================================================================
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,12 +239,22 @@
} 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 (...) {
}
}
+// In fact, a rethrow with ANY catch should be trusted here, otherwise it is
+// going to result in many false positives.
+void p_ShouldNotDiag() noexcept {
+ try {
+ throw;
+ } catch (int){
+ }
+}
#define NOEXCEPT noexcept
void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing here}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39013.119379.patch
Type: text/x-patch
Size: 1447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171017/46aaeb45/attachment.bin>
More information about the cfe-commits
mailing list