digitalmars.D.bugs - [Issue 20582] New: destroy should be nogc if class constructor is
- d-bugmail puremagic.com (48/48) Feb 15 2020 https://issues.dlang.org/show_bug.cgi?id=20582
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 puremagic.com Reporter: htvennik 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- 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- 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- nogc function std.experimental.allocator.dispose!(shared(Mallocator), C).dispose This effectively makes it impossible to write 100% nogc code. --
Feb 15 2020