Stupid scope destruction question
monarch_dodra
monarchdodra at gmail.com
Mon Sep 24 00:49:28 PDT 2012
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."
>>
>
> Thanks, looks like D does have C++ behaviour here. But your
> last statement about return value is incorrect. More than that
> function call doesn't change anything.
>
> Correct answers are here:
> * `12.2 Temporary objects [class.temporary]` section of C++
> standard
> *
> http://stackoverflow.com/questions/2506793/c-life-span-of-temporary-arguments
> *
> http://stackoverflow.com/questions/5459759/full-expression-boundaries-and-lifetime-of-temporaries
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.
Unless you were playing on the words "gone out of scope" (which
is indeed not the 100% correct), I don't see how my statement is
incorrect.
More information about the Digitalmars-d-learn
mailing list