[Issue 1517] New: .sort for structs behaves badly with ref opCmp

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 19 00:44:17 PDT 2007


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

           Summary: .sort for structs behaves badly with ref opCmp
           Product: D
           Version: 1.021
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: wbaxter at gmail.com


This is incorrect code according to the spec but it doesn't really make sense
to me why it doesn't work.  

So the spec says:
"""
For the .sort property to work on arrays of structs or unions, the struct or
union definition must define the function: int opCmp(S) or int opCmp(S*). The
type S is the type of the struct or union. This function will determine the
sort ordering.
"""
But I just happened to use opCmp(ref S) and it seemed to work (everything
compiled fine and ran without crashing, anyway). 

But it doesn't actually work.  Sorting sorts improperly.

I think making a ref opCmp in a struct should either be made to work (i see no
reason why it should not work), or it should be made a compiler error to try to
create one.

Attached is a simple test.


-- 



More information about the Digitalmars-d-bugs mailing list