Skip to content

NullReferenceException in CovariantTypeComparer.IsDescendentOf with typedef #1266

@lostmsu

Description

@lostmsu
Brief Description

The code below produces NullReferenceException in CovariantTypeComparer.IsDescendentOf when processing Derived.clone:

#include <memory>

struct Base;
typedef std::unique_ptr<Base> Ptr;

struct Base {
  virtual Ptr clone() const = 0;
};

struct Derived: public Base {
  std::unique_ptr<Base> clone() const override {
    return Ptr(new Derived());
  }
};

OS: Windows (IMHO, problem is likely OS-independent)

Used headers

<memory>

Used settings
var options = driver.Options;
options.GeneratorKind = GeneratorKind.CSharp;
options.GenerateClassTemplates = true;
options.GenerateFunctionTemplates = true;

driver.ParserOptions.LanguageVersion = LanguageVersion.CPP14;
driver.ParserOptions.ForceClangToolchainLookup = false;
driver.ParserOptions.EnableRTTI = true;
driver.ParserOptions.AddArguments("-fexceptions");
driver.ParserOptions.AddArguments("-fcxx-exceptions");

module.Defines.Add("WIN32");
module.Defines.Add("_WINDOWS");

Target: Clang

Stack trace or incompilable generated code
<details>
  <summary>Stack trace</summary>
CppSharp.Generator.dll!CppSharp.Passes.CovariantTypeComparer.IsDescendentOf(CppSharp.AST.Class class, CppSharp.AST.Class parent) Line 76	C#
 	CppSharp.Generator.dll!CppSharp.Passes.CovariantTypeComparer.VisitClassDecl(CppSharp.AST.Class class) Line 83	C#
 	CppSharp.AST.dll!CppSharp.AST.AstVisitor.VisitClassTemplateSpecializationDecl(CppSharp.AST.ClassTemplateSpecialization specialization) Line 509	C#
 	CppSharp.AST.dll!CppSharp.AST.ClassTemplateSpecialization.Visit<bool>(CppSharp.AST.IDeclVisitor<bool> visitor) Line 307	C#
 	CppSharp.AST.dll!CppSharp.AST.AstVisitor.VisitTemplateSpecializationType(CppSharp.AST.TemplateSpecializationType template, CppSharp.AST.TypeQualifiers quals) Line 200	C#
 	CppSharp.AST.dll!CppSharp.AST.TemplateSpecializationType.Visit<bool>(CppSharp.AST.ITypeVisitor<bool> visitor, CppSharp.AST.TypeQualifiers quals) Line 702	C#
 	CppSharp.AST.dll!CppSharp.AST.AstVisitor.VisitTypedefNameDecl(CppSharp.AST.TypedefNameDecl typedef) Line 439	C#
 	CppSharp.AST.dll!CppSharp.AST.AstVisitor.VisitTypedefDecl(CppSharp.AST.TypedefDecl typedef) Line 444	C#
 	CppSharp.AST.dll!CppSharp.AST.TypedefDecl.Visit<bool>(CppSharp.AST.IDeclVisitor<bool> visitor) Line 20	C#
 	CppSharp.AST.dll!CppSharp.AST.AstVisitor.VisitTypedefType(CppSharp.AST.TypedefType typedef, CppSharp.AST.TypeQualifiers quals) Line 148	C#
 	CppSharp.AST.dll!CppSharp.AST.TypedefType.Visit<bool>(CppSharp.AST.ITypeVisitor<bool> visitor, CppSharp.AST.TypeQualifiers quals) Line 430	C#
 	CppSharp.AST.dll!CppSharp.AST.QualifiedType.Visit<bool>(CppSharp.AST.ITypeVisitor<bool> visitor) Line 76	C#
 	CppSharp.Generator.dll!CppSharp.Passes.CheckVirtualOverrideReturnCovariance.IsCovariantType(CppSharp.AST.QualifiedType t1, CppSharp.AST.QualifiedType t2) Line 165	C#
 	CppSharp.Generator.dll!CppSharp.Passes.CheckVirtualOverrideReturnCovariance.IsCompatibleOverload(CppSharp.AST.Method m1, CppSharp.AST.Method m2) Line 158	C#
 	CppSharp.Generator.dll!CppSharp.Passes.CheckVirtualOverrideReturnCovariance.GetOverridenBaseMethod.AnonymousMethod__0(CppSharp.AST.Method m) Line 133	C#
 	mscorlib.dll!System.Collections.Generic.List<CppSharp.AST.Method>.Find(System.Predicate<CppSharp.AST.Method> match)	Unknown
 	CppSharp.Generator.dll!CppSharp.Passes.CheckVirtualOverrideReturnCovariance.GetOverridenBaseMethod(CppSharp.AST.Method method) Line 133	C#
 	CppSharp.Generator.dll!CppSharp.Passes.CheckVirtualOverrideReturnCovariance.VisitMethodDecl(CppSharp.AST.Method method) Line 106	C#
 	CppSharp.AST.dll!CppSharp.AST.AstVisitor.VisitClassDecl(CppSharp.AST.Class class) Line 355	C#
 	CppSharp.AST.dll!CppSharp.AST.Class.Visit<bool>(CppSharp.AST.IDeclVisitor<bool> visitor) Line 314	C#
 	CppSharp.AST.dll!CppSharp.AST.AstVisitor.VisitDeclarationContext(CppSharp.AST.DeclarationContext context) Line 570	C#
 	CppSharp.Generator.dll!CppSharp.Passes.TranslationUnitPass.VisitTranslationUnit(CppSharp.AST.TranslationUnit unit) Line 37	C#
 	CppSharp.Generator.dll!CppSharp.Passes.TranslationUnitPass.VisitASTContext(CppSharp.AST.ASTContext context) Line 24	C#
 	CppSharp.Generator.dll!CppSharp.Generators.BindingContext.RunPasses.AnonymousMethod__29_0(CppSharp.Passes.TranslationUnitPass pass) Line 41	C#
 	CppSharp.Generator.dll!CppSharp.PassBuilder<CppSharp.Passes.TranslationUnitPass>.RunPasses(System.Action<CppSharp.Passes.TranslationUnitPass> action) Line 49	C#
 	CppSharp.Generator.dll!CppSharp.Generators.BindingContext.RunPasses() Line 35	C#
 	CppSharp.Generator.dll!CppSharp.Driver.ProcessCode() Line 285	C#
 	CppSharp.Generator.dll!CppSharp.ConsoleDriver.Run(CppSharp.ILibrary library) Line 445	C#
</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions