Deprecate implicit `int` to `bool` conversion for integer literals

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Nov 12 16:57:05 UTC 2017


On 11/12/2017 08:54 AM, Michael V. Franklin wrote:
> On Sunday, 12 November 2017 at 13:49:51 UTC, Michael V. Franklin wrote:
> 
>> I don't think the proposal to deprecate integer literal conversions to 
>> `bool` would affect that as there doesn't appear to be an integer 
>> literal in the code.
> 
> Nevermind. I see what you mean now.
> 
> Mike

A DIP could be formulated to only address the problem at hand. BTW, 
here's a really fun example:

void fun(long) { assert(0); }
void fun(bool) {}

enum int a = 2;
enum int b = 1;

void main()
{
     fun(a - b);
}

The overload being called depends on (a) whether a - b can be computed 
during compilation or not, and (b) the actual value of a - b. Clearly a 
big problem for modular code. This is the smoking gun motivating the DIP.


Andrei


More information about the Digitalmars-d mailing list