www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11588] New: Inconsistent abilities to compare `const`/`immutable` classes

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 puremagic.com
        ReportedBy: verylonglogin.reg gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg 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: -------
Nov 23 2013