Browse Source

Fixed the code generation for indexers returning a void pointer (#901)

pull/902/head
Mohit Mohta 8 years ago committed by Dimitar Dobrev
parent
commit
48c6094f52
  1. 3
      src/Generator/Passes/CheckOperatorsOverloads.cs
  2. 10
      tests/CSharp/CSharp.Tests.cs
  3. 8
      tests/CSharp/CSharp.h

3
src/Generator/Passes/CheckOperatorsOverloads.cs

@ -101,7 +101,8 @@ namespace CppSharp.Passes
}; };
var returnType = @operator.Type; var returnType = @operator.Type;
if (returnType.IsAddress()) if (returnType.IsAddress() &&
!returnType.GetQualifiedPointee().Type.Desugar().IsPrimitiveType(PrimitiveType.Void))
{ {
var pointer = (PointerType) returnType; var pointer = (PointerType) returnType;
var qualifiedPointee = pointer.QualifiedPointee; var qualifiedPointee = pointer.QualifiedPointee;

10
tests/CSharp/CSharp.Tests.cs

@ -844,4 +844,14 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.That(indexproperty[&a], Is.EqualTo(2)); Assert.That(indexproperty[&a], Is.EqualTo(2));
} }
} }
[Test]
public void TestVoidPtrReturningIndexer()
{
using (var indexproperty = new TestIndexedProperties())
{
uint n = 21;
Assert.That(*((int*) indexproperty[n]), Is.EqualTo(21));
}
}
} }

8
tests/CSharp/CSharp.h

@ -1198,7 +1198,9 @@ struct HasComplexArray
class DLL_API TestIndexedProperties class DLL_API TestIndexedProperties
{ {
public: public:
mutable int field;
int operator[](const int& key); int operator[](const int& key);
void* operator[](size_t n) const;
}; };
int TestIndexedProperties::operator[](const int& key) int TestIndexedProperties::operator[](const int& key)
@ -1206,6 +1208,12 @@ int TestIndexedProperties::operator[](const int& key)
return key; return key;
} }
void* TestIndexedProperties::operator[](size_t n) const
{
field = n;
return &field;
}
extern const ComplexArrayElement ArrayOfVariableSize[]; extern const ComplexArrayElement ArrayOfVariableSize[];
void useStdStringJustAsParameter(std::string s); void useStdStringJustAsParameter(std::string s);

Loading…
Cancel
Save