Skip to content

Commit 764806e

Browse files
committed
Fixed the generated C# for templates derived from regular dynamic classes.
Fixes #967. Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent cd5b57a commit 764806e

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ public void GenerateVTable(Class @class)
13791379

13801380
// Generate a delegate type for each method.
13811381
foreach (var method in wrappedEntries.Select(e => e.Method))
1382-
GenerateVTableMethodDelegates(containingClass, containingClass.IsDependent ?
1382+
GenerateVTableMethodDelegates(containingClass, method.Namespace.IsDependent ?
13831383
(Method) method.InstantiatedFrom : method);
13841384

13851385
WriteLine("private static void*[] __ManagedVTables;");

tests/CSharp/CSharp.Tests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,15 @@ public void TestPropertyReturnsTemplateWithRenamedTypeArg()
841841
}
842842
}
843843

844+
[Test]
845+
public void TestTemplateDerivedFromRegularDynamic()
846+
{
847+
using (var templateDerivedFromRegularDynamic = new TemplateDerivedFromRegularDynamic<RegularDynamic>())
848+
{
849+
templateDerivedFromRegularDynamic.VirtualFunction();
850+
}
851+
}
852+
844853
[Test]
845854
public void TestAbstractImplementatonsInPrimaryAndSecondaryBases()
846855
{

tests/CSharp/CSharpTemplates.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,24 @@ void TemplateSpecializer::completeSpecializationInParameter(TwoTemplateArgs<int
108108
{
109109
}
110110

111+
RegularDynamic::RegularDynamic()
112+
{
113+
}
114+
115+
RegularDynamic::~RegularDynamic()
116+
{
117+
}
118+
119+
void RegularDynamic::virtualFunction()
120+
{
121+
}
122+
111123
void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool> _2,
112124
IndependentFields<T1> _3, IndependentFields<std::string> _4,
113-
VirtualTemplate<int> _5, VirtualTemplate<bool> _6,
114-
HasDefaultTemplateArgument<int, int> _7, std::string s)
125+
DependentValueFields<int> _5,
126+
VirtualTemplate<int> _6, VirtualTemplate<bool> _7,
127+
HasDefaultTemplateArgument<int, int> _8, DerivedChangesTypeName<T1> _9,
128+
TemplateWithIndexer<int> _10, TemplateWithIndexer<T1> _11,
129+
TemplateWithIndexer<T2*> _12, TemplateDerivedFromRegularDynamic<RegularDynamic> _13, std::string s)
115130
{
116131
}

tests/CSharp/CSharpTemplates.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,40 @@ struct MapResultType<InputSequence<T>, MapFunctor>
449449
typedef InputSequence<typename LazyResultType<MapFunctor>::Type> ResultType;
450450
};
451451

452+
class RegularDynamic
453+
{
454+
public:
455+
RegularDynamic();
456+
~RegularDynamic();
457+
virtual void virtualFunction();
458+
};
459+
460+
template<typename T>
461+
class TemplateDerivedFromRegularDynamic : public RegularDynamic
462+
{
463+
public:
464+
TemplateDerivedFromRegularDynamic();
465+
~TemplateDerivedFromRegularDynamic();
466+
};
467+
468+
template<typename T>
469+
TemplateDerivedFromRegularDynamic<T>::TemplateDerivedFromRegularDynamic()
470+
{
471+
}
472+
473+
template<typename T>
474+
TemplateDerivedFromRegularDynamic<T>::~TemplateDerivedFromRegularDynamic()
475+
{
476+
}
477+
452478
// we optimise specialisations so that only actually used ones are wrapped
453479
void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool> _2,
454480
IndependentFields<T1> _3, IndependentFields<std::string> _4,
455481
DependentValueFields<int> _5,
456482
VirtualTemplate<int> _6, VirtualTemplate<bool> _7,
457483
HasDefaultTemplateArgument<int, int> _8, DerivedChangesTypeName<T1> _9,
458484
TemplateWithIndexer<int> _10, TemplateWithIndexer<T1> _11,
459-
TemplateWithIndexer<T2*> _12, std::string s);
485+
TemplateWithIndexer<T2*> _12, TemplateDerivedFromRegularDynamic<RegularDynamic> _13, std::string s);
460486

461487
// force the symbols for the template instantiations because we do not have the auto-compilation for the generated C++ source
462488
template class DLL_API IndependentFields<int>;
@@ -472,6 +498,7 @@ template class DLL_API DerivedChangesTypeName<T1>;
472498
template class DLL_API TemplateWithIndexer<int>;
473499
template class DLL_API TemplateWithIndexer<T1>;
474500
template class DLL_API TemplateWithIndexer<T2*>;
501+
template class DLL_API TemplateDerivedFromRegularDynamic<RegularDynamic>;
475502

476503
class TestForwardedClassInAnotherUnit;
477504

0 commit comments

Comments
 (0)