Skip to content

Commit 3409498

Browse files
committed
Fix template type checking in CovariantTypeComparer.
Fixes #1266.
1 parent 36896f5 commit 3409498

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Generator/Passes/CheckVirtualOverrideReturnCovariance.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ public override bool VisitTagType(TagType tag, TypeQualifiers quals)
7171
return tag.Declaration.Visit(this);
7272
}
7373

74+
public override bool VisitTemplateSpecializationType(TemplateSpecializationType template,
75+
TypeQualifiers quals)
76+
{
77+
if (!currentType.Qualifiers.Equals(quals))
78+
return false;
79+
80+
var currentTemplateType = currentType.Type as TemplateSpecializationType;
81+
if (currentTemplateType == null)
82+
return false;
83+
84+
return currentTemplateType.Equals(template);
85+
}
86+
7487
static bool IsDescendentOf(Class @class, Class parent)
7588
{
7689
return @class == parent ||

tests/Common/Common.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#endif
77
#include <string>
88
#include <vector>
9+
#include <memory>
910

1011
class DLL_API TestPacking
1112
{
@@ -1522,3 +1523,17 @@ struct DLL_API StructWithCopyCtor
15221523
};
15231524

15241525
uint16_t DLL_API TestStructWithCopyCtorByValue(StructWithCopyCtor s);
1526+
1527+
// Issue: https://github.com/mono/CppSharp/issues/1266
1528+
struct BaseCovariant;
1529+
typedef std::unique_ptr<BaseCovariant> PtrCovariant;
1530+
1531+
struct BaseCovariant {
1532+
virtual PtrCovariant clone() const = 0;
1533+
};
1534+
1535+
struct DerivedCovariant: public BaseCovariant {
1536+
std::unique_ptr<BaseCovariant> clone() const override {
1537+
return PtrCovariant(new DerivedCovariant());
1538+
}
1539+
};

0 commit comments

Comments
 (0)