The code for "object.destroy" for static arrays looks like: void destroy(T : U[n], U, size_t n)(ref T obj) if (!is(T == struct)) { foreach_reverse (ref e; obj[]) destroy(e); } I think the template constraint is to avoid structs that have an "alias this" pointing to a static array. The same can happen for classes as well.
I agree with you. I made a unittest for checking this --- unittest { struct S { static dtorCount = 0; ~this() { ++dtorCount; } } class C { static dtorCount = 0; ~this() { ++dtorCount; } } struct A(T) { T[3] a; alias a this; } auto as = new A!S; destroy(as); auto ac = new A!C; destroy(as); assert(S.dtorCount == 3); // 0 assert(C.dtorCount == 3); // 0 }
(In reply to karita from comment #1) > I agree with you. I made a unittest for checking this [...] That unittest is wrong because it destroys the >pointer< to an A instead of the instance (`destroy` takes its arguments by ref).
@MoonlightSentinel created dlang/druntime pull request #2942 "Fix Issue 19218 - object.destroy should check for classes for static …" fixing this issue: - Fix Issue 19218 - object.destroy should check for classes for static arrays https://github.com/dlang/druntime/pull/2942
dlang/druntime pull request #2942 "Fix Issue 19218 - object.destroy should check for classes for static …" was merged into master: - 453b320bf13239faf73ff969d0095187ac9f0ecc by MoonlightSentinel: Fix Issue 19218 - object.destroy should check for classes for static arrays https://github.com/dlang/druntime/pull/2942