[Issue 7833] Regression(2.059 Beta): struct opEquals broken

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 5 18:22:12 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7833


Jonathan M Davis <jmdavisProg at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg at gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-04-05 18:22:49 PDT ---
Actually, I don't believe that this is a bug. With this release, Foo() has been
fixed so that it's not an lvalue. Previously Foo() would have been considered
an lvalue but a Foo returned from a function would not making it so that

assert(foo == Foo());

worked by

assert(foo == getFoo());

did not. Many of us considered it incredibly inconsistent to treat struct
literals as lvalues. They're temporaries and don't represent variables or
places in memory at all. So, they shouldn't be lvalues. And not they're not, so
your opEquals doesn't work.

Given that auto ref currently only works with templates, I believe that the
correct solution for this is to then declare 2 overloads of opEquals.

struct Foo
{
    bool opEquals(ref const Foo b) const
    {
        return true;
    }

    bool opEquals(Foo b) const
    {
        return true;
    }
}

One will work with lvalues and avoid copying them, whereas the other will work
with rvalues. I believe that when Kenji fixed it so that struct literals aren't
lvalues, he also went into Phobos and fixed it so that all structs which define
opEquals define both overloads of opEquals. You'll need to do the same.

So yes, this change breaks code, but as I understand it, it's a bug fix, not a
regression.

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


More information about the Digitalmars-d-bugs mailing list