Yet another slap on the hand by implicit bool to int conversions

Steven Schveighoffer schveiguy at yahoo.com
Mon Jun 20 05:47:02 PDT 2011


On Sun, 19 Jun 2011 19:42:22 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Timon Gehr:
>
>> Maybe DMD could warn on nonsense of the form x != x.
>
> Right. This thread is very good food for this enhancement request of  
> mine:
> http://d.puremagic.com/issues/show_bug.cgi?id=5540
>
> Vote for this enhancement :-)

I don't think this is a good idea.  Generic code could result in an error  
where there shouldn't be.  For example:

int foo(T)()
{
    if(T.sizeof == char.sizeof)
      ...
}

Would this fail to compile where T == char?  What about if T == ubyte?

Generic programming sometimes results in silly code that is perfectly  
acceptable as generic code, and we need to take this into account before  
making decisions assuming a person is writing the code.

-Steve


More information about the Digitalmars-d mailing list