From aecd3b69aa70678b83c119ad13e68657b61a7a6c Mon Sep 17 00:00:00 2001 From: triton Date: Thu, 15 Aug 2013 23:42:52 +0100 Subject: [PATCH] Fixed base constructor calls in the CLI backend to cast to the type of the base types as that can fix some ambiguous calls to overloaded constructors. --- .../Generators/CLI/CLISourcesTemplate.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index a14d7fa1..d9b61e93 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -478,7 +478,7 @@ namespace CppSharp.Generators.CLI var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName); WriteLine("{0} native)", isIntPtr ? "System::IntPtr" : nativeType); - var hasBase = GenerateClassConstructorBase(@class); + var hasBase = GenerateClassConstructorBase(@class, isIntPtr); WriteStartBraceIndent(); @@ -542,25 +542,34 @@ namespace CppSharp.Generators.CLI } } - private bool GenerateClassConstructorBase(Class @class, Method method = null) + private bool GenerateClassConstructorBase(Class @class, bool isIntPtr, Method method = null) { var hasBase = @class.HasBase && !@class.Bases[0].Class.Ignore; + if (!hasBase) + return false; - if (hasBase && !@class.IsValueType) + if (!@class.IsValueType) { PushIndent(); - Write(": {0}(", QualifiedIdentifier(@class.Bases[0].Class)); - if (method != null) - Write("nullptr"); - else - Write("native"); + var baseClass = @class.Bases[0].Class; + Write(": {0}(", QualifiedIdentifier(baseClass)); + + // We cast the value to the base clas type since otherwise there + // could be ambiguous call to overloaded constructors. + if (!isIntPtr) + { + var cppTypePrinter = new CppTypePrinter(Driver.TypeDatabase); + var nativeTypeName = baseClass.Visit(cppTypePrinter); + Write("({0}*)", nativeTypeName); + } + + WriteLine("{0})", method != null ? "nullptr" : "native"); - WriteLine(")"); PopIndent(); } - return hasBase; + return true; } public void GenerateMethod(Method method, Class @class)