On Tuesday, 17 September 2013 at 13:36:24 UTC, Luís Marques wrote:
This works:

    extern(C) alias F = void function();
              alias G = void function();

    void foo(F f) {}
    void foo(G g) {}

Indeed, the correct foo is called, depending on whether the passed function is extern(C) or not (although I must say that the syntax for declaring the alias F is not good, IMO; the extern(C) should come after the equal sign).

Yet, the following does not work:

    void foo(T)(F f) {}
    void foo(G g) {}

    Error: function foo conflicts with template foo(T)(F f).

or

    void foo(F f) {}
    void foo(T)(G g) {}

    Error: template foo(T)(E e) conflicts with function foo.

It this not incoherent? If non-templated functions can overload on extern(C)/non-extern(C) function parameter, why can't templated functions?

This works for me on dmd git master:

extern(C) alias F = void function();
alias G = void function();

void foo(T)(T g) {}
void foo(F f) {}

extern(C) void a(){}
void b(){}

void main()
{
    foo(&a);
    foo(&b);
}

It used to be that templates and normal functions couldn't overload each other, now they can. I'm not sure when the change was made, it might only be in git master.

Reply via email to