From: Peter Collingbourne Date: Sun, 27 Nov 2011 22:09:28 +0000 (+0000) Subject: In Sema::MaybeBindToTemporary, create a CXXBindTemporaryExpr for an X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bceb75528a4a9757f85df002ab45c6002dc10f94;p=clang In Sema::MaybeBindToTemporary, create a CXXBindTemporaryExpr for an array of objects with non-trivial destructors. PR11365. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145203 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 99e9002a48..1bbf8494fa 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -618,8 +618,9 @@ CXXTemporary *CXXTemporary::Create(ASTContext &C, CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, CXXTemporary *Temp, Expr* SubExpr) { - assert(SubExpr->getType()->isRecordType() && - "Expression bound to a temporary must have record type!"); + assert((SubExpr->getType()->isRecordType() || + SubExpr->getType()->isArrayType()) && + "Expression bound to a temporary must have record or array type!"); return new (C) CXXBindTemporaryExpr(Temp, SubExpr); } diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 7b5c358f7d..973e92d214 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4116,7 +4116,8 @@ ExprResult Sema::MaybeBindToTemporary(Expr *E) { if (!getLangOptions().CPlusPlus) return Owned(E); - const RecordType *RT = E->getType()->getAs(); + QualType ET = Context.getBaseElementType(E->getType()); + const RecordType *RT = ET->getAs(); if (!RT) return Owned(E); diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index 98e5ae3e6e..e90c94796f 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -519,3 +519,21 @@ namespace PR8623 { b ? A(2) : A(3); } } + +namespace PR11365 { + struct A { A(); ~A(); }; + + // CHECK: define void @_ZN7PR113653fooEv( + void foo() { + // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [3 x [[A:%.*]]]* {{.*}}, i32 0, i32 0 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 3 + // CHECK-NEXT: br label + + // CHECK: [[PHI:%.*]] = phi + // CHECK-NEXT: [[ELEM:%.*]] = getelementptr inbounds [[A]]* [[PHI]], i64 -1 + // CHECK-NEXT: call void @_ZN7PR113651AD1Ev([[A]]* [[ELEM]]) + // CHECK-NEXT: icmp eq [[A]]* [[ELEM]], [[BEGIN]] + // CHECK-NEXT: br i1 + (void) (A [3]) {}; + } +}