Bug 7032 – OpAssign is not called when this(this) is disabled
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-11-29T13:16:00Z
Last change time
2016-02-09T13:40:59Z
Assigned to
nobody
Creator
deadalnix
Comments
Comment #0 by deadalnix — 2011-11-29T13:16:21Z
As of http://digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=150299
If we disable this(this) in a struct, the opAssign member function should be used if it exists. Here is a sample code :
module fail2;
struct Fail {
@disable
this(this);
ref Fail opAssign(ref const Fail t) {
return this;
}
}
int main(string[] argv) {
Fail a;
Fail b = a; // Error: struct fail2.Fail is not copyable because it is annotated with @disable
return 0;
}
Comment #1 by k.hara.pg — 2016-02-09T13:40:59Z
OpAssign never work when a variable is initialized. In this line:
> Fail b = a;
'b' is yet not born, but opAssign needs a living 'this' instance. Therefore, the variable 'b' initialization with an lvalue 'a' always tries to copy 'a', then rejected by @disable this(this).