Skip to content

Commit 0c87a77

Browse files
committed
Fixed the generated C# for constant references to primitives.
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
1 parent 2fe8d21 commit 0c87a77

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

src/Generator/Generators/CSharp/CSharpMarshal.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
186186
if (Context.Function != null &&
187187
Context.Function.OperatorKind == CXXOperatorKind.Subscript)
188188
{
189-
if (type.IsPrimitiveType(primitive) ||
190-
new QualifiedType(pointer, quals).IsConstRefToPrimitive())
189+
if (type.IsPrimitiveType(primitive))
191190
{
192191
Context.Return.Write("*");
193192
}
@@ -199,6 +198,9 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
199198
}
200199
}
201200

201+
if (new QualifiedType(pointer, quals).IsConstRefToPrimitive())
202+
Context.Return.Write("*");
203+
202204
Context.Return.Write(Context.ReturnVarName);
203205
return true;
204206
}

tests/CSharp/CSharp.Tests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void TestUncompilableCode()
5454
hasSecondaryBaseWithAbstractWithDefaultArg.Abstract();
5555
hasSecondaryBaseWithAbstractWithDefaultArg.AbstractWithNoDefaultArg(foo);
5656
}
57+
Assert.That(foo.ReturnConstRef(), Is.EqualTo(5));
5758
}
5859
using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
5960
hasOverride.CauseRenamingError();

tests/CSharp/CSharp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ void Foo::set_width(int value)
6060
{
6161
}
6262

63+
const int& Foo::returnConstRef()
64+
{
65+
return rename;
66+
}
67+
6368
const int Foo::rename;
6469

6570
int Foo::makeFunctionCall()

tests/CSharp/CSharp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class DLL_API Foo
2626
void takesStdVector(const std::vector<int>& vector);
2727
int width();
2828
void set_width(int value);
29+
const int& returnConstRef();
2930

3031
static const int rename = 5;
3132
static int makeFunctionCall();

0 commit comments

Comments
 (0)