Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-02-10 09:52:06


Anthony Williams <anthony.williamsNOSPAM_at_[hidden]> writes:

>> I don't see any problem here. There's no problem getting the rvalue
>> out of source(), or sink(source()) would fail. Furthermore, no
>> compiler I've ever seen will actually make the allowed temporary in
>> that case.
>
> How about
>
> struct X{};
>
> struct Y
> {
> std::string s;
> X x;
> std::vector<int> v;
> };
>
> Y ySource();
>
> const X& x=ySource().x;
>
> This strikes me as more likely to cause a copy than a straight-forward binding
> from an X temporary.

I think the actual problem is one of either interpretation of 8.5.3/5
or overspecification in that very paragraph. If, instead of saying,

   "A temporary of type ``cv1 T2'' [sic] is created, and a constructor
   is called to copy the entire rvalue object into the temporary. The
   reference is bound to the temporary or to a sub-object within the
   temporary"

It said:

   "A temporary of type ``cv1 T2'' [sic] is constructed using direct
   initialization from the rvalue object. The reference is bound to
   the temporary or to a sub-object within the temporary"

we'd be home free.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk