[Issue 5895] Object.clear() doesn't work as expected for pointers to structs

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Jan 24 17:41:04 PST 2015


https://issues.dlang.org/show_bug.cgi?id=5895

AndyC <andy at squeakycode.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andy at squeakycode.net

--- Comment #2 from AndyC <andy at squeakycode.net> ---
This might be closeable.

object.close() is deprecated and the compiler warns you should use destroy()
instead.  However:

import std.stdio;

struct Bar
{
    ~this()
    {
        writeln("bye");
    }
}

void main()
{
    Bar *b = new Bar();
    destroy(b);
}

Still doesnt call the destructor ... but that's because it needs to be called
as:

destroy(*b)

There is form discussion here:

http://forum.dlang.org/thread/fpvoxowzicqoqlitadyj@forum.dlang.org

I wonder if there is any way the compiler can warn on:

    Bar *b = new Bar();
    destroy(b);

If so I think that should be a new bug, and this one closed.

--


More information about the Digitalmars-d-bugs mailing list