[cfe-commits] r124002 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CXX/special/class.copy/p33-0x.cpp

Douglas Gregor dgregor at apple.com
Fri Jan 21 14:46:35 PST 2011


Author: dgregor
Date: Fri Jan 21 16:46:35 2011
New Revision: 124002

URL: http://llvm.org/viewvc/llvm-project?rev=124002&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CXX/special/class.copy/p33-0x.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=124002&r1=124001&r2=124002&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Jan 21 16:46:35 2011
@@ -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>();

Modified: cfe/trunk/test/CXX/special/class.copy/p33-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/special/class.copy/p33-0x.cpp?rev=124002&r1=124001&r2=124002&view=diff
==============================================================================
--- cfe/trunk/test/CXX/special/class.copy/p33-0x.cpp (original)
+++ cfe/trunk/test/CXX/special/class.copy/p33-0x.cpp Fri Jan 21 16:46:35 2011
@@ -16,4 +16,10 @@
   else
     return x;
 }
+
+void throw_move_only(X x) {
+  X x2;
+  throw x;
+  throw x2;
+}
   





More information about the cfe-commits mailing list