www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17244] New: Undefined comparison of struct arrays is allowed


          Issue ID: 17244
           Summary: Undefined comparison of struct arrays is allowed
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: thecybershadow gmail.com

Comparison of structs without an opCmp is undefined:

struct A { int i; }
static assert(!__traits(compiles,  A(1)  <  A(2) )); // OK

However, comparing arrays of such structs is allowed:

static assert(!__traits(compiles, [A(1)] < [A(2)])); // Fails

Andrei wrote[1]:

 Oh. Yah, that's problematic too - you can't order lexicographically 
 unless elements are ordered.
[1]: https://github.com/dlang/druntime/pull/1787#discussion_r104548229 --
Mar 06 2017