Hi, I have done some experiments with the rvalue reference feature on the cxx0x-branch.
If I execute the following program: ------------------------- #include <iostream> struct A { A () { std::cout << "def ctor" << std::endl; } A (const A&) { std::cout << "normal copy" << std::endl; } A (A&&) { std::cout << "rvalue ref copy" << std::endl; } ~A () { std::cout << "dtor" << std::endl; } }; A f() { return A(); } int main() { A c = f(); } ------------------------ I get : ----- def ctor rvalue ref copy dtor rvalue ref copy dtor dtor ------ Now if I comment out the "rvalue reference constructor", I get the optimal: ---- def ctor dtor ---- I am wondering: is this behavior (2 extra copies) required by the rvalue-reference specifications, or would gcc be allowed to do better? Even if the whole point of rvalue-reference copies is that they are supposed to be cheap (can we count on them to be fully optimized by the lower level optimizers, in principle?), it would probably be better to still be allowed to skip the 2 extra copies completely using the RVO, even for objects defining an rvalue-ref copy constructor, right? BTW, http://gcc.gnu.org/projects/cxx0x.html does not yet mention the rvalue reference patch. -- Sylvain Pion INRIA Sophia-Antipolis Geometrica Project CGAL, http://cgal.org/