diff options
author | Anders Carlsson <andersca@mac.com> | 2009-10-18 21:20:14 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-10-18 21:20:14 +0000 |
commit | 4fa26848acfbec29a748df4b58d6d654027b49c7 (patch) | |
tree | e72dfb59d823d74a12b09016998e52b942898282 | |
parent | 01eb9b9683535d8a65c704ad2c545903409e2d36 (diff) |
When building a cast argument, make sure to bind the result to a temporary.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84448 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 13 | ||||
-rw-r--r-- | test/CodeGenCXX/temporaries.cpp | 22 |
2 files changed, 31 insertions, 4 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index b6dcd76d46..ebb5b519c1 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2202,9 +2202,14 @@ Sema::OwningExprResult Sema::BuildCXXCastArgument(SourceLocation CastLoc, MultiExprArg(*this, (void **)&From, 1), CastLoc, ConstructorArgs)) return ExprError(); - - return BuildCXXConstructExpr(CastLoc, Ty, cast<CXXConstructorDecl>(Method), - move_arg(ConstructorArgs)); + + OwningExprResult Result = + BuildCXXConstructExpr(CastLoc, Ty, cast<CXXConstructorDecl>(Method), + move_arg(ConstructorArgs)); + if (Result.isInvalid()) + return ExprError(); + + return MaybeBindToTemporary(Result.takeAs<Expr>()); } case CastExpr::CK_UserDefinedConversion: { @@ -2216,7 +2221,7 @@ Sema::OwningExprResult Sema::BuildCXXCastArgument(SourceLocation CastLoc, // Create an implicit call expr that calls it. CXXMemberCallExpr *CE = BuildCXXMemberCallExpr(From, Method); - return Owned(CE); + return MaybeBindToTemporary(CE); } } } diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index 03fbd4b8d9..d622193f59 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -93,3 +93,25 @@ void f6() { F().f(); } +struct G { + G(); + G(A); + ~G(); + operator A(); +}; + +void a(const A&); + +void f7() { + // CHECK: call void @_ZN1AC1Ev + // CHECK: call void @_Z1aRK1A + // CHECK: call void @_ZN1AD1Ev + a(A()); + + // CHECK: call void @_ZN1GC1Ev + // CHECK: call void @_ZN1Gcv1AEv + // CHECK: call void @_Z1aRK1A + // CHECK: call void @_ZN1AD1Ev + // CHECK: call void @_ZN1GD1Ev + a(G()); +} |