* Fix anonymous member name colliding with enclosing type name
@ -146,7 +146,14 @@ namespace CppSharp.Passes
{
var anonymousDecls = decls.Where(p => string.IsNullOrEmpty(p.Name)).ToList();
for (int i = 0; i < anonymousDecls.Count; i++)
anonymousDecls[i].Name = $"_{i}";
var anonymousDecl = anonymousDecls[i];
if (anonymousDecl.Namespace != null && anonymousDecl.Namespace.Name == anonymousDecl.Name)
anonymousDecl.Name = $"__{i}";
else
anonymousDecl.Name = $"_{i}";
}
@ -1429,4 +1429,10 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.That(CSharp.CSharp.TakeTypemapTypedefParam(false), Is.False);
[Test]
public void TestAnonymousMemberNameCollision()
StringAssert.EndsWith(nameof(CSharp.TestAnonymousMemberNameCollision._0.__0), "__0");
@ -6,6 +6,7 @@
#include <limits>
#include <string>
#include "AnotherUnit.h"
#include "ExcludedUnit.hpp"
#include "CSharpTemplates.h"
class DLL_API Foo
@ -1401,3 +1402,6 @@ struct {
typedef int boolean_t;
DLL_API boolean_t takeTypemapTypedefParam(boolean_t b);
class DLL_API TestAnonymousMemberNameCollision : public ClassUsingUnion {
};
@ -0,0 +1,11 @@
#pragma once
class ClassUsingUnion {
public:
union {
float arr[2];
struct {
float a, b;