[Issue 16064] New: std.experimental.allocator.dispose can't be used in @nogc blocks

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon May 23 07:49:34 PDT 2016


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

          Issue ID: 16064
           Summary: std.experimental.allocator.dispose can't be used in
                    @nogc blocks
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: b2.temp at gmx.com

There's a flaw, the following code doesn't compile, even if Mallocator is 100%
@nogc and that the __dtor is @nogc

----
import std.experimental.allocator;
import std.experimental.allocator.mallocator;

class Foo
{
    ~this()@nogc {}
}

void main() @nogc
{
    Foo foo = make!Foo(Mallocator.instance);
    dispose(Mallocator.instance, foo);
} 
----

The problem is due to dispose() that calls destroy() which is not a template
and thus cannot infer the attributes.

A possible fix is to write a custom destroy() that would call __dtor or
__xdtor, at least for classes and pointer to structs, as a template, and used
in dispose().

--


More information about the Digitalmars-d-bugs mailing list