D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1641 - Template function arg deduction gets confused when used with implicit conversions
Summary: Template function arg deduction gets confused when used with implicit convers...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2007-11-05 15:50 UTC by Andrei Alexandrescu
Modified: 2015-06-09 01:14 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2007-11-05 15:50:56 UTC
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 BCS 2007-11-05 16:21:43 UTC
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 Stewart Gordon 2007-11-11 10:53:27 UTC
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 Kenji Hara 2011-10-21 03:48:51 UTC
With git master (1ff6ad8509), the sample codes compile without error.