From b15ca8827e4b15d4abd682f9f1036dbd64bf487b Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Tue, 10 Dec 2019 13:36:32 +0000 Subject: [PATCH] Avoid generating abstract implementations for template classes. Fixes https://github.com/mono/CppSharp/issues/1268. --- .../Passes/GenerateAbstractImplementationsPass.cs | 6 +++--- tests/Common/Common.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Generator/Passes/GenerateAbstractImplementationsPass.cs b/src/Generator/Passes/GenerateAbstractImplementationsPass.cs index 4953047d..6ae567b3 100644 --- a/src/Generator/Passes/GenerateAbstractImplementationsPass.cs +++ b/src/Generator/Passes/GenerateAbstractImplementationsPass.cs @@ -7,8 +7,8 @@ namespace CppSharp.Passes /// /// This pass generates internal classes that implement abstract classes. /// When the return type of a function is abstract, these internal - /// classes provide since the real type cannot be resolved while binding - /// an allocatable class that supports proper polymorphism. + /// classes are used instead since the real type cannot be resolved + /// while binding an allocatable class that supports proper polymorphism. /// public class GenerateAbstractImplementationsPass : TranslationUnitPass { @@ -57,7 +57,7 @@ namespace CppSharp.Passes if (@class.CompleteDeclaration != null) return VisitClassDecl(@class.CompleteDeclaration as Class); - if (@class.IsAbstract) + if (@class.IsAbstract && !@class.IsTemplate) { foreach (var ctor in from ctor in @class.Constructors where ctor.Access == AccessSpecifier.Public diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 8cf28fab..bee5e26d 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -1537,3 +1537,15 @@ struct DerivedCovariant: public BaseCovariant { return PtrCovariant(new DerivedCovariant()); } }; + +// Issue: https://github.com/mono/CppSharp/issues/1268 +template +class AbstractClassTemplate { + public: + virtual void func() = 0; +}; + +class DerivedClass: public AbstractClassTemplate { + public: + void func() override {} +};