www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Structs intended to run destructor immediately if not assigned to a

reply rsw0x <anonymous anonymous.com> writes:
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
Jan 14
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Jan 14