Re: [PATCH] rvalue reference implementation for C++0x
Russell Yanofsky <russ <at> yanofsky.org>
2007-05-01 04:28:37 GMT
On Mon, 2007-04-30 at 18:51 -0400, Doug Gregor wrote:
> Looking more closely at this, I think Jason is right... the B(A)
> allows us to build a B, but we still need a copy constructor to make a
> copy of the B before binding the reference.
You don't need to make a copy of temporary value before binding a
reference to it. You used to need to check for a copy constructor, but
you don't anymore. In C++0x, compilers are required to do a direct
binding here. That's the point I was making at
http://gcc.gnu.org/ml/gcc-patches/2007-04/msg01752.html . And there's
more information about this in DR391:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#391 .
> Now, the compiler is
> permitted to elide the actual copy construction... but the copy
> constructor needs to be there even if the copy construction will be
> elided. I had thought that the rvalue references proposal change this,
> but it did not. This paragraph from N2118 points out explicitly that
> out explicitly:
>
> -16- When the criteria for elision of a copy operation are met and the
> object to be copied is designated by an lvalue, overload resolution to
> select the constructor for the copy is first performed as if the
> object were designated by an rvalue. If overload resolution fails, or
> if the type of the first parameter of the selected constructor is not
> an rvalue-reference to the object's type (possibly cv-qualified),
> overload resolution is performed again, considering the object as an
> lvalue. [Note: This two-stage overload resolution must be performed
> regardless of whether copy elision will occur. It determines the
> constructor to be called if elision is not performed, and the selected
(Continue reading)