Thread overview
[Issue 5609] New: struct opEquals doesn't conform to language specifications.
May 11, 2011
kennytm@gmail.com
Apr 22, 2012
SomeDude
February 18, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5609

           Summary: struct opEquals doesn't conform to language
                    specifications.
           Product: D
           Version: D2
          Platform: x86_64
               URL: http://www.digitalmars.com/d/2.0/operatoroverloading.h
                    tml#equals
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: eatingstaples@gmail.com


--- Comment #0 from eatingstaples@gmail.com 2011-02-18 04:09:28 PST ---
Created an attachment (id=916)
Code demonstrating the issue.

The language specification states (with respect to opEquals in structs) "...the
expressions a.opEquals(b) and b.opEquals(a) are tried. If both resolve to the
same opEquals function, then the expression is rewritten to be a.opEquals(b).
If one is a better match then the other, or one compiles and the other does
not, the one is selected.
Otherwise, an error results."

Structs, however, don't properly follow the "if one compiles and the other does not" rule, at least not for the form a.opEquals(rvalue). Example attached.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 11, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5609


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dpx.infinity@gmail.com


--- Comment #1 from kennytm@gmail.com 2011-05-11 10:40:22 PDT ---
*** Issue 5979 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5609


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #2 from SomeDude <lovelydear@mailmetrash.com> 2012-04-22 16:23:34 PDT ---
Code in the attachment:

struct A
{
    int x;

    A foo()
    {
        return A(x);
    }

    const bool opEquals(ref const A other)
    {
        return (x == other.x);
    }
}

void main()
{
    auto a = A(5);
    assert(a.foo == a); // OK
    assert(a == a.foo); // Error
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------