[Issue 19894] Structs with disabled postblit is still not copyable after defining a copy constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 23 11:32:39 UTC 2019


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

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305 at gmail.com
         Resolution|---                         |INVALID

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
Once a postblit is defined (even if it is marked @disable) all copy
constructors are ignored (in the sense that the compiler will not insert calls
to them; the copy constructors can still be called explicitly).

In this specific situation, disabling the postblit in a member field will make
the struct uncopyable, which is the correct behavior. If you want to make A
uncopyable but still, have Move(T) copyable, simply use only copy constructors:

struct Move(T) {
private:
        import std.algorithm : move;
        T storage;
public:
        this(ref return scope Move rhs) {}
}

struct A {
        @disable this(ref A);
}

void main() {
        Move!A x;
        Move!A y = x;
}

--


More information about the Digitalmars-d-bugs mailing list