On Monday, 25 November 2019 at 13:09:44 UTC, mipri wrote:
gdc assembly. ldc eliminates the object entirely.

DIP-1000 kicks comes to the rescue here aswell:


class C
{
    @safe pure nothrow @nogc:
    this(int x)
    {
        this.x = x;
    }
    int x;
}

C leakClass() @safe pure nothrow
{
    scope x = new C(42);
return x; // Error: scope variable `x` may not be returned
}

@safe pure nothrow unittest
{
    auto x = leakClass();
}


Brilliant!

Reply via email to