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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Nov 24 09:25:09 PST 2013


On 11/24/13 6:32 AM, ilya-stromberg wrote:
> On Sunday, 24 November 2013 at 14:16:39 UTC, bearophile wrote:
>> Maxim Fomin:
>>
>>> This is neither bug not a terribale feature.
>>
>> I think the implicit question of ilya-stromberg was: how much
>> bug-prone is this language feature?
>
> Yes, exactly. I personally was VERY surprised. My code example from real
> life:
>
> class Foo
> {
> }
>
> class Bar
> {
>      Foo f;
>
>      void bar()
>      {
>          //variable was wrongly commented here
>          //bool f = true;
>
>          if(f)
>          {
>              //Oops!
>          }
>      }
> }

If uncommented that would make for a shadow definition error. In brief I 
think you'll have a hard time finding evidence that "if (p)" is dangerous.


Andrei



More information about the Digitalmars-d mailing list