Thread overview
[Issue 15843] D-type mangling used for extern(C) (extern) function declaration inside function body, on LDC, GDC, and DMD.
Oct 26, 2017
Walter Bright
Jan 16, 2022
Basile-z
Jan 16, 2022
Iain Buclaw
Jan 16, 2022
Basile-z
Jan 16, 2022
Mathias LANG
Jan 17, 2022
anonymous4
Dec 17, 2022
Iain Buclaw
Oct 03
basile-z
October 26, 2017
https://issues.dlang.org/show_bug.cgi?id=15843

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |mangling
                 CC|                            |bugzilla@digitalmars.com

--
January 16, 2022
https://issues.dlang.org/show_bug.cgi?id=15843

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com
           Hardware|x86_64                      |All
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=6132
                 OS|Linux                       |All

--
January 16, 2022
https://issues.dlang.org/show_bug.cgi?id=15843

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@gdcproject.org

--- Comment #1 from Iain Buclaw <ibuclaw@gdcproject.org> ---
I would err on the side of this is working as intended.  Nested functions are not compatible with C, and so should not have a C name (by declaring the function inside main, it implicitly gets a "this" context parameter)

--
January 16, 2022
https://issues.dlang.org/show_bug.cgi?id=15843

Basile-z <b2.temp@gmx.com> changed:

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

--
January 16, 2022
https://issues.dlang.org/show_bug.cgi?id=15843

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pro.mathias.lang@gmail.com

--- Comment #2 from Mathias LANG <pro.mathias.lang@gmail.com> ---
Perhaps we should error out on `extern` and `extern(XXX)` functions then?

--
January 17, 2022
https://issues.dlang.org/show_bug.cgi?id=15843

--- Comment #3 from anonymous4 <dfj1esp02@sneakemail.com> ---
Static nested functions with C calling convention are useful as system callbacks. They just don't need to be visible to other linked modules.

--
January 17, 2022
https://issues.dlang.org/show_bug.cgi?id=15843

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@gmail.com

--- Comment #4 from Steven Schveighoffer <schveiguy@gmail.com> ---
extern(C) specifies not only the mangling, but also the calling convention. So having extern(C) inner functions do serve a purpose. I think the mangling is really implementation defined, since C doesn't have any notion of inner functions.

Note that `extern` on its own isn't doing anything here.

If anything, I'd say pragma(mangle) should work in this context, that would at
least give a more straightforward path (really issue 22682).

Note that defining the prototype without `static` indeed suggests it should have a `this` pointer, but it doesn't work even if you add `static`.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=15843

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
October 03
https://issues.dlang.org/show_bug.cgi?id=15843

basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from basile-z <b2.temp@gmx.com> ---
Prgma mangle works locally since a year or so:

```
void main() {
    pragma(mangle, "func")
    extern(C) int func(int);
    static assert(func.mangleof == "func");
}
```

--