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();