[Issue 16197] New: [The D Bug Tracker]

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jun 23 08:08:44 PDT 2016


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

          Issue ID: 16197
           Summary: [The D Bug Tracker]
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: major
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: eyal at weka.io

Post-blit not being called properly:

import std.stdio:writeln;

struct Elem {
    int x = -1;
    this(int x) { this.x = x; writeln("CTOR ", x); }
    this(this) { writeln("POSTBLIT ", x); }
    ~this()    { if (x!=-1) writeln("DTOR "    , x); }
}

struct Ctr {
    Elem[3] arr;
    Elem[] slice() { return arr; }
    Elem[3] arrVal() { return arr; }
}

void main() {
    auto p = Ctr();
    p.arr = [Elem(1), Elem(2), Elem(3)];
    {
        writeln("slice rval -> arr {");
        Elem[3] _arr = p.slice;
        writeln("}");
    }
    {
        writeln("arr rval -> arr {");
        Elem[3] _arr = p.arrVal();
        writeln("}");
    }
}


Prints out:
CTOR 1
CTOR 2
CTOR 3
slice rval -> arr {
}
DTOR 3
DTOR 2
DTOR 1
arr rval -> arr {
POSTBLIT 1
POSTBLIT 2
POSTBLIT 3
}
DTOR 3
DTOR 2
DTOR 1
DTOR 3
DTOR 2
DTOR 1


Note that there are more DTOR's than CTOR/POSTBLITS.

I believe dmd should maintain the same number of CTOR+POSTBLIT calls as DTOR
calls, or all user invariants get broken.

--


More information about the Digitalmars-d-bugs mailing list