1 matches bool, 2 matches long

Ali Çehreli acehreli at yahoo.com
Thu Apr 25 19:13:02 PDT 2013


On 04/25/2013 06:44 PM, Maxim Fomin wrote:

 > On Thursday, 25 April 2013 at 21:05:43 UTC, Ali Çehreli wrote:

 > Looks like value range propagation bug because 1 is integer literal and
 > should be converted to long. There is no way for 1 to be converted to
 > bool here

That special conversion rule of literal 0 and literal 1 being implicitly 
convertible to false and true gets in the way.

 > (from TDPL long is below int and it is the shortest way, value
 > range propagation can work upwards, but the path would be longer).

Interesting.

I agree with bearophile, this is too surprising:

   foo(1);  // goes to bool

Decide to change the value:

   foo(2);  // now goes to long

Introduce a variable:

   int i = 1;
   foo(i);  // again, goes to long

I feel defeated. :)

Ali



More information about the Digitalmars-d mailing list