[Issue 23937] New: LDC with -nogc and DMD object.destroy

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 25 15:17:18 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23937

          Issue ID: 23937
           Summary: LDC with -nogc and DMD object.destroy
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: black80 at bk.ru

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- at 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`

--


More information about the Digitalmars-d-bugs mailing list