digitalmars.D.learn - Template overload causing an error even when a better non-template
- Andrej Mitrovic (36/36) Aug 30 2013 You're going to need DMD git-head to run this reduced example:
You're going to need DMD git-head to run this reduced example: ----- struct S { void opAssign(T)(T t) if (Constraint!T) { } void opAssign(typeof(null)) { } template Constraint(T) if (is(T == int)) { enum bool Constraint = false; } } void main() { S s; s = null; } ----- This fails with: test.d(6): Error: template instance Constraint!(typeof(null)) does not match template declaration Constraint(T) if (is(T == int)) However I don't think the compiler should even attempt to instantiate the template when there's a better non-template overload match. The code example is contrived, but in the real code there's several overloads of "Constraint" which do more sophisticated checking on their type (some work on functions, others on delegates, structs, classes, etc). Hence why the constraint templates themselves need to have constraints, but this is then causing the above error. I'm not looking for a workaround (there's plenty of ways to work around this), but I think this should be filed as a bug?
Aug 30 2013