https://issues.dlang.org/show_bug.cgi?id=16197
David Nadlinger <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #3 from David Nadlinger <[email protected]> --- DMD from Git master (v2.072.0-devel-20e1c81) seems to call too many postblits/ctors, though, when initialising the Ctr instances and then assigning the Elem literals: --- construct Ctr { POSTBLIT -1 (7FFF5C07F598) POSTBLIT -1 (7FFF5C07F59C) POSTBLIT -1 (7FFF5C07F5A0) } assign arr { CTOR 1 (7FFF5C07F5B4) CTOR 2 (7FFF5C07F5C0) CTOR 3 (7FFF5C07F5C4) } slice rval -> arr { POSTBLIT 1 (7FFF5C07F5D0) POSTBLIT 2 (7FFF5C07F5D4) POSTBLIT 3 (7FFF5C07F5D8) } DTOR 3 (7FFF5C07F5D8) DTOR 2 (7FFF5C07F5D4) DTOR 1 (7FFF5C07F5D0) arr rval -> arr { POSTBLIT 1 (7FFF5C07F520) POSTBLIT 2 (7FFF5C07F524) POSTBLIT 3 (7FFF5C07F528) } DTOR 3 (7FFF5C07F5F0) DTOR 2 (7FFF5C07F5EC) DTOR 1 (7FFF5C07F5E8) DTOR 3 (7FFF5C07F5A0) DTOR 2 (7FFF5C07F59C) DTOR 1 (7FFF5C07F598) --- Note that the CTOR-created instances (7FFF5C07F5B4 and so on) are never destructed. (The output is from a slightly modified test case that prints the struct address in parens: --- import std.stdio:writeln; struct Elem { int x = -1; this(int x) { this.x = x; writeln("CTOR ", x, " (", cast(void*)&this, ")"); } this(this) { writeln("POSTBLIT ", x, " (", cast(void*)&this, ")"); } ~this() { if (x!=-1) writeln("DTOR " , x, " (", cast(void*)&this, ")"); } } struct Ctr { Elem[3] arr; Elem[] slice() { return arr; } Elem[3] arrVal() { return arr; } } void main() { writeln("construct Ctr {"); auto p = Ctr(); writeln("}"); writeln("assign arr {"); p.arr = [Elem(1), Elem(2), Elem(3)]; writeln("}"); { writeln("slice rval -> arr {"); Elem[3] _arr = p.slice; writeln("}"); } { writeln("arr rval -> arr {"); Elem[3] _arr = p.arrVal(); writeln("}"); } } --- ) --
