D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8522 - Comparison operator overloading doesn't consider the qualifier of lhs
Summary: Comparison operator overloading doesn't consider the qualifier of lhs
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks: 8284
  Show dependency treegraph
 
Reported: 2012-08-08 08:17 UTC by Kenji Hara
Modified: 2012-11-14 21:29 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 Kenji Hara 2012-08-08 08:17:28 UTC
Postfix const works, but prefix version doesn't work

struct Tuple(Specs...)
{
    Specs field;

    bool opEquals(R)(R rhs) { return true; }

//  bool opEquals(R)(R rhs) const { return true; }  // OK
    const bool opEquals(R)(R rhs) { return true; }  // NG
}

void main()
{
    Tuple!(size_t, size_t) t;
    assert(t == t);    // line 14
}

output:
test.d(14): Error: template test.Tuple!(uint,uint).Tuple.opEquals matches more than one template declaration, test.d(5):opEquals(R) and test.d(8):opEquals(R)
Comment 1 Kenji Hara 2012-08-08 08:51:16 UTC
More explainable test case.

struct Point
{
    bool opEquals(R)(R rhs) { return true; }
    bool opEquals(R)(R rhs) const { return true; }
}

void main()
{
    Point mp;
    const Point cp;
    assert(mp == mp);
    assert(mp == cp);
    assert(cp == mp);   // doesn't work
    assert(cp == cp);   // doesn't work
}

If the left hand side of '==' is const value, const opEquals never matches.
Comment 2 Kenji Hara 2012-08-08 08:58:02 UTC
https://github.com/D-Programming-Language/dmd/pull/1075

And changed the title.
Comment 3 github-bugzilla 2012-08-23 08:25:59 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/f6af3ce56851c2b120a87cabc79b4c3427f04606
fix Issue 8522 - Comparison operator overloading doesn't consider the qualifier of lhs

https://github.com/D-Programming-Language/dmd/commit/7cc1b80964cb8c45e4136a71860f05853d89931d
Merge pull request #1075 from 9rnsr/fix8522

Issue 8522 - Comparison operator overloading doesn't consider the qualifier of lhs