Bug 1641 – Template function arg deduction gets confused when used with implicit conversions
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-11-05T15:50:00Z
Last change time
2015-06-09T01:14:21Z
Keywords
rejects-valid
Assigned to
nobody
Creator
andrei
Comments
Comment #0 by andrei — 2007-11-05T15:50:56Z
The use case is simple:
template foo(T)
{
void foo(U)(U a, T b, T c)
{
}
}
void main()
{
int x;
foo!(uint)(x, 0, 1);
}
The template engine should properly bind 0 and 1 to type uint, but it fails to do so. As a result, the entire program does not compile although it should.
Comment #1 by shro8822 — 2007-11-05T16:21:43Z
If you convert the call to:
foo!(uint)(x, 0u, 1u);
or
foo!(int)(x, 0, 1);
it works. This might indicate that type conversion is not working correctly here. Either way it gives a work around to any one who just need to get something done.
Comment #2 by smjg — 2007-11-11T10:53:27Z
No nested template is required - this is sufficient to show the problem (DMD 1.023 and 2.007, Windows):
----------
void foo(U)(U a, uint b, uint c) {
}
void main() {
int x;
foo(x, 0, 1);
}
----------
bz1641a.d(6): template bz1641a.foo(U) does not match any template declaration
bz1641a.d(6): template bz1641a.foo(U) cannot deduce template function from argument types (int,int,int)
----------
So the problem is that, when trying to perform IFTI, it doesn't look for implicit conversions.
Comment #3 by k.hara.pg — 2011-10-21T03:48:51Z
With git master (1ff6ad8509), the sample codes compile without error.