[Issue 7864] Structs with class members can't be sorted

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 8 19:17:06 PDT 2012


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


Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2012-04-08 19:17:46 PDT ---
(In reply to comment #0)
> This compiles with 2.058, but not with the latest head (which I assume is the
> same as 2.059 beta)
> 
[snip]
> 
> /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(6802): Error:
> static assert  "Invalid predicate passed to sort: a < b"
> q.d(52):        instantiated from here: sort!("a < b",cast(SwapStrategy)0,S[])

This is wrong opCmp overload problem, not compiler regression.
If you change opCmp signatures to:

    int opCmp(const S rhs) const
    int opCmp(const ref S rhs) const
    // may work in general
or:
    int opCmp(const S rhs) const
    // may work in general if S allows lvalue copying
or:
    int opCmp(S rhs) const
    // In this case, sorted elements is always mutable so it works
or:
    int opCmp(const ref S rhs) const
    // In this case, current std.algorithm.sort implementation only requires
    // lvalue comparison, so it works)

Then you can compile it.

> The same occurs if you use a SysTime instead of C, so the problem occurs
> whether the class is directly or indirectly insed of S. This strikes me as
> being similar to issue# 7808 (though not identical). That was fixed however,
> and this isn't.

Bug 7808 was alias this type resolution problem. There is no matter.

-- 
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