Bug 8522 – Comparison operator overloading doesn't consider the qualifier of lhs

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-08T08:17:00Z
Last change time
2012-11-14T21:29:17Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Blocks
8284

Comments

Comment #0 by k.hara.pg — 2012-08-08T08:17:28Z
Postfix const works, but prefix version doesn't work struct Tuple(Specs...) { Specs field; bool opEquals(R)(R rhs) { return true; } // bool opEquals(R)(R rhs) const { return true; } // OK const bool opEquals(R)(R rhs) { return true; } // NG } void main() { Tuple!(size_t, size_t) t; assert(t == t); // line 14 } output: test.d(14): Error: template test.Tuple!(uint,uint).Tuple.opEquals matches more than one template declaration, test.d(5):opEquals(R) and test.d(8):opEquals(R)
Comment #1 by k.hara.pg — 2012-08-08T08:51:16Z
More explainable test case. struct Point { bool opEquals(R)(R rhs) { return true; } bool opEquals(R)(R rhs) const { return true; } } void main() { Point mp; const Point cp; assert(mp == mp); assert(mp == cp); assert(cp == mp); // doesn't work assert(cp == cp); // doesn't work } If the left hand side of '==' is const value, const opEquals never matches.
Comment #2 by k.hara.pg — 2012-08-08T08:58:02Z
Comment #3 by github-bugzilla — 2012-08-23T08:25:59Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f6af3ce56851c2b120a87cabc79b4c3427f04606 fix Issue 8522 - Comparison operator overloading doesn't consider the qualifier of lhs https://github.com/D-Programming-Language/dmd/commit/7cc1b80964cb8c45e4136a71860f05853d89931d Merge pull request #1075 from 9rnsr/fix8522 Issue 8522 - Comparison operator overloading doesn't consider the qualifier of lhs