Bug 14420 – partial template ordering with specialization and different arities seems broken
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-07T07:47:00Z
Last change time
2015-04-07T15:06:50Z
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2015-04-07T07:47:41Z
void foo(string op:"+", T)(ref T val, T mod)
{
}
void foo(string op, T, V1)(ref T val, V1 mod)
{
}
void main()
{
int i32 = 12;
foo!"+"(i32, 13); // should match first
ubyte u8;
foo!"+"(u8, 1); // not sure about this one
}
---
Maybe my intuition is wrong here, but it's surprising that the first template function which is specialized for op:"+" isn't called.
Comment #1 by ketmar — 2015-04-07T08:25:54Z
i'm expecting the same (with second instantiates non-specialized template, which it does currently).
Comment #2 by k.hara.pg — 2015-04-07T15:06:50Z
(In reply to Martin Nowak from comment #0)
> void foo(string op:"+", T)(ref T val, T mod)
>
> void foo(string op, T, V1)(ref T val, V1 mod)
> ---
"Partial specialization order" is defined only when two templates have same template parameters except for TemplateTypeParameterSpecialization. For example:
template A(string op, T) {} // A1
template A(string op:"+", T) {} // A2 is a specialized version of A1
But in the OP code, Two 'foo's have different number of parameters, so neither of them is not a specialized version of one another.
Therefore the ambiguous error is correct result.