dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Cannot use `__rvalue` expression on a struct(non-copyable) property(non-copyable)

Open GtenIOS opened this issue 6 months ago • 0 comments

import core.memory : pureMalloc, pureFree;
struct S {
    @("mallocd") ubyte[] p;
    this() @disable;
    this(this) @disable;
    this(ubyte[] p) pure @nogc @trusted nothrow {
        this.p = p;
    }

    this(S rhs) pure @nogc @trusted nothrow {
        p = rhs.p;
        rhs.p = null;
    }

    ~this() pure @nogc @trusted nothrow {
        if (p) {
            pureFree(p.ptr);
            p = null;
        }
    }
}

struct Container {
    S s;
    this() @disable;
    this(this) @disable;
    this(S s) pure @nogc @trusted nothrow {
        this.s = __rvalue(s);
    }

    this(Container rhs) pure @nogc @trusted nothrow {
        this.s = __rvalue(rhs.s);
    }
}

Above code results in compilation error:

Error: struct `example.S` is not copyable because it has a disabled postblit
        this.s = __rvalue(rhs.s);

GtenIOS avatar Apr 25 '25 04:04 GtenIOS