Bug 3916 – opEquals for objects does not respect const

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-03-09T11:54:00Z
Last change time
2014-02-15T02:44:18Z
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2010-03-09T11:54:35Z
Example: class C { int x; bool opEquals(Object d) {++x; return false;} } void main() { const c1= new C; const c2= new C; assert(c1 != c2); assert(c1.x == 1); } This should fail to compile. I'm unsure what the correct signature for opEquals should be, but I'd expect it to be something like: bool opEquals(const Object other) const; With the global function being changed to: bool opEquals(const Object lhs, const Object rhs); This may limit the ability to run cached calculations in the objects themselves during comparisons, but I think this situation could be worked around with casts.
Comment #1 by k.hara.pg — 2011-04-12T03:13:52Z
*** This issue has been marked as a duplicate of issue 1824 ***