D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11588 - Inconsistent abilities to compare `const`/`immutable` classes
Summary: Inconsistent abilities to compare `const`/`immutable` classes
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-23 23:50 UTC by Denis Shelomovskii
Modified: 2024-12-13 18:14 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2013-11-23 23:50:11 UTC
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.
Comment 1 dlangBugzillaToGithub 2024-12-13 18:14:10 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18716

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB