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
Comment #2 by schveiguy — 2011-12-07T07:46:59Z
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
The class overload page seems to be improved now, but the table on the structs pages lists "assign overload" rather than the better-describing "identity assign overload". https://github.com/D-Programming-Language/dlang.org/pull/562
Comment #5 by github-bugzilla — 2014-04-23T12:06:06Z
Commits pushed to master at https://github.com/D-Programming-Language/dlang.org https://github.com/D-Programming-Language/dlang.org/commit/fee0b277069a2c0bcf5fc0b3f3370197e13a6163 Fix Issue 7075 - Use better wording for identity assignment overload. https://github.com/D-Programming-Language/dlang.org/commit/beece10c7eedd0e0f7416b104cc6ab8889e60792 Merge pull request #562 from AndrejMitrovic/Fix7075 [Trivial] Issue 7075 - Use better wording for identity assignment overload.