www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16623] New: Support C++ Name Mangling

https://issues.dlang.org/show_bug.cgi?id=16623

          Issue ID: 16623
           Summary: Support C++ Name Mangling
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: gyroheli gmail.com

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.

--
Oct 18 2016