Skip to content

Commit

Permalink
Generate valid C# when std::string is only used for public fields
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed May 1, 2019
1 parent 39d5828 commit 5f2de79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Generator/Passes/TrimSpecializationsPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public override bool VisitFieldDecl(Field field)
return true;
}

TypeMap typeMap;
if (!Context.TypeMaps.FindTypeMap(field.Type, out typeMap) &&
!ASTUtils.CheckTypeForSpecialization(field.Type,
if (!ASTUtils.CheckTypeForSpecialization(field.Type,
field, AddSpecialization, Context.TypeMaps))
CheckForInternalSpecialization(field, field.Type);

Expand Down
11 changes: 11 additions & 0 deletions tests/VTables/VTables.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,15 @@ public void TestVirtualFuntionRetVal()
var retBase = new ManagedDerivedClassVirtualRetBase();
TestVirtualFunction(retBase, 10);
}

[Test]
public void TestStdStringInField()
{
using (var foo = new Foo())
{
Assert.That(foo.S, Is.Empty);
foo.S = "test";
Assert.That(foo.S, Is.EqualTo("test"));
}
}
}
2 changes: 2 additions & 0 deletions tests/VTables/VTables.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../Tests.h"
#include <string>

class DLL_API Foo
{
Expand All @@ -15,6 +16,7 @@ class DLL_API Foo
virtual int append();
virtual int append(int a);
int callVirtualWithParameter(int a);
std::string s;
};

DLL_API int FooCallFoo(Foo* foo);
Expand Down

0 comments on commit 5f2de79

Please sign in to comment.