From 5f2de79f114ce8f431ea2bb8570f1d4815530fc0 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Thu, 2 May 2019 00:07:13 +0300 Subject: [PATCH] Generate valid C# when std::string is only used for public fields Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/TrimSpecializationsPass.cs | 4 +--- tests/VTables/VTables.Tests.cs | 11 +++++++++++ tests/VTables/VTables.h | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Generator/Passes/TrimSpecializationsPass.cs b/src/Generator/Passes/TrimSpecializationsPass.cs index b9024654d0..e27b7a8cc4 100644 --- a/src/Generator/Passes/TrimSpecializationsPass.cs +++ b/src/Generator/Passes/TrimSpecializationsPass.cs @@ -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); diff --git a/tests/VTables/VTables.Tests.cs b/tests/VTables/VTables.Tests.cs index 9d321116a6..9395f8d8f6 100644 --- a/tests/VTables/VTables.Tests.cs +++ b/tests/VTables/VTables.Tests.cs @@ -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")); + } + } } diff --git a/tests/VTables/VTables.h b/tests/VTables/VTables.h index 06f35b5f4a..f223d427b3 100644 --- a/tests/VTables/VTables.h +++ b/tests/VTables/VTables.h @@ -1,4 +1,5 @@ #include "../Tests.h" +#include class DLL_API Foo { @@ -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);