Bug 6891 – template with uint value parameter causes several issues
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-04T16:31:00Z
Last change time
2012-05-02T14:55:05Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
ricochet1k
Comments
Comment #0 by ricochet1k — 2011-11-04T16:31:32Z
This bug is closely related to issue 4960 and issue 6745, although I don't think it's an exact duplicate.
One of the simplest test cases I could come up with:
----
struct S(uint N) {
void f(S!N u) { }
}
alias S!1 A;
void main()
{
A().f(A());
}
----
Which gives the following error messages:
templatetest.d(10): Error: function templatetest.S!(1).S.f (S!(N) u) is not callable using argument types (S!(1))
templatetest.d(10): Error: cannot implicitly convert expression (S()) of type S!(1) to S!(N)
In this form it is fairly easy to work around, by either changing uint to int in the struct declaration or using S!1u instead of S!1. However, I derived this from a slightly different test case:
----
struct S(int N, T) {
void f(U)(S!(N, U) u) { }
}
alias S!(1, void) A;
void main()
{
A().f(A());
}
----
Which gives me these error messages:
templatetest.d(10): Error: template templatetest.S!(1,void).S.f(U) does not match any function template declaration
templatetest.d(10): Error: template templatetest.S!(1,void).S.f(U) cannot deduce template function from argument types !()(S!(1,void))
In this version, changing the type of N or 1 doesn't do anything, and I have not found a way to work around it.
Comment #1 by lovelydear — 2012-05-01T15:51:12Z
The first case compiles with 2.059, not the second.