Bug 22174 – destroy should be @nogc when class destructor is @nogc

Status
NEW
Severity
major
Priority
P4
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-03T18:12:19Z
Last change time
2024-12-07T13:41:14Z
Assigned to
No Owner
Creator
sbuhesap
Moved to GitHub: dmd#17195 →

Comments

Comment #0 by sbuhesap — 2021-08-03T18:12:19Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17195 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB