October 14, 2011 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 --- Comment #10 from Kenji Hara <k.hara.pg@gmail.com> 2011-10-13 23:26:11 PDT --- From bug 6812: (In reply to comment #6) > List of things that do not work: > > floating-point members > array members (including strings) + member classes that have overloaded opEquals > List of things that do work: > > any member that uses bitwise comparison > member structs that have overloaded opEquals -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 14, 2011 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Platform|Other |All Depends on| |1824 --- Comment #11 from Kenji Hara <k.hara.pg@gmail.com> 2011-10-14 02:46:10 PDT --- Test case. void main() { static struct Float { double x; } Float f; assert(f.x != f.x); // NaN != NaN assert(f != f); // Fails, should pass static struct Array { int[] x; } Array a1 = Array([1,2,3].dup); Array a2 = Array([1,2,3].dup); assert(a1.x !is a2.x); assert(a1.x == a2.x); assert(a1 == a2); // Fails, should pass static struct Class { Object x; } static class X { bool opEquals(Object o){ return true; } } Class c1a = Class(new Object()); Class c2a = Class(new Object()); assert(c1a.x !is c2a.x); assert(c1a.x != c2a.x); assert(c1a != c2a); // Pass, Object.opEquals works like bitwise compare Class c1b = Class(new X()); Class c2b = Class(new X()); assert(c1b.x !is c2b.x); assert(c1b.x == c2b.x); assert(c1b == c2b); // Fails, should pass } To fix the comparison behavior of a struct that has classes as members, we need to fix the bug 1824 first. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 15, 2011 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch --- Comment #12 from Kenji Hara <k.hara.pg@gmail.com> 2011-10-15 02:36:12 PDT --- https://github.com/D-Programming-Language/dmd/pull/387 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 10, 2011 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 --- Comment #13 from Trass3r <mrmocool@gmx.de> 2011-12-10 10:01:55 PST --- *** Issue 7089 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 22, 2012 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 --- Comment #14 from Kenji Hara <k.hara.pg@gmail.com> 2012-01-22 05:39:37 PST --- *** Issue 7342 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 26, 2012 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 --- Comment #15 from bearophile_hugs@eml.cc 2012-03-26 04:30:41 PDT --- This is an answer to Walter to Bug 7783 : (In reply to comment #2) > In the absense of a user-defined opEquals for the struct, equality is defined as a bitwise compare. This is working as expected. Not a bug. I agree, it's not a DMD implementation bug because here it's working as designed. But I have voted bug 3789 time ago because I consider this in top 15 of the design decisions to fix/change, because this is a large source of bugs, it's unnatural. D is designed to be safe on default. Not comparing the strings as strings in the following code breaks the Principle of least astonishment: struct Foo { string name; bool b; } void main() { auto a = Foo("foobar".idup, true); auto b = Foo("foobar".idup, true); assert(a == b); } For me the only acceptable alternative to fixing Bug 3789 is statically disallowing the equal operator (==) in such cases. D language has the "is" for the situations where you want to perform bitwise comparison of structs too. This is OK. For the other situations where I use "==" among struts, I want it do the right thing, like comparing its contained strings correctly instead of arbitrarily choosing bitwise comparison of the sub-struct that represents the string. Making "==" work as "is" for structs means using an operator for the purpose of the other operator, and it has caused some bugs in my code. And it will cause bugs in future D code. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 26, 2012 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 --- Comment #16 from Steven Schveighoffer <schveiguy@yahoo.com> 2012-03-26 04:46:26 PDT --- (In reply to comment #15) > This is an answer to Walter to Bug 7783 : > > (In reply to comment #2) > > In the absense of a user-defined opEquals for the struct, equality is defined as a bitwise compare. This is working as expected. Not a bug. > > I agree, it's not a DMD implementation bug because here it's working as designed. The statement above is not completely true: struct S { string x; bool opEquals(const ref S other) const { return x == x; } } struct T { S s; // no user-defined opEquals } void main() { T t1, t2; t1.s.x = "foobar".idup; t2.s.x = "foobar".idup; assert(t1 == t2); } This passes in 2.058. Essentially, bitwise comparison is done unless a member requires special case opEquals, in which case a generated opEquals function is made for that struct. I contend that for the compiler to defer to user-defined structs, but not to builtin types on how to compare themselves is not only inconsistent, but leads to endless boilerplate code. It does not help anyone. We have 'is', which does a bitwise compare. There is no reason to make == duplicate that functionality. For the rare cases where you actually *need* bitwise comparison on arrays or floats, you can define a special opEquals. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 26, 2012 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 --- Comment #17 from Simen Kjaeraas <simen.kjaras@gmail.com> 2012-03-26 08:07:29 PDT --- To further underline this point: struct S { string x; bool opEquals(const ref S other) const { return x == x; } } struct T { S s; string r; } void main() { T t1, t2; t1.s.x = "foobar".idup; t1.r = "foobaz".idup; t2.s.x = "foobar".idup; t2.r = "foobaz".idup; assert(t1 == t2); } Yes, the string values in r are compared not bitwise, but for content. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 26, 2012 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 --- Comment #18 from bearophile_hugs@eml.cc 2012-03-26 15:42:03 PDT --- See also the thread: http://forum.dlang.org/thread/jkpllu$1hss$1@digitalmars.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 24, 2012 [Issue 3789] Structs members that require non-bitwise comparison not correctly compared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | http://d.puremagic.com/issues/show_bug.cgi?id=3789 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich@gmail.com --- Comment #19 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-24 12:36:15 PDT --- (In reply to comment #18) > For the rare cases where you actually *need* > bitwise comparison on arrays or floats, you can define a special opEquals. Also hashes suffer from this problem as well. They're compared via 'is' instead of '==' in struct fields, just like arrays. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation