On Tue, Nov 14, 2017 at 06:53:43PM -0500, Steven Schveighoffer via 
Digitalmars-d wrote:
> On 11/14/17 6:09 PM, H. S. Teoh wrote:
> > On Tue, Nov 14, 2017 at 11:05:51PM +0000, Michael V. Franklin via 
> > Digitalmars-d wrote:
> > > On Tuesday, 14 November 2017 at 13:54:03 UTC, Steven Schveighoffer wrote:
> > > 
> > > > IMO, no character types should implicitly convert from integer
> > > > types. In fact, character types shouldn't convert from ANYTHING
> > > > (even other character types). We have so many problems with
> > > > this.
> > > 
> > > Is everyone in general agreement on this?  Can anyone think of a
> > > compelling use case?
> > [...]
> > 
> > I am 100% for this change.  I've been bitten before by things like
> > this:
> > 
> >     void myfunc(char ch) { ... }
> >     void myfunc(int i) { ... }
> > 
> >     char c;
> >     int i;
> > 
> >     myfunc(c);      // calls first overload
> >     myfunc('a');    // calls second overload (WAT)
> >     myfunc(i);      // calls second overload
> >     myfunc(1);      // calls second overload
> 
> I couldn't believe that this is the case so I tested it:
> 
> https://run.dlang.io/is/AHQYtA
> 
> for those who don't want to look, it does indeed call the first overload for
> a character literal, so this is not a problem (maybe you were thinking of
> something else?)
[...]

Argh, should've checked before I posted.  What I meant was more
something like this:

        import std.stdio;
        void f(dchar) { writeln("dchar overload"); }
        void f(ubyte) { writeln("ubyte overload"); }
        void main() {
                f(1);
                f('a');
        }

Output:
        ubyte overload
        ubyte overload

It "makes sense" from the POV of C/C++-compatible integer promotion
rules, but in the context of D, it's just very WAT-worthy.


T

-- 
Debugging is twice as hard as writing the code in the first place. Therefore, 
if you write the code as cleverly as possible, you are, by definition, not 
smart enough to debug it. -- Brian W. Kernighan

Reply via email to