aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-01-21 22:46:35 +0000
committerDouglas Gregor <dgregor@apple.com>2011-01-21 22:46:35 +0000
commit72dfa27b415b15157a9d1fc33b6ed21f0085bed2 (patch)
treee42e929167b7928c6792531b8ef00b2c8c686d1b
parent07f402cff25354c5f06f307f19b0c57c09d964bd (diff)
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
-rw-r--r--lib/Sema/SemaExprCXX.cpp11
-rw-r--r--test/CXX/special/class.copy/p33-0x.cpp6
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 2e5204f258..0b7a051365 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -517,13 +517,14 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) {
// 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>();
diff --git a/test/CXX/special/class.copy/p33-0x.cpp b/test/CXX/special/class.copy/p33-0x.cpp
index a9ce58937a..38eb7adb38 100644
--- a/test/CXX/special/class.copy/p33-0x.cpp
+++ b/test/CXX/special/class.copy/p33-0x.cpp
@@ -16,4 +16,10 @@ X return_by_move(int i, X x) {
else
return x;
}
+
+void throw_move_only(X x) {
+ X x2;
+ throw x;
+ throw x2;
+}