https://issues.dlang.org/show_bug.cgi?id=16197
Walter Bright <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] Severity|critical |enhancement --- Comment #9 from Walter Bright <[email protected]> --- (In reply to Max Samukha from comment #7) > Should be either two destructors or no postblit. For "Elem arr" instead of > "Elem[1] arr", only the destructor is correctly called once. What's happening here is that arrays are constructed by calling _d_arraysetctor(). That works by passing it an instance of the object Elem being constructed, which is the Elem.init object, and then copying it into arr[1]. The copy operation invokes the postblit. The code doing the postblit is here: https://github.com/dlang/druntime/blob/master/src/rt/arrayassign.d#L245 Then when it goes out of scope, the destructor is called. That's why you see a single postblit and a single destructor. The code is not incorrect, this is not a bug. However, it can be improved to skip the postblit for default initialization. Therefore, I'm going to re-categorize this as an enhancement request. --
