Thread overview
overloaded extern(C) called without error
Sep 10, 2013
Luís Marques
Sep 10, 2013
Luís Marques
Sep 10, 2013
Dicebot
Sep 11, 2013
Jacob Carlborg
Sep 11, 2013
deadalnix
Sep 11, 2013
Dicebot
Sep 10, 2013
David Nadlinger
September 10, 2013
I know that extern(C) functions cannot be legally overloaded, but not issuing an error in the following situation seems wrong / a bug:

    extern(C) void foo(int);
    extern(C) void foo() {}

    void main()
    {
        foo(42);
    }
September 10, 2013
I just realized I wasn't clear -- it calls the (wrong) overloaded function:

    extern(C) void foo(int);
    extern(C) void foo() { writeln("yes, this is called"); }

    void main()
    {
        foo(42);
    }

outputs:

    yes, this is called
September 10, 2013
On Tuesday, 10 September 2013 at 14:07:18 UTC, Luís Marques wrote:
> I just realized I wasn't clear -- it calls the (wrong) overloaded function:
>
>     extern(C) void foo(int);
>     extern(C) void foo() { writeln("yes, this is called"); }
>
>     void main()
>     {
>         foo(42);
>     }
>
> outputs:
>
>     yes, this is called

This is why mixing ABI and mangling in one entity is bad. And why overloading extern(C) functions is compile-time error in C++.
September 10, 2013
On Tuesday, 10 September 2013 at 14:04:58 UTC, Luís Marques wrote:
>     extern(C) void foo(int);
>     extern(C) void foo() {}

I agree that this should not be legal. LDC detects this in the glue layer (we would have to add a workaround for the corresponding LLVM restriction otherwise):

---
$ ldc2 test.d
test.d(4): Error: Function type does not match previously declared function with the same mangled name: foo
---

David
September 11, 2013
On 2013-09-10 16:38, Dicebot wrote:

> This is why mixing ABI and mangling in one entity is bad. And why
> overloading extern(C) functions is compile-time error in C++.

There's a GCC (Clang) extension that enables support function overloading in C. I guess it's a bit overkill to support in D.

-- 
/Jacob Carlborg
September 11, 2013
On Tuesday, 10 September 2013 at 14:38:56 UTC, Dicebot wrote:
> On Tuesday, 10 September 2013 at 14:07:18 UTC, Luís Marques wrote:
>> I just realized I wasn't clear -- it calls the (wrong) overloaded function:
>>
>>    extern(C) void foo(int);
>>    extern(C) void foo() { writeln("yes, this is called"); }
>>
>>    void main()
>>    {
>>        foo(42);
>>    }
>>
>> outputs:
>>
>>    yes, this is called
>
> This is why mixing ABI and mangling in one entity is bad. And why overloading extern(C) functions is compile-time error in C++.

I think this is another form of the unclear qualifier binding problem.

Qualifier bind to symbol : mangling.
Qualifier bind to type : calling convention.
September 11, 2013
On Wednesday, 11 September 2013 at 08:26:02 UTC, deadalnix wrote:
> I think this is another form of the unclear qualifier binding problem.
>
> Qualifier bind to symbol : mangling.
> Qualifier bind to type : calling convention.

Yeah, giving tool to differ those can be an elegant way out of this inconvenience.