[Issue 9999] Integer literal 0 and 1 should prefer integer type in overload resolution

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 12 02:48:38 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=9999

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #17 from Walter Bright <bugzilla at digitalmars.com> ---
These behaviors in D make sense if one considers a 'bool' to be an integer type
that is one bit in size. There are no special conversion rules in D for bool,
it behaves just like short, int, long, etc.

For example:

In the initialization `integral_type x = ct;`, whenever
`integral_type` is wide enough to fit constant `ct`, the constant can
be used for initialization even though its ostensible type is not the
same as `integral_type`.

This is a nice successful rule in D, without which we'd need to write
nonsense like:

ubyte x = cast(ubyte) 100;

As for overloading, D chooses the tightest conversion when choosing an
overload. This is somewhat surprising, but consistent across bool,
ubyte, and all other integral types. Again, there is no special rule for bool.

Marking as invalid.

--


More information about the Digitalmars-d-bugs mailing list