From 2894999696f761e2b6d3ce8114618f1b1c822c17 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 17 Oct 2014 16:52:20 +0300 Subject: [PATCH] Fixed the generation of constructor overloads synthetised because of default arguments. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpTextTemplate.cs | 29 ++++++++++++++----- tests/CSharpTemp/CSharpTemp.cpp | 4 +++ tests/CSharpTemp/CSharpTemp.h | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 322f59ba..22263149 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2072,6 +2072,16 @@ namespace CppSharp.Generators.CSharp Write(")"); + if (method.SynthKind == FunctionSynthKind.DefaultValueOverload && method.IsConstructor && + !(Driver.Options.GenerateAbstractImpls && method.IsPure)) + { + Write(" : this({0})", + string.Join(", ", + method.Parameters.Where( + p => p.Kind == ParameterKind.Regular).Select( + p => p.GenerationKind == GenerationKind.None ? p.DefaultArgument.String : p.Name))); + } + if (Driver.Options.GenerateAbstractImpls && method.IsPure) { Write(";"); @@ -2090,14 +2100,17 @@ namespace CppSharp.Generators.CSharp if (method.SynthKind == FunctionSynthKind.DefaultValueOverload) { - Type type = method.OriginalReturnType.Type; - WriteLine("{0}{1}({2});", - type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : "return ", - method.Name, - string.Join(", ", - method.Parameters.Where( - p => p.Kind == ParameterKind.Regular).Select( - p => p.GenerationKind == GenerationKind.None ? p.DefaultArgument.String : p.Name))); + if (!method.IsConstructor) + { + Type type = method.OriginalReturnType.Type; + this.WriteLine("{0}{1}({2});", + type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : "return ", + method.Name, + string.Join(", ", + method.Parameters.Where( + p => p.Kind == ParameterKind.Regular).Select( + p => p.GenerationKind == GenerationKind.None ? p.DefaultArgument.String : p.Name))); + } goto SkipImpl; } diff --git a/tests/CSharpTemp/CSharpTemp.cpp b/tests/CSharpTemp/CSharpTemp.cpp index bde8ffcc..52ab08c2 100644 --- a/tests/CSharpTemp/CSharpTemp.cpp +++ b/tests/CSharpTemp/CSharpTemp.cpp @@ -237,6 +237,10 @@ QGenericArgument::QGenericArgument(const char *name) _name = name; } +MethodsWithDefaultValues::MethodsWithDefaultValues(Foo foo) +{ +} + void MethodsWithDefaultValues::defaultPointer(Foo *ptr) { } diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index 7a24bc37..28b931ea 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -216,6 +216,7 @@ private: class DLL_API MethodsWithDefaultValues { public: + MethodsWithDefaultValues(Foo foo = Foo()); void defaultPointer(Foo* ptr = 0); void defaultValueType(ValueType bar = ValueType()); void defaultChar(char c = 'a');