CppSharp: Ignored private field still exported

C++ code:

class CS_API AttributeConfig
{
	CS_IGNORE std::vector<kit::Matching::AttributeMetadata> _attribs;
public:
	AttributeConfig() {}
        // etc.
};

C# code includes the _attribs field which was previously (and needs to be) skipped.

public unsafe partial class AttributeConfig : IDisposable
            {
                [StructLayout(LayoutKind.Explicit, Size = 32)]
                public partial struct __Internal
                {
                    [FieldOffset(0)]
                    internal global::Std.Vector.__Internal _attribs;
                    // etc.

Note that the _attribs is not actually used anywhere else in C#; it could totally not be there and everyone would be happy. It is there on the C++ type and needs to be, but it is private and marked CS_IGNORE which in previous versions meant it would not be emitted.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

I still believe there is a bug here. The generated class (ClassNotWanted in example above) actually lives in the public namespace of the generated file. As you can see in my example it is not actually even used within the generated wrapping class - mField is an IntPtr, In my Cpp header that is parsed this type is not exposed/included anywhere, it is forward declared and private - following the Impl pattern for C++. Private (pointer) types should not be exposed to bindings for any reason imho - besides for struct consistency.

If you guys don’t want to fix this then please point me in the right direction so I can make this fix in my own fork if necessary, which would be too bad.