D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10588 - Typeinfo.compare uses bitwise comparison for structs
Summary: Typeinfo.compare uses bitwise comparison for structs
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2013-07-09 13:48 UTC by hsteoh
Modified: 2024-12-13 18:09 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description hsteoh 2013-07-09 13:48:31 UTC
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 hsteoh 2014-12-05 22:53:49 UTC
Still happens on git HEAD as of today. Tested on Linux/64.
Comment 2 hsteoh 2019-12-10 18:52:37 UTC
Still happens as of git master (5a3783db46b1b16b76c3afa493b17130b76b1eda).
Comment 3 dlangBugzillaToGithub 2024-12-13 18:09:04 UTC
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