D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2372 - Template parameter types given as template parameter inhibits template instantiation + missing line number
Summary: Template parameter types given as template parameter inhibits template instan...
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 major
Assignee: No Owner
URL:
Keywords: diagnostic, rejects-valid
: 2239 (view as issue list)
Depends on:
Blocks:
 
Reported: 2008-09-24 03:15 UTC by Simen Kjaeraas
Modified: 2017-06-28 09:06 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Simen Kjaeraas 2008-09-24 03:15:26 UTC
Passing the type of a template parameter as another template parameter causes errors when compiling. Take the following code:

////

void foo(T, T t)(mystruct!(T, t) bar)
{
}

struct mystruct(T, T t)
{
}

void main()
{
	mystruct!(int, 2) baz;
	foo(baz);
}

////

Compiling it yields this result:

Error: identifier 'T' is not defined
Error: T is used as a type
foo.d(12): template foo.foo(T,T t) does not match any function template declarat
ion
foo.d(12): template foo.foo(T,T t) cannot deduce template function from argument
 types !()(mystruct!(int,2))

Note also that the first two messages have no line number.
Comment 1 Simen Kjaeraas 2010-06-17 10:44:15 UTC
*** Issue 2239 has been marked as a duplicate of this issue. ***
Comment 2 hsteoh 2014-07-12 04:42:39 UTC
Still happens in git HEAD.
Comment 3 Jonathan Marler 2014-11-04 15:55:08 UTC
Can you confirm this code has basically the same issue or should a new bug be filed for it?
--------------------------------------
import std.stdio;

template Transform(T)
{
  alias Transform = T;
}
void testTransform(T)(Transform!T t)
{
}
void testNoTransform(T)(T t)
{
}
void main(string[] args)
{
  testTransform(3);     // FAILS "cannot deduce function..."
  testTransform!int(3);

  testNoTransform(3);
  testNoTransform!int(3);
}
--------------------------------------

The test(3) line fails with this error message:

main.d(15): Error: template main.testTransform cannot deduce function from argument types !()(int), candidates are:
main.d(7):        main.testTransform(T)(Transform!T t)
Comment 4 Simen Kjaeraas 2017-06-28 09:06:08 UTC
Jonathan Marler's code does indeed exhibit the same issue, and gives a small demonstration of why this will never work in the general case. For a more explicit demonstration:

void foo(T)(Bar!T value) {}

template Bar(T) {
    alias Bar = string;
}

foo("test"); // What is T?

Clearly, in this case T cannot be determined. Real life examples could be significantly more complex, and even involve CTFE and string mixins. There's simply no way to make this work in the language.