Bug 10183 – Eponymous template instance fails to match in parameter list of other templates
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-27T03:57:00Z
Last change time
2013-05-27T06:04:44Z
Assigned to
nobody
Creator
jakobovrum
Comments
Comment #0 by jakobovrum — 2013-05-27T03:57:40Z
Code:
----
struct A(T, Unused)
{
T t;
}
template B(T)
{
alias B = A!(T, void);
}
void foo(T)(A!T a) {}
void main()
{
auto b = B!int(42); // OK, works
foo(b); // NG - causes error
}
----
Output:
----
test.d(18): Error: template test.foo does not match any function template declaration. Candidates are:
test.d(12): test.foo(T)(A!(T) a)
test.d(18): Error: template test.foo(T)(A!(T) a) cannot deduce template function from argument types !()(A!(int, void))
----
Could be a duplicate, but I don't know what to search for. Does not appear to be a regression.
The call to `foo` works when the second template parameter of A is removed.
Comment #1 by jakobovrum — 2013-05-27T04:07:18Z
Thinking more about it, I guess this might not be meant to work.
Comment #2 by k.hara.pg — 2013-05-27T04:58:31Z
(In reply to comment #0)
> Code:
> ----
> struct A(T, Unused)
> {
> T t;
> }
>
> template B(T)
> {
> alias B = A!(T, void);
> }
>
> void foo(T)(A!T a) {}
The pattern A!T means that the template A has _exactly_ one type template argument.
> void main()
> {
> auto b = B!int(42); // OK, works
>
> foo(b); // NG - causes error
But the type of b is A!(int, void), so it does not match to A!T during IFTI.
> }
In this case, template function foo should have following signature.
void foo(TL...)(A!TL a) {}
// TL would be deduced to (int, void)
or
void foo(T, TL...)(A!(T, TL) a) {}
// T would be deduced to int
// TL would be deduced to (void)
Comment #3 by jakobovrum — 2013-05-27T06:04:44Z
Yeah, I noticed after posting.
The problem with the amended caller code is that it leaks implementation details, as it were. It would be nice if there was a good way to solve this particular abstraction problem.