www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - dmd crash: struct sorting

reply "Carlos Santander B." <carlos8294 msn.com> writes:
The following will crash dmd:

///////
struct S { }

void main ()
{
    S [] s;
    s.sort;
}
///////


-----------------------
Carlos Santander Bernal
Jun 30 2004
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
oops.  i think i hit "email" instead of "reply".  oh well, i'll post it here
for public reference as well.

adding an opCmp() declaration to the struct seems to fix it.

struct A
{
 int opCmp(A other)
 {
  return 0;
 }
}

int main()
{
 A[] array;
 array.sort;
 return 0;
}

probably what's happening is that structs do not have a default opCmp as
classes do.  though it would be nice if the compiler flagged an error saying
that you need to define an opCmp to sort a struct array.  :)

"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:cbvntq$20uu$2 digitaldaemon.com...
 The following will crash dmd:

 ///////
 struct S { }

 void main ()
 {
     S [] s;
     s.sort;
 }
 ///////


 -----------------------
 Carlos Santander Bernal
Jul 05 2004