dmd 2.012
import std.stdio; alias writefln p; struct S { int id; this(this) { p("this(this):", id); } ~this() { p("~this():", id); } }
void main() { S b; b.id = 10; { p(1); S a; a.id = 1; } { p(2); S a = b; a.id = 2; } { p(3); S a; a.id = 3; a = b; } { p(4); S* a = new S; a.id = 4; *a = b; delete a; } { p(5); scope S* a = new S; } p(6); } /+ 1 ~this():1 2 this(this):10 ~this():2 3 this(this):10 ~this():3 ~this():10 4 this(this):10 ~this():4 ~this():10 5 6 ~this():10 +/
んー? b のデストラクタってこんなに呼ばれていいんかいな.
p(5)は思いつきでやってみたおまけ.