From c1832008158083f0eb285e59fe30fe53fca0e6e3 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 20 Sep 2015 22:50:30 +0300 Subject: [PATCH] Fixed a regression causing incorrect sizes of types derived from template instantiations. Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/CheckAbiParameters.cs | 3 ++- tests/CSharp/CSharp.Tests.cs | 6 ++++++ tests/CSharp/CSharp.cpp | 9 +++++++++ tests/CSharp/CSharp.h | 20 +++++++++++++++++--- tests/Common/Common.h | 5 ++++- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/Generator/Passes/CheckAbiParameters.cs b/src/Generator/Passes/CheckAbiParameters.cs index 8d9875d6..79cdca6b 100644 --- a/src/Generator/Passes/CheckAbiParameters.cs +++ b/src/Generator/Passes/CheckAbiParameters.cs @@ -87,7 +87,8 @@ namespace CppSharp.Passes { if (@class.Fields.Count > 0 || @class.IsDynamic) return true; - return @class.HasBaseClass && @class.Bases.Any(@base => @base.IsClass && HasFieldsOrVirtuals(@base.Class)); + return @class.Bases.Any(@base => @base.IsClass && @base.Class != @class && + HasFieldsOrVirtuals(@base.Class)); } } } diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 82a38b2d..66c1bd87 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -437,4 +437,10 @@ public class CSharpTests : GeneratorTestFixture Assert.That(foo.A, Is.EqualTo(15)); } } + + [Test] + public unsafe void TestSizeOfDerivesFromTemplateInstantiation() + { + Assert.That(sizeof(DerivesFromTemplateInstantiation.Internal), Is.EqualTo(sizeof(int))); + } } diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 6fd703dc..0b5d7484 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -789,3 +789,12 @@ void TestOutTypeInterfaces::funcTryInterfaceTypePtrOut(CS_OUT TestParamToInterfa void TestOutTypeInterfaces::funcTryInterfaceTypeOut(CS_OUT TestParamToInterfacePassBaseTwo classTry) { } + +template +TemplateWithDependentField::TemplateWithDependentField() +{ +} + +DerivesFromTemplateInstantiation::DerivesFromTemplateInstantiation() +{ +} diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 64187bf8..a570c897 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -708,12 +708,26 @@ public: class DLL_API TestVariableWithFixedArrayType { public: - static Foo variableWithFixedArrayType[2]; + static Foo variableWithFixedArrayType[2]; }; class DLL_API TestOutTypeInterfaces { public: - void funcTryInterfaceTypePtrOut(CS_OUT TestParamToInterfacePassBaseTwo* classTry); - void funcTryInterfaceTypeOut(CS_OUT TestParamToInterfacePassBaseTwo classTry); + void funcTryInterfaceTypePtrOut(CS_OUT TestParamToInterfacePassBaseTwo* classTry); + void funcTryInterfaceTypeOut(CS_OUT TestParamToInterfacePassBaseTwo classTry); +}; + +template +class TemplateWithDependentField +{ +public: + TemplateWithDependentField(); + T t; +}; + +class DerivesFromTemplateInstantiation : public TemplateWithDependentField +{ +public: + DerivesFromTemplateInstantiation(); }; diff --git a/tests/Common/Common.h b/tests/Common/Common.h index afd2db8a..e9215fb3 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -842,4 +842,7 @@ namespace boost { template struct is_member_pointer_cv { static const bool value = false; }; template struct is_member_pointer_cv { static const bool value = true; }; -} \ No newline at end of file +} + +template +struct build_index_impl : build_index_impl {};