r306715 - Fixed -Wexceptions derived-to-base false positives
Stephan Bergmann via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 29 10:58:59 PDT 2017
Author: sberg
Date: Thu Jun 29 10:58:59 2017
New Revision: 306715
URL: http://llvm.org/viewvc/llvm-project?rev=306715&view=rev
Log:
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.)
Added:
cfe/trunk/test/SemaCXX/exception-warnings.cpp
Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=306715&r1=306714&r2=306715&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Thu Jun 29 10:58:59 2017
@@ -305,10 +305,14 @@ static bool isThrowCaught(const CXXThrow
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);
Added: cfe/trunk/test/SemaCXX/exception-warnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/exception-warnings.cpp?rev=306715&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/exception-warnings.cpp (added)
+++ cfe/trunk/test/SemaCXX/exception-warnings.cpp Thu Jun 29 10:58:59 2017
@@ -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 *) {}
+}
More information about the cfe-commits
mailing list