On Thu, 2005-09-15 at 07:15 -0700, Pete C wrote:
> > As to why
> > GCC 4.0.2 is trying to pass the temporary to the constructor rather
> > than binding the reference to the temporary (as 3.3.4 does), I don't
> > know.
>
> When initialising a const reference to an rvalue (which we are in this
> case), the compiler may either:
>
> a) Bind the reference directly to the object that the rvalue
> represents, or
> b) Construct a temporary const object from the rvalue, and bind the
> reference to the temporary.
>
> The choice is implementation-defined, but the standard says that the
> constructor that would be used in (b) must be available anyway.
> However for auto_ptr, such a constructor is *not* available, because
> auto_ptr's copy constructor takes a non-const reference (to which an
> rvalue cannot be bound). So the new error is correct. See section
> 8.5.3.5 of the Standard for gory details.
>
> Incidentally, the Microsoft implementation I'm currently looking at
> (incorrectly) provides an auto_ptr which takes a const reference.
> Plenty of code has been written that relies on this, sadly.
>
> The difference with std::string (as questioned elsewhere on this
> thread), is that std::string *does* provide a copy constructor from a
> const reference - so (a) and (b) above are satisfied.
Thanks a lot! I now see why GCC 4.0.2 acts the way it does, and why
it must be that way.
>
--
Mvh / Regards
Rein Anders Apeland
MIVU Solutions
|