DIP 1015--Deprecation of Implicit Conversion of Int. & Char. Literals to bool--Formal Assement

Mike Parker aldacron at gmail.com
Mon Nov 12 09:45:14 UTC 2018


DIP 1015, "Deprecation and removal of implicit conversion from 
integer and character literals to bool, has been rejected, 
primarily on the grounds that it is factually incorrect in 
treating bool as a type distinct from other integral types.

The TL;DR is that the DIP is trying to change behavior that is 
working as intended.

 From Example A in the DIP:

     bool b = 1;

This works because bool is a "small integral" with a range of 
0..1. The current behavior is consistent with all other integrals.

 From Example B in the DIP:

```
int f(bool b) { return 1; }
int f(int i) { return 2; }

enum E : int
{
     a = 0,
     b = 1,
     c = 2,
}
```

Here, f(a) and f(b) call the bool overload, while f(c) calls the 
int version. This works because D selects the overload with the 
tightest conversion. This behavior is consistent across all 
integral types. Replace bool with ubyte and f(a), f(b) would both 
call the ubyte version. The same holds for the DIP's Example C.

Walter and Andrei left the door open to change the overload 
behavior for *all* integral types, with the caveat that it's a 
huge hurdle for such a DIP to be accepted. It would need a 
compelling argument.

You can read a few more details in the summary I appended to the 
DIP:

https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1015.md#formal-assessment

Thanks to Mike Franklin for sticking with the process to the end.






More information about the Digitalmars-d-announce mailing list