Surprise destructor call...

user1234 user1234 at 12.de
Wed Aug 14 12:42:13 UTC 2024


On Wednesday, 14 August 2024 at 11:52:51 UTC, Dennis wrote:
> [...]
> Now we have a 'DotVarExp' with a struct literal on the left, 
> and the struct has a destructor. Since internally expression 
> temporaries can't have destructors, it gets extracted into a 
> temporary variable:
>
> ```D
> return ((Thing __slThing3 = Thing();) , __slThing3).this(null);
> ```
>
> Then `__slThing3` goes out of scope and needs a destructor call.
>
> So clearly, in this case you don't want the temporary, but in 
> other cases (`return Thing(null).field;`) you do need it, so 
> I'm thinking about what the right conditions should be for the 
> temporary.

The hidden temporary is not represented in the -vcg-ast output. 
That would have helped to understand the issue.


More information about the Digitalmars-d mailing list