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/[email protected]
Comment #1 by sbuhesap — 2021-08-03T18:13:22Z
Maybe relevant: issue 20914
Comment #2 by turkeyman — 2024-10-02T02:11:35Z
This is a serious issue... it needs attention.
Comment #3 by robert.schadek — 2024-12-07T13:41:14Z