[Issue 15009] Object.destroy doesn't call dtors for object in static arrays

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Sep 3 14:23:47 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15009

--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
The bug in Object.destroy overload for the static array is, that is using block
assignment.

void destroy(T : U[n], U, size_t n)(ref T obj)
  if (!is(T == struct))
{
    obj[] = U.init;
}

obj[] = U.init; _copies_ the rhs for each elements of lhs, and destroys the
original elements of lhs. Instead of that, it should just destroy the elements.

And, the order of destroying should occur from the last to the first.

Then' the fixed destroy function should be:

void destroy(T : U[n], U, size_t n)(ref T obj)
  if (!is(T == struct))
{
    foreach_reverse (ref e; obj[])
        e = U.init;
}

--


More information about the Digitalmars-d-bugs mailing list