[cfe-commits] r113664 - in /cfe/trunk: lib/AST/Expr.cpp test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Fri Sep 10 16:27:10 PDT 2010
Author: cornedbee
Date: Fri Sep 10 18:27:10 2010
New Revision: 113664
URL: http://llvm.org/viewvc/llvm-project?rev=113664&view=rev
Log:
Test destructors in delete expressions and of temporaries for throwing.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=113664&r1=113663&r2=113664&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Sep 10 18:27:10 2010
@@ -1457,11 +1457,32 @@
}
case CXXDeleteExprClass: {
- // FIXME: check if destructor might throw
CanThrowResult CT = CanCalleeThrow(
cast<CXXDeleteExpr>(this)->getOperatorDelete());
if (CT == CT_Can)
return CT;
+ const Expr *Arg = cast<CXXDeleteExpr>(this)->getArgument();
+ // Unwrap exactly one implicit cast, which converts all pointers to void*.
+ if (const ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(Arg))
+ Arg = Cast->getSubExpr();
+ if (const PointerType *PT = Arg->getType()->getAs<PointerType>()) {
+ if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) {
+ CanThrowResult CT2 = CanCalleeThrow(
+ cast<CXXRecordDecl>(RT->getDecl())->getDestructor());
+ if (CT2 == CT_Can)
+ return CT2;
+ CT = MergeCanThrow(CT, CT2);
+ }
+ }
+ return MergeCanThrow(CT, CanSubExprsThrow(C, this));
+ }
+
+ case CXXBindTemporaryExprClass: {
+ // The bound temporary has to be destroyed again, which might throw.
+ CanThrowResult CT = CanCalleeThrow(
+ cast<CXXBindTemporaryExpr>(this)->getTemporary()->getDestructor());
+ if (CT == CT_Can)
+ return CT;
return MergeCanThrow(CT, CanSubExprsThrow(C, this));
}
@@ -1486,8 +1507,7 @@
case ParenListExprClass:
case VAArgExprClass:
case CXXDefaultArgExprClass:
- case CXXBindTemporaryExprClass:
- case CXXExprWithTemporariesClass: // FIXME: this thing calls destructors
+ case CXXExprWithTemporariesClass:
case ObjCIvarRefExprClass:
case ObjCIsaExprClass:
case ShuffleVectorExprClass:
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=113664&r1=113663&r2=113664&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 Fri Sep 10 18:27:10 2010
@@ -86,9 +86,19 @@
void *operator new(__typeof__(sizeof(int)) sz, int) throw();
+struct Bad1 {
+ ~Bad1() throw(int);
+};
+struct Bad2 {
+ void operator delete(void*) throw(int);
+};
+
void implicits() {
N(new int);
P(new (0) int);
+ P(delete (int*)0);
+ N(delete (Bad1*)0);
+ N(delete (Bad2*)0);
N(S2());
P(S2(0, 0));
S2 s;
@@ -98,7 +108,7 @@
P(s - 0);
N(static_cast<int>(s));
P(static_cast<float>(s));
- // FIXME: test destructors of temporaries
+ N(Bad1());
}
struct V {
More information about the cfe-commits
mailing list