string literal string and immutable(char)* overload ambiguity

Nicholas Wilson iamthewilsonator at hotmail.com
Tue Jul 31 14:13:57 UTC 2018


is there any particular reason why

void foo(string a) {}
void foo(immutable(char)* b) {}

void bar()
{
     foo("baz");
}

result in

Error: foo called with argument types (string) matches both:
foo(string a)
and:
foo(immutable(char)* b)

especially given the pointer overload is almost always
void foo(immutable(char)* b)
{
     foo(b[0 .. strlen(b)]);
}
and if I really want to call the pointer variant I can with
     foo("baz".ptr);
but I can't call the string overload with a literal without 
creating a temp.

I think we should make string literals prefer string arguments.



More information about the Digitalmars-d mailing list