bearophile <bearophileh...@lycos.com> wrote:

This program doesn't compile, dmd prints the errors:
test.d(4): Error: template test.foo(T) does not match any function template declaration test.d(4): Error: template test.foo(T) cannot deduce template function from argument types !()(const(int),int)
test.d(9): Error: template instance test.bar!(int) error instantiating

Are you able to tell me what is the error in this code?


void foo(T)(const T a, out T b) {}

void bar(T)(const T x, out T y) {
    foo(x, y); // line 4
}

void main() {
    int s1, s2;
    bar(s1, s2); // line 9
}


Bye, and thank you,
bearophile

Simpler test case:

void bar(T)(const T x, out T y) {}

void main() {
    const int s1;
    int s2;
    bar(s1, s2);
}

It seems DMD is confused by const(int) being such a nice fit for the
first parameter. This might have to do with s2 = s1 being ok.

It is probably worth noting that this works:


import std.traits;

void bar(T)(const T x, out T y) {}

void main() {
    const int s1;
    int s2;
    bar!(CommonType!(s1,s2))(s1, s2);
}


--
Simen

Reply via email to