D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15608 - extern(C++) mangling problem
Summary: extern(C++) mangling problem
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 normal
Assignee: No Owner
URL:
Keywords: C++, industry, mangling
Depends on:
Blocks:
 
Reported: 2016-01-26 04:12 UTC by Manu
Modified: 2019-06-10 04:49 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Manu 2016-01-26 04:12:54 UTC
C++:

class IComponent
{
  virtual Variant CallMethod(String method, Slice<const Variant> args) = 0;
};

class Component : public IComponent
{
  Variant CallMethod(String method, Slice<const Variant> args) override final;
};


D:

extern(C++) interface IComponent
{
  Variant CallMethod(String method, Slice!(const(Variant)) args);
}

extern (C++) class Component : IComponent
{
  final override Variant CallMethod(String method, Slice!(const(Variant)) args);
}


I think override + final is messing up the C++ mangling.

C++: ?CallMethod@Component@ep@@UEAA?AUVariant@2@U?$BaseString@D@2@U?$Slice@$$CBUVariant@ep@@@2@@Z
D:   ?CallMethod@Component@ep@@QEAA?AUVariant@2@U?$BaseString@D@2@U?$Slice@UVariant@ep@@@2@@Z

'U' is a 'Q', and C++ has a bonus '$$CB'
Comment 1 Manu 2016-01-26 04:13:47 UTC
MSVC 2015 - Win64
Comment 2 Walter Bright 2016-01-26 06:07:49 UTC
I need a complete example, i.e. the example must be standalone. String, Variant and Slice are not defined.
Comment 3 anonymous4 2016-01-26 10:31:16 UTC
Looks like 'U' is virtual, 'Q' is final, '$$CB' is const in Slice<const Variant>.
Comment 4 Manu 2016-01-28 02:22:56 UTC
(In reply to Walter Bright from comment #2)
> I need a complete example, i.e. the example must be standalone. String,
> Variant and Slice are not defined.

I define them as empty structs when testing.
  extern(C++) struct Slice(T) {}
  extern(C++) struct String {}
  extern(C++) struct Variant {}
Comment 5 Nicholas Wilson 2019-06-10 04:49:46 UTC
god bolt MSVC v19.20:
template<typename T>
struct Slice {};
struct String {};
struct Variant {};

void foo();
class IComponent
{
  virtual Variant CallMethod(String method, Slice<const Variant> args) = 0;
};

class Component : public IComponent
{
public:
  Variant CallMethod(String method, Slice<const Variant> args) override final
  {
      foo();
      Variant v;
      return v;
  }
};

LDC beta:

extern(C++) interface IComponent
{
  Variant CallMethod(String method, Slice!(const(Variant)) args);
}

extern (C++) class Component : IComponent
{
  final override Variant CallMethod(String method, Slice!(const(Variant)) args);
    pragma(msg, CallMethod.mangleof);
}

  extern(C++) struct Slice(T) {}
  extern(C++) struct String {}
  extern(C++) struct Variant {}

both give 

//?CallMethod@Component@@UEAA?AUVariant@@UString@@U?$Slice@$$CBUVariant@@@@@Z