On Sunday, 19 January 2014 at 19:24:23 UTC, Benjamin Thaut wrote:
Yes this looks like a bug to me. Please file a bug report at https://d.puremagic.com/issues/

Kind Regards
Benjamin Thaut

Here is a reduced case:

//----
import std.stdio;

struct B
{
        A sup;

        this(A a)
        {
                writeln("Here");
                sup = a;
                writeln("There");
        }
}

struct A
{
        static int count;

        this(int n)
        {
                writeln("A.this()");
        }

        this(this)
        {
                writeln("A.this(this)");
        }

        ~this()
        {
                writeln("A.~this()");
        }
}

void main()
{
        A a = A(1);

        writeln("Start");
        B b = B(a);
        writeln("End");
}
//----
A.this()
Start
A.this(this)
Here
A.this(this) //!!!
A.~this()    //!!!
There
A.~this()
End
A.~this()
A.~this()
//----

I think the behavior is not *strictly* incorrect: When you write:
sup = a;

it triggers a postblit of "a" into "sup". To do said postblit, you destroy sup. It's the way it works :/

Arguably, since it is initialization, we could avoid the destruction altogether, but it's not strictly *wrong*.

I'll file it as an ER, and try to get Kenji on it.

Reply via email to