When throwing an elidable object, first try to treat the subexpression
as an rvalue per C++0x [class.copy]p33. If that fails, try again with
the original subexpression.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124002 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 2e5204f..0b7a051 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -517,13 +517,14 @@
// Initialize the exception result. This implicitly weeds out
// abstract types or types with inaccessible copy constructors.
+ const VarDecl *NRVOVariable = getCopyElisionCandidate(QualType(), E, false);
+
// FIXME: Determine whether we can elide this copy per C++0x [class.copy]p32.
InitializedEntity Entity =
- InitializedEntity::InitializeException(ThrowLoc, E->getType(),
- /*NRVO=*/false);
- ExprResult Res = PerformCopyInitialization(Entity,
- SourceLocation(),
- Owned(E));
+ InitializedEntity::InitializeException(ThrowLoc, E->getType(),
+ /*NRVO=*/false);
+ ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOVariable,
+ QualType(), E);
if (Res.isInvalid())
return true;
E = Res.takeAs<Expr>();