Skip to content

Commit 51d422a

Browse files
committed
Fix invalid C++/CLI generated for anonymous types
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent c358d6b commit 51d422a

File tree

3 files changed

+74
-66
lines changed

3 files changed

+74
-66
lines changed

src/Generator/Passes/CleanInvalidDeclNamesPass.cs

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using CppSharp.AST;
55
using CppSharp.Generators.CLI;
66
using CppSharp.Generators.CSharp;
7+
using CppSharp.Generators;
78

89
namespace CppSharp.Passes
910
{
@@ -14,6 +15,13 @@ public override bool VisitClassDecl(Class @class)
1415
if (!base.VisitClassDecl(@class))
1516
return false;
1617

18+
if (Options.GeneratorKind == GeneratorKind.CLI &&
19+
string.IsNullOrEmpty(@class.OriginalName))
20+
{
21+
@class.ExplicitlyIgnore();
22+
return true;
23+
}
24+
1725
if (@class.Layout != null)
1826
{
1927
int order = 0;

tests/CSharp/CSharp.h

-66
Original file line numberDiff line numberDiff line change
@@ -1307,72 +1307,6 @@ DLL_API void va_listFunction(va_list v);
13071307
DLL_API char* returnCharPointer();
13081308
DLL_API const char* takeConstCharStarRef(const char*& c);
13091309

1310-
union
1311-
{
1312-
struct
1313-
{
1314-
struct
1315-
{
1316-
long Capabilities;
1317-
} Server;
1318-
struct
1319-
{
1320-
long Capabilities;
1321-
} Share;
1322-
} Smb2;
1323-
} ProtocolSpecific;
1324-
1325-
struct DLL_API TestNestedTypes
1326-
{
1327-
public:
1328-
struct
1329-
{
1330-
struct
1331-
{
1332-
};
1333-
};
1334-
struct
1335-
{
1336-
struct
1337-
{
1338-
};
1339-
};
1340-
struct
1341-
{
1342-
struct
1343-
{
1344-
};
1345-
};
1346-
struct
1347-
{
1348-
struct
1349-
{
1350-
};
1351-
};
1352-
1353-
union as_types
1354-
{
1355-
int as_int;
1356-
struct uchars
1357-
{
1358-
unsigned char blue, green, red, alpha;
1359-
} as_uchar;
1360-
};
1361-
};
1362-
1363-
class TestNamingAnonymousTypesInUnion
1364-
{
1365-
public:
1366-
union {
1367-
struct {
1368-
} argb;
1369-
struct {
1370-
} ahsv;
1371-
struct {
1372-
} acmyk;
1373-
} ct;
1374-
};
1375-
13761310
struct {
13771311
struct {
13781312
struct {

tests/Common/Common.h

+66
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,44 @@ class PureDtor
822822

823823
DLL_API void va_listFunction(va_list v);
824824

825+
struct DLL_API TestNestedTypes
826+
{
827+
public:
828+
struct
829+
{
830+
struct
831+
{
832+
};
833+
};
834+
struct
835+
{
836+
struct
837+
{
838+
};
839+
};
840+
struct
841+
{
842+
struct
843+
{
844+
};
845+
};
846+
struct
847+
{
848+
struct
849+
{
850+
};
851+
};
852+
853+
union as_types
854+
{
855+
int as_int;
856+
struct uchars
857+
{
858+
unsigned char blue, green, red, alpha;
859+
} as_uchar;
860+
};
861+
};
862+
825863
class DLL_API HasStdString
826864
{
827865
public:
@@ -883,6 +921,19 @@ class DLL_API DifferentConstOverloads
883921

884922
DLL_API bool operator ==(const DifferentConstOverloads& d, const char* s);
885923

924+
class TestNamingAnonymousTypesInUnion
925+
{
926+
public:
927+
union {
928+
struct {
929+
} argb;
930+
struct {
931+
} ahsv;
932+
struct {
933+
} acmyk;
934+
} ct;
935+
};
936+
886937
class DLL_API RefTypeClassPassTry { };
887938

888939
void DLL_API funcTryRefTypePtrOut(CS_OUT RefTypeClassPassTry* classTry);
@@ -1380,6 +1431,21 @@ inline namespace InlineNamespace
13801431
}
13811432
}
13821433

1434+
union
1435+
{
1436+
struct
1437+
{
1438+
struct
1439+
{
1440+
long Capabilities;
1441+
} Server;
1442+
struct
1443+
{
1444+
long Capabilities;
1445+
} Share;
1446+
} Smb2;
1447+
} ProtocolSpecific;
1448+
13831449

13841450
template<class _Other>
13851451
using UsingTemplatePtr = _Other *;

0 commit comments

Comments
 (0)