DIP 1015--removal of implicit conversion from integer and character literals to bool--Community Review Round 1

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 21 21:23:12 UTC 2018


On 6/21/18 3:29 PM, Jonathan M Davis wrote:
> On Thursday, June 21, 2018 18:56:39 Francesco Mecca via Digitalmars-d wrote:
>> On Thursday, 21 June 2018 at 17:11:07 UTC, Steven Schveighoffer
>>
>> wrote:
>>> On 6/20/18 4:16 AM, Mike Parker wrote:
>>>> [...]
>>>
>>> I agree with everything, but one thing that is not specified
>>> here is when integers are used as conditionals.
>>>
>>> In other words, this still has to compile:
>>>
>>> if(1) ...
>>>
>>> enum a = 1;
>>>
>>> if(a) ...
>>>
>>> I can see this somehow getting caught up in the "implicit
>>> conversion to bool", so there should be a section to address
>>> this.
>>>
>>
>> I agree and after reading the DIP I am still confused if we are
>> allowed to write while(1) (and similar conditionals) anymore.
> 
> while(1)
> 
> is not technically an implicit conversion. It's an implicit, explicit
> conversion, which sounds kind of dumb, but it is technically what happens,
> since when you write a conditional, the compiler inserts an explicit cast.

I'm not so sure this is the case for integer literals (literally, I'm 
not sure). It's certainly the case for custom types. The compiler 
handles things with builtin types specially. See for instance foreach on 
ranges vs. arrays.

It might be that this actually is an implicit conversion (it's a literal 
after all). In that case, what I DON'T want to see after this proposal 
is accepted is an explanation like "well, why wouldn't you just use 
while(true)? It's the same thing".

It's why I think the document needs clarification.

-Steve


More information about the Digitalmars-d mailing list