[webkit-dev] PSA: Don't try to hold onto temporaries with references
Leandro Graciá Gil
leandrogracia at chromium.org
Mon Oct 4 04:23:06 PDT 2010
> In summary, looking at code like this
> B& b = c->foo();
> If c->foo() returns a temporary ("return B();"), then it is safe.
Maybe I'm wrong, but are you completely sure about this one? I would say
that the temporary object created in return B() will cease to exist as soon
as it returns (just after the constructor finishes). So you will be
returning a reference to a temporary which, I think, no longer is valid. I
made a quick test to be sure and the destructor of B is indeed called. Why
is it safe?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev