r184810 - Fix noexcept for delete expressions.
Eli Friedman
eli.friedman at gmail.com
Mon Jun 24 18:24:22 PDT 2013
Author: efriedma
Date: Mon Jun 24 20:24:22 2013
New Revision: 184810
URL: http://llvm.org/viewvc/llvm-project?rev=184810&view=rev
Log:
Fix noexcept for delete expressions.
Using "delete" on a pointer to an incomplete type can't throw.
While I'm here, clean up the signature of the canCalleeThrow() helper.
Modified:
cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
cfe/trunk/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=184810&r1=184809&r2=184810&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Mon Jun 24 20:24:22 2013
@@ -790,11 +790,8 @@ static CanThrowResult canSubExprsThrow(S
return R;
}
-static CanThrowResult canCalleeThrow(Sema &S, const Expr *E,
- const Decl *D,
- bool NullThrows = true) {
- if (!D)
- return NullThrows ? CT_Can : CT_Cannot;
+static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D) {
+ assert(D && "Expected decl");
// See if we can get a function type from the decl somehow.
const ValueDecl *VD = dyn_cast<ValueDecl>(D);
@@ -945,7 +942,9 @@ CanThrowResult Sema::canThrow(const Expr
cast<CXXDeleteExpr>(E)->getOperatorDelete());
if (const RecordType *RT = DTy->getAs<RecordType>()) {
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
- CT = mergeCanThrow(CT, canCalleeThrow(*this, E, RD->getDestructor()));
+ const CXXDestructorDecl *DD = RD->getDestructor();
+ if (DD)
+ CT = mergeCanThrow(CT, canCalleeThrow(*this, E, DD));
}
if (CT == CT_Can)
return CT;
Modified: cfe/trunk/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp?rev=184810&r1=184809&r2=184810&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp Mon Jun 24 20:24:22 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -fms-extensions %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -fms-extensions -Wno-delete-incomplete %s
// expected-no-diagnostics
#define P(e) static_assert(noexcept(e), "expected nothrow")
@@ -91,6 +91,8 @@ struct S2 {
void *operator new(__typeof__(sizeof(int)) sz, int) throw();
+struct IncompleteStruct;
+
struct Bad1 {
~Bad1() throw(int);
};
@@ -104,6 +106,7 @@ void implicits() {
N(new int);
P(new (0) int);
P(delete (int*)0);
+ P(delete (IncompleteStruct*)0);
N(delete (Bad1*)0);
N(delete (Bad2*)0);
N(S2());
More information about the cfe-commits
mailing list