DIP 1015--Deprecation of Implicit Conversion of Int. & Char. Literals to bool--Formal Assement
Chris M.
chrismohrfeld at comcast.net
Tue Nov 13 16:26:55 UTC 2018
On Monday, 12 November 2018 at 09:45:14 UTC, Mike Parker wrote:
> 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.
I was going to write something up about how you can't do
arithmetic on bool types therefore they aren't integral, but I
tested and realized D allows this (i.e. bool + bool, bool *
bool). Still that seems nonsensical, so I guess my question what
is the definition of an integral type and how does bool fit?
More information about the Digitalmars-d-announce
mailing list