www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24182] New: DMD crashes when compile time sort is called with

https://issues.dlang.org/show_bug.cgi?id=24182

          Issue ID: 24182
           Summary: DMD crashes when compile time sort is called with
                    templatized opCmp()
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: puneet coverify.org

$ dmd -c foo.d
invalid op 32 94
Illegal instruction (core dumped)

The error goes away if I comment out either of F0, F1..5
The error also goes away if I use a non-templatized version of opCmp -- as in
int opCmp(bar other)

// foo.d
enum foo {
  // No error if one of these is commented out
  F0   = bar(0),  
  F1   = bar(1),  
  F2   = bar(2),  
  F3   = bar(3),  
  F4   = bar(4),  
  F5   = bar(5)
}
struct bar {
  int _val;
  this(int val) { _val = val; }
  int opCmp(U)(U other) {
    if (_val == other._val) return 0;
    if (_val > other._val) return 1;
    else return -1;
  }
}
struct frop(T) {
  enum _elems = getSortedMembers!T;
  static T[] getSortedMembers(T)() {
    import std;
    return array([EnumMembers!T].sort());
  }
}
alias fropfoo = frop!foo;

--
Oct 09 2023