[Issue 16180] Unable to dispose an interface with std.experiment.allocator

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jun 17 06:51:18 PDT 2016


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

b2.temp at gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp at gmx.com

--- Comment #1 from b2.temp at gmx.com ---
(In reply to Maik Klein from comment #0)
> I opened a stack overflow question which contains all the needed details 
> 
> http://stackoverflow.com/questions/37868594/disposing-a-class-with-an-
> interface?lq=1

There a dispose overload that works with interface. It's available because you
can retrieve the object that implements the interface using "cast(Object) itf".

So to me the report is invalid:

uint a;
interface Bar{}
class Foo: Bar
{
    ~this(){a = 1;}
}

void main()
{
    import std.experimental.allocator.mallocator;
    import std.experimental.allocator;
    auto f = Mallocator.instance.make!Foo();
    Bar b = f;
    Mallocator.instance.dispose(b);
    assert(a == 1);
} 

I think that on S.O you ignore what is done here

https://github.com/dlang/phobos/blob/master/std/experimental/allocator/package.d#L1135

This is basically what allows to destroy an object from its interface.

--


More information about the Digitalmars-d-bugs mailing list