diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 2906d07158..ef75963588 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -186,8 +186,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals) if (Context.Function != null && Context.Function.OperatorKind == CXXOperatorKind.Subscript) { - if (type.IsPrimitiveType(primitive) || - new QualifiedType(pointer, quals).IsConstRefToPrimitive()) + if (type.IsPrimitiveType(primitive)) { Context.Return.Write("*"); } @@ -199,6 +198,9 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals) } } + if (new QualifiedType(pointer, quals).IsConstRefToPrimitive()) + Context.Return.Write("*"); + Context.Return.Write(Context.ReturnVarName); return true; } diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 14744a22f6..5c80378b89 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -54,6 +54,7 @@ public void TestUncompilableCode() hasSecondaryBaseWithAbstractWithDefaultArg.Abstract(); hasSecondaryBaseWithAbstractWithDefaultArg.AbstractWithNoDefaultArg(foo); } + Assert.That(foo.ReturnConstRef(), Is.EqualTo(5)); } using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType()) hasOverride.CauseRenamingError(); diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 586e7eceb2..0be74837c3 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -60,6 +60,11 @@ void Foo::set_width(int value) { } +const int& Foo::returnConstRef() +{ + return rename; +} + const int Foo::rename; int Foo::makeFunctionCall() diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index aa8755adc3..676e6dbdd3 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -26,6 +26,7 @@ class DLL_API Foo void takesStdVector(const std::vector& vector); int width(); void set_width(int value); + const int& returnConstRef(); static const int rename = 5; static int makeFunctionCall();