A bug with matching overloaded functions?

Steven Schveighoffer schveiguy at yahoo.com
Wed Dec 1 14:18:20 PST 2010


On Wed, 01 Dec 2010 13:58:25 -0500, Jonathan M Davis <jmdavisProg at gmx.com>  
wrote:

> On Wednesday, December 01, 2010 08:42:23 flyinghearts wrote:
>> void check(string s)  {}
>> void check(wstring s) {}
>> void check(dstring s) {}
>>
>> void main()
>> {
>>   check("test");
>>   //check("test"c);
>> }
>>
>>
>> D:\Desktop\d\zb.d(7): Error: function zb.check called with argument  
>> types:
>> 	((string))
>> matches both:
>> 	zb.check(string s)
>> and:
>> 	zb.check(immutable(dchar)[] s)
>>
>>
>>
>>
>>
>> The type of "test" is string, isn't it?
>
> Not exactly. A string literal implictly casts to all 3 string types. You  
> can add
> a suffix to force it to be a wstring or dstring (I don't think that  
> there's a suffix
> for a normal string though), or you can cast it to the exact one you  
> want, or
> you can assign it to a variable first. If you use auto, I believe that  
> it will
> default to string rather than wstring or dstring, but string literals  
> implicitly
> cast to all 3, so the compiler considers your code to be ambiguous.

I think it's a bug.  This compiles:

void check(int i) {}
void check(long i) {}
void check(short i) {}

void main()
{
     check(1);
}

-Steve


More information about the Digitalmars-d mailing list