ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

Struct with two or more bases will have duplicate member names

Open 2A5F opened this issue 10 months ago • 0 comments

https://github.com/dotnet/ClangSharp/issues/367 partially solves the problem, but pure virtual classes will still be generated duplicate

struct Foo
{
    virtual ~Foo() = default;
};

struct Bar
{
    virtual ~Bar() = default;
};

struct Baz: Foo, Bar
{
};

output:

public unsafe partial struct Foo : Foo.Interface
{
    public void** lpVtbl;
    public void Dispose()
    {
        ((delegate* unmanaged[Thiscall]<Foo*, void>)(lpVtbl[0]))((Foo*)Unsafe.AsPointer(ref this));
    }
    public interface Interface
    {
        void Dispose();
    }
}

public unsafe partial struct Bar : Bar.Interface
{
    public void** lpVtbl;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Dispose()
    {
        ((delegate* unmanaged[Thiscall]<Bar*, void>)(lpVtbl[0]))((Bar*)Unsafe.AsPointer(ref this));
    }
    public interface Interface
    {
        void Dispose();
    }
}

public unsafe partial struct Baz : Baz.Interface
{
    public void** lpVtbl;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Dispose()
    {
        ((delegate* unmanaged[Thiscall]<Baz*, void>)(lpVtbl[0]))((Baz*)Unsafe.AsPointer(ref this));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Dispose()
    {
        ((delegate* unmanaged[Thiscall]<Baz*, void>)(lpVtbl[0]))((Baz*)Unsafe.AsPointer(ref this));
    }
    public interface Interface : Foo.Interface, Bar.Interface
    {
    }
}

This is wrong. There should be multiple virtual table pointers when multiple inheritance occurs.

2A5F avatar Feb 08 '25 13:02 2A5F