Jump to page: 1 2
Thread overview
[Issue 18385] [REG 2.079] method cannot be overloaded with another extern(C) method
[Issue 18385] [REG nightly] function cannot be overloaded with another extern(C) function
Feb 06, 2018
Jack Stouffer
Feb 23, 2018
Mike Franklin
Feb 23, 2018
Mike Franklin
Feb 23, 2018
Walter Bright
Feb 23, 2018
Martin Nowak
Feb 23, 2018
Martin Nowak
Feb 23, 2018
Martin Nowak
Feb 23, 2018
Martin Nowak
Feb 23, 2018
Jacob Carlborg
Feb 23, 2018
Jesse Phillips
Mar 03, 2018
Jacob Carlborg
Jul 01, 2018
greenify
February 06, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jack@jackstouffer.com
           Hardware|x86                         |All

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slavo5150@yahoo.com

--- Comment #1 from Mike Franklin <slavo5150@yahoo.com> ---
I tested this at the module level: https://run.dlang.io/is/6iuGF4

It fails with a "multiple definition" linker error for 2.071.2 ~ 2.074.1.  It succeeds beginning with 2.075.1, but displays a linker warning "Warning: size of symbol `foo` changed"

I don't think this should have ever compiled, and I'm tempted to say that this bug has finally been fixed.  But I would be delighted to be proven wrong.

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=15217

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|---                         |INVALID

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
Yes, it should never have compiled, and it cannot work, as two functions with the same mangled name cannot both exist in the executable.

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

--- Comment #3 from Martin Nowak <code@dawg.eu> ---
(In reply to Jacob Carlborg from comment #0)
> Note that global C function will not have a mangling, but methods of a struct or class declared as `extern (C)` will get mangled as a D method. This can be used as a callback function for a C function.

So you're bug report is about

cat > bug.d << CODE
struct S
{
    extern(C) static void foo(int) {}
    extern(C) static void foo(double) {}
}
CODE
dmd -c bug.d
----
Error: function bug.S.foo(double) cannot be overloaded with another extern(C)
function at /home/dawg/Code/D/bug.d(3)
----

instead
?

For top-level functions there is no way to just use C calling convention without the mangling, so the example from the OP will clearly lead to a multiple definition problem and undefined behavior dependening on various linker behaviors.

Introduced here https://github.com/dlang/dmd/pull/7577.

BTW, please use [Reg <upcoming version>] instead of a non-permanent [Reg nightly]. For nightlies it's the next major version, so 2.079.0 in your case.

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |code@dawg.eu
         Resolution|INVALID                     |---

--- Comment #4 from Martin Nowak <code@dawg.eu> ---
(In reply to Walter Bright from comment #2)
> Yes, it should never have compiled, and it cannot work, as two functions with the same mangled name cannot both exist in the executable.

Not so fast, the report about methods being broken is still somewhat valid.
In that case `extern(C)` only affects the calling convention but not the
mangling, and has mentioned use-cases as callbacks.
It's relatively easy to just use different names for that use-case, so we might
decide to deprecate this overloading if that seems necessary.

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[REG nightly] function      |[REG 2.079] method cannot
                   |cannot be overloaded with   |be overloaded with another
                   |another extern(C) function  |extern(C) method

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

--- Comment #5 from Martin Nowak <code@dawg.eu> ---
https://github.com/dlang/dmd/pull/7577/files#diff-3084a264389e086215b36670ae9f4a3dR386

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

--- Comment #6 from Jacob Carlborg <doob@me.com> ---
(In reply to Martin Nowak from comment #3)

> So you're bug report is about
> 
> cat > bug.d << CODE
> struct S
> {
>     extern(C) static void foo(int) {}
>     extern(C) static void foo(double) {}
> }
> CODE
> dmd -c bug.d
> ----
> Error: function bug.S.foo(double) cannot be overloaded with another
> extern(C) function at /home/dawg/Code/D/bug.d(3)
> ----
> 
> instead
> ?

Yes, I actually have a class. I just tried to reduce the test case as much as possible.

--
February 23, 2018
https://issues.dlang.org/show_bug.cgi?id=18385

Jesse Phillips <Jesse.K.Phillips+D@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Jesse.K.Phillips+D@gmail.co
                   |                            |m

--- Comment #7 from Jesse Phillips <Jesse.K.Phillips+D@gmail.com> ---
So C clearly doesn't support function overloads, but D provides for better type checking and generally expects as much.

I think it would be nice to allow D to specify function overloads if the C call is ultimately the same (parameter sizes and such).

This way in D a function can be specified to accept pointer types of A, B, and C rather than needing to be a void* as it is defined in C. I think it is similar to marking a parameter const even though it has no meaning to C and isn't actually enforced. This also appears to be how DWT has utilized definitions.

I've realized that my upgrade to dxml and DWT for an application has cause my application to not compile on any of the D compilers, so a solution here would be nice or for [18475] to be fixed on 2.078.

18475: https://issues.dlang.org/show_bug.cgi?id=18475

--
« First   ‹ Prev
1 2