www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10588] New: Typeinfo.compare uses bitwise comparison for structs

http://d.puremagic.com/issues/show_bug.cgi?id=10588

           Summary: Typeinfo.compare uses bitwise comparison for structs
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx


--- Comment #0 from hsteoh quickfur.ath.cx 2013-07-09 13:48:31 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 09 2013