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)
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.
https://github.com/D-Programming-Language/dmd/pull/1075 And changed the title.
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