August 03, 2021 [Issue 22174] New: destroy should be @nogc when class destructor is @nogc | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=22174 Issue ID: 22174 Summary: destroy should be @nogc when class destructor is @nogc Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: druntime Assignee: nobody@puremagic.com Reporter: sbuhesap@gmail.com Pretty much same as the issue summary: destroy should be @nogc when class destructor is @nogc. A piece of code that should work but doesn't: ```D import core.stdc.stdlib; import core.lifetime; class Example { int x; ~this() @nogc {} } void main() @nogc { enum size = __traits(classInstanceSize, Example); auto pointer = malloc(size)[0..size]; scope(exit) free(pointer.ptr); Example ex = emplace!(Example)(pointer); // Error: `@nogc` function `D main` cannot call non-@nogc function `object.destroy!(true, Example).destroy` destroy(ex); } ``` There should be a @nogc overload for destroy that allows people to use class destructors. Currently there is no way to call destroy in a @nogc function without breaking the type system. Or just un-deprecating class allocators / dealloctors would work too. A recent discussion I found about this: https://forum.dlang.org/thread/jsrjgmeblfukwhqbwjab@forum.dlang.org -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply