August 27, 2020
https://issues.dlang.org/show_bug.cgi?id=21203

          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.

--