Boost logo

Boost :

Subject: Re: [boost] [operators] moving forward use return by reference for compilers with proper support?
From: Andrew Ho (helloworld922_at_[hidden])
Date: 2013-04-30 21:06:22


> They do NOT apply to this scenario:
>
> X&& func(X&& x) { return std::move(x); }
> const X& r3 = func(temporary()); // DANGLING REFERENCE
> X&& r4 = func(temporary()); // DANGLING REFERENCE

Hmm, I see.

sub-clause of 12.2 clause 5:

> The lifetime of a temporary bound to the returned value in a function
return statement (6.6.3) is not extended; the temporary is destroyed at the
end of the full-expression in the return statement.

I presume there must be some implementation detail on why a returned
temporaries' lifetime can't be extended.

Too bad, looks like return by value is the best option available.


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