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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 8 17:14:31 PDT 2012


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

           Summary: Structs with class members can't be sorted
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-04-08 17:15:12 PDT ---
This compiles with 2.058, but not with the latest head (which I assume is the
same as 2.059 beta)

import std.algorithm;
import std.string;

class C
{
    string str;

    this(string str)
    {
        this.str = str;
    }

    override int opCmp(Object o) const
    {
        auto rhs = cast(C)o;
        assert(rhs);
        return cmp(str, rhs.str);
    }
}

struct S
{
    C c;

    this(C c)
    {
        this.c = c;
    }

    int opCmp(S rhs) const
    {
        if(c < rhs.c)
            return -1;
        if(c > rhs.c)
            return 1;
        return 0;
    }

    int opCmp(const ref S rhs) const
    {
        if(c < rhs.c)
            return -1;
        if(c > rhs.c)
            return 1;
        return 0;
    }
}

void main()
{
    S[] stuff;
    sort(stuff);
}


/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[])



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.

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