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