summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-06-29 17:58:59 +0000
committerStephan Bergmann <sbergman@redhat.com>2017-06-29 17:58:59 +0000
commit743de46043d2e35eb6034537648d3893c9834ae6 (patch)
treecedfe0d8526af22a34b3b341d114706237423df1 /clang
parentc4bbce724e62dc1f309ccd45abcb26a8e2bc9ceb (diff)
downloadbcm5719-llvm-743de46043d2e35eb6034537648d3893c9834ae6.tar.gz
bcm5719-llvm-743de46043d2e35eb6034537648d3893c9834ae6.zip
Fixed -Wexceptions derived-to-base false positives
...as introduced with recent <https://reviews.llvm.org/D33333> "Emit warning when throw exception in destruct or dealloc functions which has a (possible implicit) noexcept specifier". (The equivalent of the goodReference case hit when building LibreOffice.) (These warnings are apparently only emitted when no errors have yet been encountered, so it didn't work to add the test code to the end of the existing clang/test/SemaCXX/exceptions.cpp.) llvm-svn: 306715
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/AnalysisBasedWarnings.cpp6
-rw-r--r--clang/test/SemaCXX/exception-warnings.cpp36
2 files changed, 41 insertions, 1 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 934e13e72d0..fd2d07957c2 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -305,10 +305,14 @@ static bool isThrowCaught(const CXXThrowExpr *Throw,
CaughtType = CaughtType->castAs<ReferenceType>()
->getPointeeType()
->getUnqualifiedDesugaredType();
+ if (ThrowType->isPointerType() && CaughtType->isPointerType()) {
+ ThrowType = ThrowType->getPointeeType()->getUnqualifiedDesugaredType();
+ CaughtType = CaughtType->getPointeeType()->getUnqualifiedDesugaredType();
+ }
if (CaughtType == ThrowType)
return true;
const CXXRecordDecl *CaughtAsRecordType =
- CaughtType->getPointeeCXXRecordDecl();
+ CaughtType->getAsCXXRecordDecl();
const CXXRecordDecl *ThrowTypeAsRecordType = ThrowType->getAsCXXRecordDecl();
if (CaughtAsRecordType && ThrowTypeAsRecordType)
return ThrowTypeAsRecordType->isDerivedFrom(CaughtAsRecordType);
diff --git a/clang/test/SemaCXX/exception-warnings.cpp b/clang/test/SemaCXX/exception-warnings.cpp
new file mode 100644
index 00000000000..f6c646e5a40
--- /dev/null
+++ b/clang/test/SemaCXX/exception-warnings.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
+
+struct B {};
+struct D: B {};
+void goodPlain() throw () {
+ try {
+ throw D();
+ } catch (B) {}
+}
+void goodReference() throw () {
+ try {
+ throw D();
+ } catch (B &) {}
+}
+void goodPointer() throw () {
+ D d;
+ try {
+ throw &d;
+ } catch (B *) {}
+}
+void badPlain() throw () { // expected-note {{non-throwing function declare here}}
+ try {
+ throw B(); // expected-warning {{'badPlain' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ } catch (D) {}
+}
+void badReference() throw () { // expected-note {{non-throwing function declare here}}
+ try {
+ throw B(); // expected-warning {{'badReference' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ } catch (D &) {}
+}
+void badPointer() throw () { // expected-note {{non-throwing function declare here}}
+ B b;
+ try {
+ throw &b; // expected-warning {{'badPointer' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ } catch (D *) {}
+}
OpenPOWER on IntegriCloud