www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23563] New: Array length extension ignores copy constructor

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

          Issue ID: 23563
           Summary: Array length extension ignores copy constructor
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

As of DMD 2.101.0, the following program compiles and runs successfully to
completion:

---
struct S
{
    this(ref S)
    {
        assert(0);
    }
}

void main()
{
    S[] a = [ S() ];
    auto p = a.ptr;
    // extend until reallocation
    while (a.ptr == p)
        a.length = a.length + 1; // no assert    
}
---

This program should assert at runtime when the array is reallocated, but does
not, because the copy constructors of the array's elements are not called.

If the copy constructor is changed to a postblit (`this(this)`), the program
asserts at runtime, as expected.

See also issues 23557, 23556, and 20879, which cover array reallocations
triggered by other means.

--
Dec 16 2022