forked from OSchip/llvm-project
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. llvm-svn: 124002
This commit is contained in:
parent
f694a55736
commit
c74edc272e
|
|
@ -517,13 +517,14 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) {
|
||||||
|
|
||||||
// Initialize the exception result. This implicitly weeds out
|
// Initialize the exception result. This implicitly weeds out
|
||||||
// abstract types or types with inaccessible copy constructors.
|
// 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.
|
// FIXME: Determine whether we can elide this copy per C++0x [class.copy]p32.
|
||||||
InitializedEntity Entity =
|
InitializedEntity Entity =
|
||||||
InitializedEntity::InitializeException(ThrowLoc, E->getType(),
|
InitializedEntity::InitializeException(ThrowLoc, E->getType(),
|
||||||
/*NRVO=*/false);
|
/*NRVO=*/false);
|
||||||
ExprResult Res = PerformCopyInitialization(Entity,
|
ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOVariable,
|
||||||
SourceLocation(),
|
QualType(), E);
|
||||||
Owned(E));
|
|
||||||
if (Res.isInvalid())
|
if (Res.isInvalid())
|
||||||
return true;
|
return true;
|
||||||
E = Res.takeAs<Expr>();
|
E = Res.takeAs<Expr>();
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,10 @@ X return_by_move(int i, X x) {
|
||||||
else
|
else
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void throw_move_only(X x) {
|
||||||
|
X x2;
|
||||||
|
throw x;
|
||||||
|
throw x2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue