Bug 14797 – template with inout parameter `foo(String: inout(CharT)[], CharT)` should be implicitly instanciated as foo!(char[], char)
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-07-13T05:56:00Z
Last change time
2015-07-13T14:14:06Z
Assigned to
nobody
Creator
ttanjo
Comments
Comment #0 by ttanjo — 2015-07-13T05:56:07Z
In the following code, foo(String: inout(CharT)[], CharT) should be implicitly instanciated as foo!(char[], char) but it does not.
I checked it doesn't work with dmd trunk v2.068-devel-4bc3d3d on Mac OSX.
----
inout(dchar)[] foo(String: inout(CharT)[], CharT)(String str)
{
return typeof(return).init;
}
void main()
{
char[] str = "str".dup;
auto b = foo!(inout(char)[], char)(str); // it works
auto a = foo(str); // it doesn't work but it should
}
----
Output:
error.d(10): Error: template error.foo cannot deduce function from argument types !()(char[]), candidates are:
error.d(1): error.foo(String : inout(CharT)[], CharT)(String str)
P.S. Its severity may be `enhancement` instead of normal.
Comment #1 by schveiguy — 2015-07-13T14:14:06Z
This is expected behavior. What you have is a specialization for inout(CharT) where str is inout(CharT)[], and you are passing in just char[], which doesn't match the specialization.
IFTI breaks down in certain ways with specializations, but this should work if you have an inout(char)[] to pass in.
I think all you need to do to fix your example is:
inout(dchar)[] foo(CharT)(inout(CharT)[] str)