[Issue 13468] std.algorithm.canFind(null) fails with class
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Oct 2 10:24:24 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13468
hsteoh at quickfur.ath.cx changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Component|Phobos |DMD
--- Comment #5 from hsteoh at quickfur.ath.cx ---
Apparently I made a total fool of myself. The *real* reason for the bug is not
a.opEquals(b), but is caused by using == to compare a class reference to an
instance of typeof(null).
Specifically, this code works:
----------
class C { }
bool fun(C e, C needle)
{
return (e == needle);
}
void main()
{
fun(null, null);
}
----------
But this code segfaults:
----------
class C { }
bool fun(C e, typeof(null) needle)
{
return (e == needle);
}
void main()
{
fun(null, null);
}
----------
The only difference is that the segfaulting case takes `typeof(null)` as
parameter. Comparing class references with null is actually OK; what's *not* OK
is comparing them with an instance of typeof(null). I think this is a compiler
bug.
--
More information about the Digitalmars-d-bugs
mailing list