[Issue 20285] New: Struct destructor called multiple times in dynamic arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 8 19:46:24 UTC 2019


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

          Issue ID: 20285
           Summary: Struct destructor called multiple times in dynamic
                    arrays
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: graham.stjack at internode.on.net

With dmd 2.088, this code:

import std.stdio;

struct Foo {
    int value;
    @disable this(this);
    ~this() { writefln("Destroying foo %s", value); }
}

void main() {
    Foo[] array;
    array.length = 1;
    array[0] = Foo(0);
    array.length = 2;
    array[1] = Foo(1);
}

produces this output:

Destroying foo 0
Destroying foo 0
Destroying foo 0
Destroying foo 1
Destroying foo 0

when what I want is:

Destroying foo 0
Destroying foo 1

I assume that despite Foo being uncopyable, it is being copied by the dynamic
array implementation rather than being moved.

--


More information about the Digitalmars-d-bugs mailing list