operator "~" does not check type?

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 12 00:57:17 PDT 2011


On Wednesday, October 12, 2011 03:53:22 bearophile wrote:
> Jonathan M Davis:
> > int and dchar implicitly convert to one another for better or for worse.
> > Personally, I'd prefer that they didn't, but that's the way that it is,
> > so I don't believe that this is technically a bug.
> 
> char->int is OK, but int->char is not so OK. This programs (that compiles
> with no errors) seems to show a possible source of bugs, so I call this a
> design bug, worth fixing:
> 
> 
> void main(string[] args) {
>     int x = args.length;
>     string s = "hello";
>     s ~= x;
> }

I believe that the primary reasoning for allowing the implicit conversion 
between int and dchar is so that code like this

dchar c = 'a' + 7;

doesn't require a cast. So, the primary target is converting to int to dchar. 
Regardless, when it's come up before, Walter has been very much against 
changing it.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list