Should __ArrayDtor be called for uninitialised arrays?

Adam D Ruppe destructionator at gmail.com
Thu Nov 18 13:32:32 UTC 2021


On Thursday, 18 November 2021 at 12:27:54 UTC, Teodor Dutu wrote:
> Is this the expected behaviour?

Yes, this is specified.

https://dlang.org/spec/struct.html#struct-destructor

It is always called when it goes out of scope. You're supposed to 
ensure S.init's destructor is a harmless no-op because it is 
always called. But if you void initialize of course it isn't 
S.init, it is S.random.

But the spec does give you a way to handle destruction yourself: 
use a union. See more: 
http://dpldocs.info/this-week-in-d/Blog.Posted_2021_03_15.html#tip-of-the-week



More information about the Digitalmars-d mailing list