mono/CppSharp

[Linux] Incorrect bindings generated for virtual methods overridden in C++

JordanL8 opened this issue · 0 comments

Apparent incorrect bindings generated for virtual method overridden in C++ and then called from C#. Works correctly in Windows.

  • Methods implemented in the base class are callable from C#.
  • Methods declared in the base class then implemented in the intermediary class in C++ are not callable from C# (no errors, just nothing happens)

repro drawio (1)

OS: Linux (Ubuntu 22.04.3 LTS)

Repro

C++
// .h
class IBaseClass
{
public:
	virtual void BaseMethod();
	virtual void CPPImplementedVirtualMethod() = 0;
	virtual void CSharpImplementVirtualMethod() = 0;
};

class IIntermediaryClass : public IBaseClass
{
	virtual void CPPImplementedVirtualMethod() override;
};
// .cpp
void IBaseClass::BaseMethod()
{
    // ... log that displays "Base Method"
}

void IIntermediaryClass::CPPImplementedVirtualMethod()
{
    // ... log that displays "Intermediary Method"
}
C#
class CSharpClass : IIntermediaryClass
{
    public override void CSharpImplementVirtualMethod()
    {
        Console.WriteLine("C# Method");
    }
}
CSharpClass @class = new CSharpClass();
@class.BaseMethod();
@class.CPPImplementedVirtualMethod();
@class.CSharpImplementVirtualMethod();

When generating bindings for Windows and running the above code, the following is logged:

  • Base Method
  • Intermediary Method
  • C# Method

When generating bindings for Linux and running the above code, the following is logged:

  • Base Method
  • C# Method