import core.stdc.stdio;
struct S
{
        ~this()
        {
                printf("%x\n".ptr, &this);
        }
}
void main()
{
        S* sp = new S;
        destroy(*sp);

        S s;
        destroy(s);

        auto sa = new S[2];
        foreach(ref s_; sa)
                destroy(s_);
}

output:

4002dff0
bfa89a70
4002dfe0
4002dfe1
bfa89a70

Note the double destruction of s

Its seems that calling destroy on a stack-allocated struct is a no-no (unless you have a re-entrant destructor). The other two examples seem OK though.

Am I in dangerous territory? Will I see unexpected double-destructions in some cases?

Reply via email to