DMD can implicitly convert class pointer to the bool. Is it bug or terrible feature?

Steven Schveighoffer schveiguy at yahoo.com
Thu Jan 16 14:03:14 PST 2014


On Sun, 24 Nov 2013 16:38:19 -0500, Ary Borenszweig <ary at esperanto.org.ar>
wrote:

> On 11/24/13 11:18 AM, ilya-stromberg wrote:
>> DMD output:
>>
>> Error: use 'is' instead of '==' when comparing with null
>> Error: use '!is' instead of '!=' when comparing with null
>
> Ugh, if the compiler disallows comparison of reference with "==" and  
> "!=" and tells you to use "is" and "!is", can't compiler just allow you  
> to write "==" and understand it as "is"? What's the big deal?

The reason for this was a long fought battle with Walter. f == null would
crash if f actually WAS null (compiler did blind rewrite to
f.opEquals(null), which is a virtual call). This was the solution we could
get Walter to implement, and that was a pretty big accomplishment after
his opposition :) The rewrite could be done too, but this implementation
is actually how Walter was convinced -- it flagged several cases in Phobos
where he had done that and didn't realize it.

However, x == y has since been changed to forward to object.opEquals(x,
y), which can handle null parameters in either position, so this "error"
is actually unneeded, and could be removed (I'd recommend removing it).

-Steve


More information about the Digitalmars-d mailing list