extern(C++):
class Child : Parent
{
}
extern(C++, "Namespace") extern(C++, class) struct Struct
{
}
class Parent
{
~this();
//pragma(msg, __traits(getCppNamespaces, Struct));
private static void func(Struct*);
pragma(msg, " MangleInClass: " ~ func.mangleof);
}
pragma(msg, "MangleOutsideClass: " ~ Parent.func.mangleof);
///////////////////////////////////////////////////////////////
The code above prints the mangling of the same member function twice. For Windows 64 bit the output is:
MangleInClass: ?func@Parent@@CAXPEAUStruct@@@Z
MangleOutsideClass: ?func@Parent@@CAXPEAVStruct@Namespace@@@Z
For Linux the output is:
MangleInClass: _ZN6Parent4funcEP6Struct
MangleOutsideClass: _ZN6Parent4funcEPN9Namespace6StructE
Normally it should print the same mangling inside and outside the class, but actually the mangling is incomplete inside the class. On both platforms it misses the namespace and on Windows also ignores extern(C++, class). The mangling printed outside the class is correct.
If trait getCppNamespaces is used inside the class for Struct, then the mangling will later also be printed correctly inside the class.
Comment #1 by robert.schadek — 2024-12-13T19:20:03Z