[Issue 17244] New: Undefined comparison of struct arrays is allowed

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Mar 6 15:24:13 PST 2017


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

          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 at puremagic.com
          Reporter: thecybershadow at 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

--


More information about the Digitalmars-d-bugs mailing list