[Issue 22505] Array relocation causes multiple calls to destructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 12 10:37:47 UTC 2021


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

--- Comment #1 from omerfirmak at gmail.com ---
Previous sample code was missing some parts;

--------------------

import std;
import core.memory;

struct B
{
        int[] b;
    ~this ()
    {
                b[0]++;
                writeln(b[0]);
    }
        @disable this(this);
        this (ref B rhs) @trusted nothrow pure
        {
                this.b = rhs.b.dup;
        }
}

void main()
{
        B[] b_list;
        foreach(idx; 0 ..100)
            b_list ~= B([0]);
        b_list.length = 0;
    GC.collect();
}

--


More information about the Digitalmars-d-bugs mailing list