[Issue 20582] New: destroy should be @nogc if class constructor is @nogc
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sat Feb 15 13:27:26 UTC 2020
    
    
  
https://issues.dlang.org/show_bug.cgi?id=20582
          Issue ID: 20582
           Summary: destroy should be @nogc if class constructor is @nogc
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: htvennik at gmail.com
-----
class C
{
    ~this() @nogc { }
}
void foo()
{
    auto c = new C();
    () @nogc { destroy(c); } ();
}
-----
Above code snippet should compile, but doesn't:
destroy_nogc.d(9): Error: @nogc delegate destroy_nogc.foo.__lambda1 cannot call
non- at nogc function object.destroy!(true, C).destroy
This also causes the following to fail:
-----
import std.experimental.allocator : make, dispose;
import std.experimental.allocator.mallocator : Mallocator;
class C
{
    ~this() @nogc { }
}
void foo() @nogc
{
    auto c = Mallocator.instance.make!C();
    Mallocator.instance.dispose(c);
}
-----
Here, dispose is inferred to be non- at nogc because it calls destroy, which is
not @nogc, and thus the following error is produced:
make_dispose_nogc.d(12): Error: @nogc function make_dispose_nogc.foo cannot
call non- at nogc function std.experimental.allocator.dispose!(shared(Mallocator),
C).dispose
This effectively makes it impossible to write 100% @nogc code.
--
    
    
More information about the Digitalmars-d-bugs
mailing list