
12 Feb
2006
12 Feb
'06
3:10 a.m.
"Eric Niebler" <eric@boost-consulting.com> wrote
Vertleyb wrote:
I am still not sure though, if the lifetime is extended far enough for this case, or does this just work correctly by accident... (have to take a closer look into the Standard)
This is broken. f() returns a temporary, which is bound to a const ref and has its lifetime extended to the end of the scope containing the const ref. So when ff() returns, the temporary object will be cleaned up, so ff() is returning a dead reference. If you use an object with a destructor instead of int, you can set a breakpoint to verify.
I see... So, this makes my original assumption wrong :-( Any luck with telling const x from const x&? Regards, Arkadiy