From fc1e6c79bbfe0e9a58bb792996d51f42e36e3d6a Mon Sep 17 00:00:00 2001 From: John McCall Date: Sat, 18 Sep 2010 00:58:34 +0000 Subject: Fix a bug with binding l-values to elided temporaries, and leave a couple helpful asserts behind. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114250 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprCXX.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/CodeGen/CGExprCXX.cpp') diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 4dbfa7ee4f..aadceff8be 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -280,10 +280,12 @@ CodeGenFunction::EmitCXXConstructExpr(const CXXConstructExpr *E, if (CD->isTrivial() && CD->isDefaultConstructor()) return; - // Code gen optimization to eliminate copy constructor and return - // its first argument instead, if in fact that argument is a temporary - // object. + // Elide the constructor if we're constructing from a temporary. + // The temporary check is required because Sema sets this on NRVO + // returns. if (getContext().getLangOptions().ElideConstructors && E->isElidable()) { + assert(getContext().hasSameUnqualifiedType(E->getType(), + E->getArg(0)->getType())); if (E->getArg(0)->isTemporaryObject(getContext(), CD->getParent())) { EmitAggExpr(E->getArg(0), Dest); return; -- cgit v1.2.3