[Issue 11592] New: Inconsistent comparisons of classes between `opCmp` and `opEquals` calls
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Nov 24 01:21:32 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11592
Summary: Inconsistent comparisons of classes between `opCmp`
and `opEquals` calls
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: verylonglogin.reg at gmail.com
--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2013-11-24 13:21:29 MSK ---
Currently `opCmp` is called from current class but `opEquals` is called from
class instance upcasted to `Object`:
---
class C
{
int opCmp(in C) const { return 0; }
bool opEquals(in C) const { return 0; }
}
void main()
{
C c1 = new C, c2 = new C;
assert(c1 <= c2); // ok, calls `C.opCmp`
assert(c1 == c2); // fails, calls `object.opEquals`
}
---
This is because `==` and `!=` are rewritten as call to `object.opEquals` which
calls `Object.opEquals`.
As we are going to remove such functions from `Object` a solution is to make
`object.opEquals` templated by current class types.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list