struct postblit not called, but still destructed

Benjamin Thaut code at benjamin-thaut.de
Sun Jan 19 11:24:24 PST 2014


Am 19.01.2014 18:48, schrieb Lemonfiend:
> import std.stdio;
>
> struct C
> {
>      A[] _objs;
>
>      this(A[] objs...)
>      {
>          writeln(`  C this()`);
>          _objs = objs;
>
>          // A.this(this) is not called
>          // yet A.~this IS called
>      }
> }
>
> struct B
> {
>      A sup;
>      alias sup this;
>
>      this(A a)
>      {
>          writeln(count, ` B this()`);
>          sup = a;
>      }
> }
>
> struct A
> {
>      static int count;
>
>      this(int n)
>      {
>          count++;
>          writeln(count, ` A this()`);
>      }
>
>      this(this)
>      {
>          count++;
>          writeln(count, ` A this(this)`);
>      }
>
>      ~this()
>      {
>          count--;
>          writeln(count, ` A ~this()`);
>      }
> }
>
> void main()
> {
>      A a = A(1);
>      writeln(a.count == 1);
>
>      B b = B(a);
>      writeln(a.count == 2);
>
>      C c = C(b);
>      writeln(a.count == 3);
> }


Yes this looks like a bug to me. Please file a bug report at 
https://d.puremagic.com/issues/

Kind Regards
Benjamin Thaut


More information about the Digitalmars-d-learn mailing list