diff options
-rw-r--r-- | clang/lib/Sema/AnalysisBasedWarnings.cpp | 6 | ||||
-rw-r--r-- | clang/test/SemaCXX/exception-warnings.cpp | 36 |
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 *) {} +} |