Bug 10588 – Typeinfo.compare uses bitwise comparison for structs

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-09T13:48:31Z
Last change time
2024-12-13T18:09:04Z
Keywords
wrong-code
Assigned to
No Owner
Creator
hsteoh
Moved to GitHub: dmd#18624 →

Comments

Comment #0 by hsteoh — 2013-07-09T13:48:31Z
CODE: ------snip------ struct S { int[] data; } void main() { auto s = S([1,2,3]); auto t = S([1,2,3]); auto u = S([1,2,4]); assert(s == t); assert(s != u); assert(typeid(s).compare(&s, &t) == 0); // FAILS assert(typeid(s).compare(&s, &u) != 0); } ------snip------ Since S doesn't define opEquals or opCmp, the typeinfo's .compare is just the default provided by DMD. However, it uses bitwise comparison, whereas == uses field-wise comparison.
Comment #1 by hsteoh — 2014-12-05T22:53:49Z
Still happens on git HEAD as of today. Tested on Linux/64.
Comment #2 by hsteoh — 2019-12-10T18:52:37Z
Still happens as of git master (5a3783db46b1b16b76c3afa493b17130b76b1eda).
Comment #3 by robert.schadek — 2024-12-13T18:09:04Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18624 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB