D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9670 - Shared class object comparison is not yet well defined
Summary: Shared class object comparison is not yet well defined
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2013-03-09 00:09 UTC by Kenji Hara
Modified: 2022-09-08 14:24 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2013-03-09 00:09:20 UTC
With this class definition,

class C
{
    static int count;
    override bool opEquals(Object rhs)
    {
        ++count;
        return true;
    }
}

Mutable object comparison calls C.opEquals once. This is expected.

    C.count = 0;
    auto mc1 = new C;
    auto mc2 = new C;
    assert(mc1 == mc2);
    assert(C.count == 1);

But, in shared object comparison,

    C.count = 0;
    auto sc1 = new shared C;
    auto sc2 = new shared C;
    assert(sc1 == sc2);  // compiles... why?
    assert(C.count == 1);

Mutable opEquals is still called. This is bad hehavior.

Moreover, there is another inconsistency.

    auto so1 = new shared Object;
    auto so2 = new shared Object;
    assert(so1 == so2); // fail to compile

If you directly compare shared Object class, it fails to compile correctly.
Comment 1 RazvanN 2022-09-08 14:24:48 UTC
The shared version of equality comparison does not work today. Closing as fixed.