February 24, 2017 D to C++ Name Mangling Discrepancy | ||||
---|---|---|---|---|
| ||||
Hello, I stumbled upon a mangling issue when trying to interface C++ with D. Basically I have the following entities: 1) The D stl_pair code: module core.stdcpp.stl_pair; version (CRuntime_Glibc) { extern (C++, std) struct pair(T1, T2) { alias first_type = T1; alias second_type = T2; T1 first; T2 second; this(T1 x, T2 y) { first = x; second = y; } this(U1, U2)(auto ref U1 x, auto ref U2 y) { if (isConvertible!(U1, T1) && isConvertible!(U2, T2)) { first = x; second = y; } } this(U1, U2)(auto ref pair!(U1, U2) p) { first = p.first; second = p.second; } this(U1, U2)(auto ref const pair!(U1, U2) p) { first = p.first; second = p.second; } // this should link directly void swap(ref pair rhs); }} 2) The D test code: import core.stdcpp.stl_pair; void main() { auto p = pair!(void*,void*)(null, null); auto p2 = pair!(void*,void*)(null, null); p.swap(p2); } 3) The C++ test code: #include <utility> void unused(std::pair<void*,void*> &p) { p.swap(p); } Using the C++ file I create an object file and link it with the D test code. Now this generated the following error: " undefined reference to `_ZNSt4pairIPvS1_E4swapERStS0_IS1_S1_E' " After inspecting the C++ obj it is clearly noticeable that we have mangling discrepancy: _ZNSt4pairIPvS0_E4swapERS1_ // C++ generated _ZNSt4pairIPvS1_E4swapERStS0_IS1_S1_E // D required Currently I have no experience with this part and require assistance. If someone could guide me where to look and how to fix this I can create the PR. Thanks, Alex |
February 24, 2017 Re: D to C++ Name Mangling Discrepancy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandru Razvan Caciulescu | On Friday, 24 February 2017 at 17:50:47 UTC, Alexandru Razvan Caciulescu wrote:
>
> Currently I have no experience with this part and require assistance. If someone could guide me where to look and how to fix this I can create the PR.
>
> Thanks,
> Alex
Mangling for templates is done in dtemplate.d
The it uses the Visitor defined in dmangle.d
|
Copyright © 1999-2021 by the D Language Foundation