Re: [boost] [operators] moving forward use return by reference for compilers with proper support?
1 May
2013
1 May
'13
1:06 a.m.
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.
4229
Age (days ago)
4229
Last active (days ago)
0 comments
1 participants
participants (1)
-
Andrew Ho