www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21203] New: Accept pragma(mangle) on aggregate types


          Issue ID: 21203
           Summary: Accept pragma(mangle) on aggregate types
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: turkeyman gmail.com

pragma(mangle) is only accepted on hard functions and variables.
Adding support to AggregateDecl will allow the user to customise the mangling
for type names, and that mangle override should be used when composing mangled
names for functions/templates.

This is the key to allowing comprehensive C++ class interop.

For instance, this becomes possible:

struct ScopeClass(C)
  if (is(C == class)
  static if (__traits(getLinkage, C) == "C++")
    extern(C++, class)
    pragma(mangle, C.mangleof) // <- here's the magic!
    struct ScopeClass
      char[__traits(classInstanceSize, C)] buffer;

      //... all the things ...

And then consider these functions:

void fun(MyClass);                       // mangles MyClass*
void fun(const MyClass);                 // mangles const MyClass* const
void fun(ScopedClass!MyClass);           // mangles MyClass
void fun(const ScopedClass!MyClass);     // mangles const MyClass
void fun(ref ScopedClass!MyClass);       // mangles MyClass&
void fun(ref const ScopedClass!MyClass); // mangles const MyClass&

By allowing pragma(mangle) to apply to AggregateDecl, we can override the
mangling for the type names, and with this, we can write in-language tooling
that can handle classes in ALL the ways that C++ can express.

Aug 27 2020