http://d.puremagic.com/issues/show_bug.cgi?id=11161
Kenji Hara <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|wrong-code |spec Component|DMD |websites Summary|If `opEquals` is not |Document the default struct |defined, compiler should |equality comparison and |translate struct objects |operator overloading |equality to member-wise | |equality even if there is | |`alias this` | --- Comment #2 from Kenji Hara <[email protected]> 2013-10-03 02:45:37 PDT --- (In reply to comment #0) > --- > struct S { > bool opEquals(ref const S) { return false; } > } > struct T { > S s; > int value; > alias value this; > } > > void main() { > T t1, t2; > assert(t1.tupleof != t2.tupleof); > assert(t1 != t2); // fails > } > --- > > If this behavior is expected, please write the reasons shortly and change it > to > documentation issue unless this feature is documented. For the expression `t1 != t2`, the semantic analysis is done in the following order: 1. Find opEquals method from the type of operands 2. If 'alias this' declaration exists, compiler tries to resolve equality operation via alias this. -> `t1.value != t2.value` is tested, and succeeds to compile. 3. If any opEquals and comparable 'alias this' is not found, the struct equality comparison is rewritten to their each field comparison. The point is, #1 and #2 are the part of "operator overloading" feature, and it is precedence than the default struct equality operation (== field-wise comparison). Historically Historically: - By bug 3789, the default comparison behavior was changed from bitwise to member-wise. - By bug 10037, the operator overload resolution precedence order was fixed (default member-wise comparison does not hide explicitly defined alias this). Therefore, current behavior is expected. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
