Annoyance with new integer promotion deprecations

Meta jared771 at gmail.com
Tue Feb 6 01:07:21 UTC 2018


On Tuesday, 6 February 2018 at 00:18:08 UTC, Jonathan M Davis 
wrote:
> On Monday, February 05, 2018 15:27:45 H. S. Teoh via 
> Digitalmars-d wrote:
>> On Mon, Feb 05, 2018 at 01:56:33PM -0800, Walter Bright via 
>> Digitalmars-d
> wrote:
>> > The idea is a byte can be implicitly converted to a dchar, 
>> > [...]
>>
>> This is the root of the problem.  Character types should never 
>> have been implicitly convertible to/from arithmetic integral 
>> types in the first place.
>
> +1
>
> Occasionally, it's useful, but in most cases, it just causes 
> bugs - especially when you consider stuff like appending to a 
> string.
>
> - Jonathan M Davis

I remember a fairly old defect, or maybe it was just a post in 
the Learn forum. Doing "string" ~ 0 would append '\0' to a 
string, because the int was auto-converted to a char. This still 
works today:

import std.stdio;
void main()
{
     string msg = "Hello" ~ 0 ~ " D" ~ '\0';
     writeln(msg);
     writeln(cast(ubyte[])msg);
     writeln(cast(ubyte[])"Hello D");
}


More information about the Digitalmars-d mailing list