Re: NRVO or I think so
"K?r?at" <kursattheking@gmail.com> wrote in message
news:OfmcnA8oJHA.5100@TK2MSFTNGP03.phx.gbl
I expeced this output :
Constructor... (For line 3)
Copy constructor... (For line 7, a temporary object is
copy-constructed from foo_1)
Destructor... (For foo_1)
Copy constructor... (For line 12, foo is copy-constructed from the
temporary object)
Destructor... (for foo)
Destructor... (for the temporary object)
but the real output is (using Visual Studio 2008 compiler with debug
configuration) :
Constructor...
Copy constructor...
Destructor...
Destructor...
When I checked the assemby out I see address of the foo pushed into
the stack and used directly in getFoo () rather than creating a new
temporary. This is the optimization named NRVO, isn't this?
No. NRVO would have eliminated the last remaining
copy-constructor/destructor pair, by having foo_1 be an alias for the
space reserved for return value.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925