Issue ID: 16623
           Summary: Support C++ Name Mangling
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: druntime

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*

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.


Reply via email to