Bug 7075 – overloading opAssign for classes is poorly specified
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-12-06T20:32:00Z
Last change time
2014-04-23T12:06:06Z
Keywords
pull, spec
Assigned to
andrej.mitrovich
Creator
Jesse.K.Phillips+D
Comments
Comment #0 by Jesse.K.Phillips+D — 2011-12-06T20:32:40Z
The table states that classes do not overload the assignment operator. However this code compiles:
class A {
int a;
string b;
float c;
void opAssign(B b) {
a = b.a;
}
}
class B {
int a;
}
void main()
{
auto a = new A();
a.a = 5;
auto b = new B();
b.a = 10;
a = b;
assert(a.a == 10);
}
Comment #1 by Jesse.K.Phillips+D — 2011-12-06T20:36:26Z
No, the code isn't invalid, the documentation is just bad.
identity assignment overloading is not allowed for classes, that is what the table is alluding to:
class A
{
void opAssign(A a) {}
}
Error: function testassign.A.opAssign identity assignment operator overload is illegal
There are several other places in the spec that could be better written.
Comment #3 by bugzilla — 2012-04-28T02:13:22Z
Doc bugs aren't critical.
Comment #4 by andrej.mitrovich — 2014-04-23T11:52:57Z