Bug 11452 – IFTI failure for aliased static array parameter

Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2013-11-06T05:39:16Z
Last change time
2018-04-17T16:10:31Z
Assigned to
No Owner
Creator
Atila Neves

Comments

Comment #0 by atila.neves — 2013-11-06T05:39:16Z
template_alias.d: struct Foo(uint LENGTH, T = bool) { } template Foos(uint SIZE, T = bool) { alias Foo!(SIZE, T)[] Foos; } void func1(uint num, uint size)(Foo!(size)[]) { } void func2(uint num, uint size)(Foos!(size)) { } void main() { Foo!(4)[] foos; func1!(2)(foos); //compiles func2!(2)(foos); //doesn't compile } dmd template_alias.d template_alias.d(18): Error: template template_alias.func2 does not match any function template declaration. Candidates are: template_alias.d(12): template_alias.func2(uint num, uint size)(Foos!(size)) template_alias.d(18): Error: template template_alias.func2(uint num, uint size)(Foos!(size)) cannot deduce template function from argument types !(3)(Foo!(4)[]) template_alias.d(18): Error: template instance func2!(3) errors instantiating template
Comment #1 by public — 2013-11-06T05:54:06Z
Reduced test case: template Foos(uint SIZE) { alias Foos = int[SIZE]; } void func(uint size)(Foos!size) {} void main() { int[4] foos; func!4(foos); // does compile func(foos); // doesn't compile }
Comment #2 by simen.kjaras — 2013-11-06T08:45:06Z
I'm not sure this is something we actually do want. Consider: template Foos(uint size, T) { static if (is(T == string)) { alias Foos = T[size*3]; } else { alias Foos = T[size]; } } void func(uint size, T)(Foos!(size, T)) { } void test() { string[6] a; func(a); } How is the poor compiler to figure out the values of size and T? An even simpler example: template Foos(uint size, T) { alias Foos = float; } Bottom line is, templates can be arbitrarily complex. This sort of matching can only be done for very simple cases.
Comment #3 by ag0aep6g — 2018-04-17T16:10:31Z
*** This issue has been marked as a duplicate of issue 10884 ***