Bug 8018 – Template fails to instantiate with templated argument
Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-02T20:45:00Z
Last change time
2013-09-17T14:31:32Z
Keywords
rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2012-05-02T20:45:48Z
version=Fail;
enum Enum { Foo }
struct Stub { }
template Temp(alias T) { alias Stub Temp; }
struct Foo
{
auto call(Enum en)()
{
Stub arg;
test!en(arg);
return arg;
}
version(Fail)
{
void test(Enum en)(Temp!en arg)
if (0) {}
void test(Enum en)(Temp!en arg)
if (1) {}
}
else
version(Ok)
{
void test(Enum en)(Stub arg)
if (0) {}
void test(Enum en)(Stub arg)
if (1) {}
}
}
void main()
{
Foo foo;
foo.call!(Enum.Foo)();
}
This fails with:
test.d(14): Error: template test.Foo.test does not match any function template declaration
test.d(14): Error: template test.Foo.test cannot deduce template function from argument types !(cast(Enum)0)(Stub)
test.d(40): Error: template instance test.Foo.call!(cast(Enum)0) error instantiating
You can comment out the test template in the version(Fail) that has this constraint: "if (0) {}" and it will compile again.
You can also version=Fail to version=Ok then it will compile. The version=Ok code doesn't instantiate the Temp template and this seems to work. But both versions should work because both templates resolve the type as a Stub struct.
Comment #1 by andrej.mitrovich — 2012-05-02T20:48:16Z
Ok there's another workaround, just make the last type implicit:
void test(Enum en, StubType)(StubType arg)
So maybe it's not a major bug. :)
Comment #2 by andrej.mitrovich — 2013-09-17T14:31:32Z