[Issue 3789] [TDPL] Structs members that require non-bitwise comparison not correctly compared

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 7 07:41:17 PDT 2013


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



--- Comment #32 from Kenji Hara <k.hara.pg at gmail.com> 2013-05-07 07:41:13 PDT ---
(In reply to comment #26)
> The holes must be initialized to zero, by definition, so that a bitwise
> comparison can be done.

I think '==' operation should test structural comparison, not bitwise
comparison.
Only when structural comparison is equal to bitwise one, it can be optimized to
the latter.

By fixing issue 9873, struct objects comparison `s1 == s2` is rewritable to
`s1.tupleof == s2.tupleof` for member-wise structural comparison. Compiler can
apply this expansion recursively.

struct S {
    int num;
    int[] arr;
}
struct T {
    S s;
    int[int] aa;
}
void main() {
    T t1, t2;
    t1 == t2;
    // is rewritable to:
    // t1.tupleof == t2.tupleof
    // t1.tupoelf[0] == t2.tupoelf[0] && t1.tupoelf[1] == t2.tupoelf[1]
    // t1.s == t2.s && t1.aa == t2.aa
    // t1.s.tupleof == t2.s.tupleof && t1.aa == t2.aa
    // t1.s.num == t2.s.num && t1.s.arr == t2.s.arr && t1.aa == t2.aa
}

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


More information about the Digitalmars-d-bugs mailing list