Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeinfo.compare uses bitwise comparison for structs #18624

Open
dlangBugzillaToGithub opened this issue Jul 9, 2013 · 2 comments
Open

Typeinfo.compare uses bitwise comparison for structs #18624

dlangBugzillaToGithub opened this issue Jul 9, 2013 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

hsteoh reported this on 2013-07-09T13:48:31Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=10588

Description

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.
@dlangBugzillaToGithub
Copy link
Author

hsteoh commented on 2014-12-05T22:53:49Z

Still happens on git HEAD as of today. Tested on Linux/64.

@dlangBugzillaToGithub
Copy link
Author

hsteoh commented on 2019-12-10T18:52:37Z

Still happens as of git master (5a3783db46b1b16b76c3afa493b17130b76b1eda).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant