Bug 11407 – can't move struct with disabled default constructor
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-31T22:37:31Z
Last change time
2018-10-16T18:28:58Z
Assigned to
No Owner
Creator
Martin Nowak
Comments
Comment #0 by code — 2013-10-31T22:37:31Z
cat > bug.d << CODE
import std.algorithm;
struct Unique
{
int* _p;
@disable this(this); // non-copyable
~this() { _p = null; } // release resource
@disable this(); // non-null
this(int* p) { _p = p; }// acquire resource
}
Unique bug(Unique u)
{
return move(u);
}
CODE
dmd -c bug
----
The use-case is to encapsulate unique ownership in a struct.
It seems the static T empty; in move() is only need to reinitialized the moved value. Maybe it could be done with destroy or by copying from typeid(T).init().ptr.
Comment #1 by n8sh.secondary — 2018-10-16T18:28:58Z
The example code currently compiles so presumably this was fixed in the last 5 years.