Hi,

The following code is supposed to destroy the struct instance:

    import std.stdio;
    struct S{
        ~this(){"destruct".writeln;}
        }
    auto p = new S;
    destroy(p);
    "end".writeln;

It works correctly if I use destroy(*p), but the above code could perhaps be statically rejected by object.destroy to help prevent bugs. Currently, the pointer p is set to null without calling the destructor (with recent dmd the destructor is called, but only after "end" is printed).

Here is the destroy overload:

void destroy(T)(ref T obj)
if (!is(T == struct) && !is(T == interface) && !is(T == class) && !_isStaticArray!T)
{
    obj = T.init;
}

Reply via email to