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