...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.)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306715
91177308-0d34-0410-b5e6-
96231b3b80d8
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);
--- /dev/null
+// 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 *) {}
+}