www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23337] New: Wrongly elided postblit/copy ctor for array


          Issue ID: 23337
           Summary: Wrongly elided postblit/copy ctor for array
                    construction (_d_arrayctor lowering)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kinke gmx.net

The following code worked for DMD v2.085-2.090, but regressed with v2.091 and
still fails with current DMD master, after the templated `_d_arrayctor`

void main() {
    int copies;
    struct S
        int i;
        this(this) { ++copies; }
        //this(inout ref S) inout { ++copies; }

    import core.lifetime;
    S[2] ss1 = void;
    S[2] ss2;

    emplace(&ss1, ss2);
    assert(copies == 2);

    copies = 0;
    emplace(&ss1, ss2[]);
    assert(copies == 2); // fails (is 0)

[It works just fine with LDC though.] This came up when bumping LDC's frontend,
as the glue layer would still lower this to old untemplated `_d_arrayctor`. So
the frontend misses the new templated `_d_arrayctor` lowering in this case; the
according buggy logic is probably here:

Sep 15 2022