http://d.puremagic.com/issues/show_bug.cgi?id=10567
Summary: Typeinfo.compare has unreasonable signature requirements on opCmp Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: hst...@quickfur.ath.cx --- Comment #0 from hst...@quickfur.ath.cx 2013-07-07 21:25:25 PDT --- CODE: ------------snip----------- import std.stdio; struct S { int[] data; int opCmp(const S s) const { return (data < s.data) ? -1 : (data == s.data) ? 0 : 1; } } void main() { auto s = S([1,2,3]); auto t = S([1,2,3]); writeln(s==t); writeln(typeid(s).compare(&s, &t)); // prints 16 } ------------snip----------- Here, we defined opCmp to compare the array wrapped in S, and == correctly calls the custom opCmp to return true. However, typeid(S) fails to call the custom opCmp; it appears to fall back to the default implementation of opCmp, which does a bitwise compare of S. This is a bug, because if the signature of opCmp is changed to: int opCmp(ref const S s) const { ... } then typeid(S) correctly calls the custom opCmp instead. However, requiring ref in the argument is unnecessarily restrictive. If == works correctly without requiring a ref const argument, then why should typeid(S).compare require a ref const argument? This bug is blocking issue #8435 and issue #10118. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------