Stupid scope destruction question

Ali Çehreli acehreli at yahoo.com
Mon Sep 24 10:50:14 PDT 2012


On 09/24/2012 12:49 AM, monarch_dodra wrote:
 > On Monday, 24 September 2012 at 07:25:28 UTC, Denis Shelomovskij wrote:
 >> 20.09.2012 15:35, monarch_dodra пишет:
 >>>
 >>> AFAIK, if the rules are the same in C++ (which they probably are), 
then:
 >>> "Any object constructed during argument passing will remain valid for
 >>> the duration of the call. It will go out of scope once the function has
 >>> finished returning, and after the return value has itself gone out of
 >>> scope and been destroyed."

That sounds like you are saying that the temporary S() is destroyed 
after 'r' below:

     // C++ code
     R r = foo(S());

 > How is my statement incorrect? The "function call" itself doesn't change
 > anything sure, since it is more generally a "full expression": The
 > return value itself is created *during* that full expression, but after
 > the creation of the arguments. Last in, first out, it is destroyed
 > before the passed in arguments.

That is not correct. The temporary S() is destroyed at the end of the 
assignment expression (at the semicolon), while 'r' will live until the 
end of the current scope.

Ali



More information about the Digitalmars-d-learn mailing list