diff --git a/src/Generator/Options.cs b/src/Generator/Options.cs index 766fd4de..1852e536 100644 --- a/src/Generator/Options.cs +++ b/src/Generator/Options.cs @@ -133,7 +133,7 @@ namespace CppSharp public List NoGenIncludeDirs; /// - /// Wether the generated C# code should be automatically compiled. + /// Whether the generated C# code should be automatically compiled. /// public bool CompileCode; diff --git a/src/Generator/Passes/CleanInvalidDeclNamesPass.cs b/src/Generator/Passes/CleanInvalidDeclNamesPass.cs index 9eb352a1..19a4c172 100644 --- a/src/Generator/Passes/CleanInvalidDeclNamesPass.cs +++ b/src/Generator/Passes/CleanInvalidDeclNamesPass.cs @@ -74,6 +74,17 @@ namespace CppSharp.Passes var ret = base.VisitClassDecl(@class); this.uniqueName = currentUniqueName; + if (@class.Namespace.Classes.Any(d => d != @class && d.Name == @class.Name)) + { + StringBuilder str = new StringBuilder(); + str.Append(@class.Name); + do + { + str.Append('_'); + } while (@class.Classes.Any(d => d != @class && d.Name == str.ToString())); + @class.Name = str.ToString(); + } + return ret; } diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index de990011..69d34e92 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -647,24 +647,24 @@ public: { }; }; - struct - { - struct - { - }; - }; - struct - { - struct - { - }; - }; - struct - { - struct - { - }; - }; + struct + { + struct + { + }; + }; + struct + { + struct + { + }; + }; + struct + { + struct + { + }; + }; union as_types { @@ -728,3 +728,16 @@ public: bool operator ==(const DifferentConstOverloads& other); bool operator ==(int number) const; }; + +class TestNamingAnonymousTypesInUnion +{ +public: + union { + struct { + } argb; + struct { + } ahsv; + struct { + } acmyk; + } ct; +};