For example say I have a class foo and a class diverged from foo called bar, and I have a template specialization for foo and a template by the same name that takes an alias. I instantiate that template with bar and get the alias version. The spec say that the most specialized version is chosen, but isn't an alias template the least specialized type of template, even more so than a unspecialized template that takes a generic type?
Comment #1 by spunit262 — 2007-11-10T13:28:50Z
Created attachment 208
an example
Comment #2 by gide — 2009-04-03T16:04:30Z
Including original attachment in this comments. Issue looks similar to BUG 918.
import std.stdio;
typedef char ctd;
class Foo { }
class Bar : Foo { }
void main()
{
Baz!(char)(); /* regular template version used only because
* template alias parameters reject basic types. */
Baz!(ctd)(); // alias version used
Baz!(Foo)(); // Foo version used
Baz!(Bar)(); // alias version used
}
void Baz(T)()
{
writefln("regular template version called with ", T.stringof);
}
void Baz(T : Foo)()
{
writefln("foo specialization called with ", T.stringof);
}
void Baz(alias T)()
{
writefln("alias version called with ", T.stringof);
}
Comment #3 by witold.baryluk+d — 2010-01-24T21:09:54Z
This problem is still present in DMD 2.039.
It looks that from unknown reasons bug918 is solved (nobody comented what was source of regression and dissapiring of it). Probably it is different aspect here of template matching.
Comment #4 by dlang-bugzilla — 2014-02-03T14:32:36Z
Still happens with 2.064. The typedef part is no longer relevant as the language feature is going away, but the class hierarchy part remains.
Shorter test case:
class Foo { }
class Bar : Foo { }
void f(T : Foo)() { }
void f(alias T)() { assert(false); }
void main()
{
f!Bar();
}
Comment #5 by dlang-bugzilla — 2014-02-03T14:34:49Z
*** Issue 3137 has been marked as a duplicate of this issue. ***