[Issue 11588] New: Inconsistent abilities to compare `const`/`immutable` classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 23 23:50:12 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11588

           Summary: Inconsistent abilities to compare `const`/`immutable`
                    classes
           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 11:50:11 MSK ---
Currently because of Issue 1824 `opEquals` and `opCmp` aren't `const`.

dmd rejects `opCmp` calls but accepts `opEquals` ones:
---
class C
{
    int i;
    override bool opEquals(Object o) { ++i; return true;}
    override int opCmp(Object c) { ++i; return 0; }
}

void main()
{
    const c1 = new C, c2 = new C;
    assert(c1 == c2); // ok, calls `opEquals`
    assert(c1 <= c2); // Error: mutable method main.C.opCmp is not callable
using a const object
}
---

Both should be either accepted or rejected. See Issue 11557 for proposal to
allow `opCmp` calls too.

-- 
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