Thread overview
[Issue 19101] Miscompilation on extern(C++) overloads with D types
Jul 30, 2018
kinke@gmx.net
Aug 14, 2018
kinke@gmx.net
Dec 17, 2022
Iain Buclaw
July 30, 2018
https://issues.dlang.org/show_bug.cgi?id=19101

kinke@gmx.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #1 from kinke@gmx.net ---
> The fix: use the full D type for mangling.

Assuming you suggest mangling `module mod; extern(C++) class C {};` as `mod::C`, that would prevent all interop with external C++ symbols in the root namespace, as there is no root namespace in D. Likewise, you'd have to have a huge `std.d` file for the std::* symbols etc.

--
August 14, 2018
https://issues.dlang.org/show_bug.cgi?id=19101

--- Comment #2 from johanengelen@weka.io ---
> Assuming you suggest mangling `module mod; extern(C++) class C {};` as `mod::C`

No, of course not.

I suggest mangling `module mod; class C {};` as `mod.C`. Currently we mangle
extern(D) types as if they are extern(C++) types for extern(C++) templated
functions. In the original example, we currently mangle `foo!(a.A)(a.A)` as
`foo!(A)(A)`. Hence the miscompilation / clash with mangling of
`foo!(b.A)(b.A)`.

--
August 14, 2018
https://issues.dlang.org/show_bug.cgi?id=19101

--- Comment #3 from kinke@gmx.net ---
(In reply to johanengelen from comment #2)
> Currently we mangle extern(D) types as if they are extern(C++) types for extern(C++) templated functions.

Ah now I get it, I overlooked that the 2 structs are extern(D). [The function
doesn't need to be templated.] Not sure if a dot can be used in typenames for
C++ mangling. Also not sure how much code that would break (structs needing
`extern(C++)` for C++ interop, whereas that's optional now).

--
August 14, 2018
https://issues.dlang.org/show_bug.cgi?id=19101

--- Comment #4 from johanengelen@weka.io ---
> Not sure if a dot can be used in typenames for C++ mangling.

Good point. `a.A` should not be mangled as `a::A` (using the C++ namespace divider), because that then would clash with C++ types.

I think it is OK if the mangle can never be expressed in C++ when there are D
types involved, because C++ cannot express the D types anyway. What I mean is,
`foo!A` should be expressible in C++:
```
extern(C++) struct A {}
extern(C++) int foo(T)(T t) {}
```
but doesn't have to in this code:
```
struct A {}
extern(C++) int foo(T)(T t) {}
```

So C++ doesn't have to be able to express the mangled name, but it would definitely be nice if C++ demanglers can demangle it into something sensible. A dot is actually allowed in symbol names, so we can use it as part of the name? (i.e. pretend that the class name of A is "a.A".)

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

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--
December 13
https://issues.dlang.org/show_bug.cgi?id=19101

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19459

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--