Structs intended to run destructor immediately if not assigned to a variable?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 14 22:08:15 PST 2016


On 01/14/2016 09:23 PM, rsw0x wrote:
 > Returning a struct with a destructor and not binding it to a variable
 > appears to make the destructor run immediately instead of at the end of
 > the scope.
 > Is this intended?
 >
 > example:
 > http://dpaste.dzfl.pl/dd285200ba2b

Assuming that this rule is the same as in C++ (and I think so), the 
lifetime of a temporary variable is the whole expression that created 
it. So, the behaviour you are describing is intended.

Ali



More information about the Digitalmars-d-learn mailing list