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

Teodor Dutu <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #2 from Teodor Dutu <[email protected]> ---
a ~= S() is not supposed to call either the copy constructor or the postblit
because the newly appended element is supposed to be created in-place inside
the array. This test ensures this behaviour (only the constructor is called,
without the postblit):
https://github.com/dlang/dmd/blob/d405b343e301e5c37a90e66131b3f4d588bed2f2/compiler/test/runnable/sdtor.d#L2244-L2245

The issue comes from copying the array during reallocation. The postblit is
correctly called while the cpctor is not. The following code prints "loop" 15
times before printing "pblit" 15 times when the array is reallocated:

---
struct S
{
    this(this)
    {
        writeln("pblit");
    }
}

void main()
{
    S[] a = [ S() ];
    auto p = a.ptr;
    // append until reallocation
    while (a.ptr == p)
    {
        writeln("loop");
        a ~= S(); // no assert
    }
}
---

--

Reply via email to