Bug 19894 – Structs with disabled postblit is still not copyable after defining a copy constructor

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-05-23T10:18:05Z
Last change time
2019-05-23T11:32:39Z
Assigned to
No Owner
Creator
Yuxuan Shui

Comments

Comment #0 by yshuiv7 — 2019-05-23T10:18:05Z
Comment #1 by razvan.nitu1305 — 2019-05-23T11:32:39Z
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; }