D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5783 - Const Tuple equality
Summary: Const Tuple equality
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
: 7586 (view as issue list)
Depends on:
Blocks: 7586
  Show dependency treegraph
 
Reported: 2011-03-24 16:55 UTC by bearophile_hugs
Modified: 2013-02-03 13:08 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-03-24 16:55:26 UTC
Problem found on tuples by Magnus Lie Hetland, then reduced:


import std.typecons;
void main() {
    alias Tuple!int T;
    const T t;
    bool b = t == t;
}


DMD 2.052 shows:

test.d(5): Error: template std.typecons.Tuple!(int).Tuple.opEquals(R) if (isTuple!(R)) does not match any function template declaration
test.d(5): Error: template std.typecons.Tuple!(int).Tuple.opEquals(R) if (isTuple!(R)) cannot deduce template function from argument types !()(const(Tuple!(int)))



I think it can be further reduced to:

struct Foo(T) {
    bool opEquals(R)(R rhs) {
        return false;
    }
}
void main() {
    const Foo!int f;
    bool result = f == f;
}
Comment 1 kennytm 2011-03-24 17:28:55 UTC
opEquals is a non-const method (issue 1824). Of course a const object cannot call it. The reduced test case is working as expected. The problem is just Tuple needs a const opEquals.
Comment 2 bearophile_hugs 2011-03-24 17:31:21 UTC
(In reply to comment #1)
> opEquals is a non-const method (issue 1824). Of course a const object cannot
> call it. The reduced test case is working as expected. The problem is just
> Tuple needs a const opEquals.

Thank you for your answer.

A secondary problem here is that I wasn't unable to understand what the problem was from those error messages. So is it possible to improve them?
Comment 3 bearophile_hugs 2012-02-26 14:52:17 UTC
*** Issue 7586 has been marked as a duplicate of this issue. ***
Comment 4 Andrej Mitrovic 2013-02-03 13:08:22 UTC
Seems to be fixed in 2.061.