Bug 23937 – LDC with -nogc and DMD object.destroy

Status
RESOLVED
Resolution
MOVED
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2023-05-25T15:17:18Z
Last change time
2023-05-26T07:35:10Z
Assigned to
No Owner
Creator
a11e99z

Comments

Comment #0 by black80 — 2023-05-25T15:17:18Z
code is totally @nogc //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import std, core.lifetime; class C { @nogc: long v; this() @nogc { "C.this()\n".printf; } ~this() @nogc { "C.~this()\n".printf; } void destroy() @nogc { "C.destroy()\n".printf; } void sayHi() @nogc { "hi\n".printf; } } void[ __traits(classInstanceSize, C)] tmem; void main() @nogc { scope auto c = emplace!C( tmem ); //scope( exit) destroy( c); // Error: `@nogc` function `D main` cannot call non-@nogc function `object.destroy!(true, C).destroy` scope( exit) c.destroy(); // OK //scope( exit) c.~C(); // C++ style. doesnt compile c.sayHi(); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1) cannot call global ::destroy( obj) in @nogc context so used own one. https://issues.dlang.org/show_bug.cgi?id=22174 2) code compiles w/o -nogc switch and get strange error with it. why so? \import\core\lifetime.d(107): Error: No implicit garbage collector calls allowed with -nogc option enabled: `_d_array_slice_copy`
Comment #1 by black80 — 2023-05-25T15:28:10Z
ldc --release -nogc empl.d is working. strange.
Comment #2 by razvan.nitu1305 — 2023-05-26T07:35:10Z
Hello, this does not seem to be a dmd-druntime issue. Note that LDC has a modified version of druntime so from dmd's perspective this issue has nothing actionable. You can report this to ldc. > //scope( exit) c.~C(); // C++ style. doesnt compile This works if you call c.__dtor();