Browse Source

Generate valid C# for constructors taking const&

Fixes https://github.com/mono/CppSharp/issues/1119.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
const-wchar_t
Dimitar Dobrev 5 years ago
parent
commit
b7fa720ee1
  1. 12
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 3
      tests/Common/Common.Tests.cs
  3. 5
      tests/Common/Common.cpp
  4. 1
      tests/Common/Common.h

12
src/Generator/Generators/CSharp/CSharpSources.cs

@ -2640,10 +2640,11 @@ namespace CppSharp.Generators.CSharp @@ -2640,10 +2640,11 @@ namespace CppSharp.Generators.CSharp
{
if (method.SynthKind == FunctionSynthKind.ComplementOperator)
{
Parameter parameter = method.Parameters[0];
if (method.Kind == CXXMethodKind.Conversion)
{
// To avoid ambiguity when having the multiple inheritance pass enabled
var paramType = method.Parameters[0].Type.SkipPointerRefs().Desugar();
var paramType = parameter.Type.SkipPointerRefs().Desugar();
paramType = (paramType.GetPointee() ?? paramType).Desugar();
Class paramClass;
Class @interface = null;
@ -2651,9 +2652,10 @@ namespace CppSharp.Generators.CSharp @@ -2651,9 +2652,10 @@ namespace CppSharp.Generators.CSharp
@interface = paramClass.GetInterface();
var paramName = string.Format("{0}{1}",
method.Parameters[0].Type.IsPrimitiveTypeConvertibleToRef() ?
!parameter.QualifiedType.IsConstRefToPrimitive() &&
parameter.Type.IsPrimitiveTypeConvertibleToRef() ?
"ref *" : string.Empty,
method.Parameters[0].Name);
parameter.Name);
var printedType = method.ConversionType.Visit(TypePrinter);
if (@interface != null)
{
@ -2667,8 +2669,8 @@ namespace CppSharp.Generators.CSharp @@ -2667,8 +2669,8 @@ namespace CppSharp.Generators.CSharp
{
var @operator = Operators.GetOperatorOverloadPair(method.OperatorKind);
WriteLine("return !({0} {1} {2});", method.Parameters[0].Name,
@operator, method.Parameters[1].Name);
WriteLine("return !({0} {1} {2});", parameter.Name,
@operator, method.Parameters[1].Name);
}
return;
}

3
tests/Common/Common.Tests.cs

@ -20,8 +20,9 @@ public class CommonTests : GeneratorTestFixture @@ -20,8 +20,9 @@ public class CommonTests : GeneratorTestFixture
}
Foo.NestedAbstract a;
Foo.RenamedEmptyEnum.EmptyEnum1.GetHashCode();
using (var foo = new Foo())
using (var foo = new Foo(5))
{
Assert.That(foo.B, Is.EqualTo(5));
Bar bar = foo;
Assert.IsTrue(Bar.Item.Item1 == bar);

5
tests/Common/Common.cpp

@ -54,6 +54,11 @@ Foo::Foo(Private p) @@ -54,6 +54,11 @@ Foo::Foo(Private p)
{
}
Foo::Foo(const float& f)
{
B = f;
}
const char* Foo::GetANSI()
{
return "ANSI";

1
tests/Common/Common.h

@ -85,6 +85,7 @@ public: @@ -85,6 +85,7 @@ public:
Foo();
Foo(Private p);
Foo(const float& f);
int A;
float B;
IgnoredType ignoredType;

Loading…
Cancel
Save