Bug 17244 – Undefined comparison of struct arrays is allowed

Status
NEW
Severity
normal
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-03-06T23:24:13Z
Last change time
2024-12-07T13:37:18Z
Keywords
accepts-invalid
Assigned to
Lucia Cojocaru
Creator
Vladimir Panteleev
Moved to GitHub: dmd#17344 →

Comments

Comment #0 by dlang-bugzilla — 2017-03-06T23:24:13Z
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
Comment #1 by andrei — 2017-03-06T23:42:26Z
Same problem for alias A = cfloat;
Comment #2 by qs.il.paperinik — 2020-12-02T02:13:10Z
Probably part of the same problem: float[1] xs = [ float.nan ]; assert(!(xs[0] <= xs[0] || xs[0] >= xs[0])); assert(xs != xs); assert(xs <= xs && xs >= xs); Especially the last two lines are very odd. No type should have that behavior.
Comment #3 by robert.schadek — 2024-12-07T13:37:18Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17344 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB