Bug 16623 – Support C++ Name Mangling

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-10-18T15:50:06Z
Last change time
2018-06-08T01:41:49Z
Keywords
C++, mangling
Assigned to
No Owner
Creator
Jack

Comments

Comment #0 by gyroheli — 2016-10-18T15:50:06Z
Add support to mangle C++ names. It can be useful when writing a wrapper for a library. Generally C++ uses references, but they aren't as useful in D, since reference's can't exist as variables. So having reference types return a pointer instead would be better, which is just a synthetically change. As a reference is essentially a pointer that just behaves a bit differently. // C++ /////////////////////////////// struct MyStruct; namespace MyNamespace { MyStruct& GetGlobal(); } // D ///////////////////////////////// struct MyStruct; extern(C++, MyNamespace) { // generates correct mangle, but not desired signature // ref MyStruct GetGlobal(); ref MyStruct function() _GetGlobal; // desired but requires pragma(mangle) // no cross platform way to get C++ mangle of desired signature // error: Can't mangle extern(C++) functions. pragma(mangle, mangleFunc!(typeof(_GetGlobal))("GetGlobal")) MyStruct* GetGlobal(); } Adding support, perhaps with some help from the compiler (it has name mangling built into it already, just need to expose it?) to be able to get C++ name mangling would be nice.
Comment #1 by pro.mathias.lang — 2018-06-08T01:41:49Z
Well, this has been implemented a while ago!