(non-)extern(C) function parameter vs templates

2013-09-17 Thread Luís.Marques

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?


Re: (non-)extern(C) function parameter vs templates

2013-09-17 Thread Luís.Marques

Nevermind. Lack of sleep --;;

:-)


Re: (non-)extern(C) function parameter vs templates

2013-09-17 Thread John Colvin

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.


Re: (non-)extern(C) function parameter vs templates

2013-09-17 Thread Luís.Marques

On Tuesday, 17 September 2013 at 13:50:20 UTC, John Colvin wrote:
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.


Ah, OK! I said nevermind because the following works (on 2.063.2):

void foo(T)(F f) { }
void foo(T)(E e) { }

So I guess it's more subtle than that. Thanks!


Re: (non-)extern(C) function parameter vs templates

2013-09-17 Thread Luís.Marques

On Tuesday, 17 September 2013 at 13:59:05 UTC, Luís Marques wrote:

So I guess it's more subtle than that.


I meant it didn't have to do with extern(C).