Browse Source

Fixed a bug causing some functions with pointer parameters to be marked as ambiguous when they aren't.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/696/head
Dimitar Dobrev 9 years ago
parent
commit
1aa85ab9f7
  1. 15
      src/Generator/Passes/CheckAmbiguousFunctions.cs
  2. 5
      tests/Common/Common.Tests.cs
  3. 8
      tests/Common/Common.cpp
  4. 3
      tests/Common/Common.h

15
src/Generator/Passes/CheckAmbiguousFunctions.cs

@ -130,7 +130,7 @@ namespace CppSharp.Passes @@ -130,7 +130,7 @@ namespace CppSharp.Passes
Function function, Function overload)
{
var functionParams = function.Parameters.Where(
p => p.Kind == ParameterKind.Regular && p.Type.IsAddress()).ToList();
p => p.Kind == ParameterKind.Regular).ToList();
// It's difficult to handle this case for more than one parameter
// For example, if we have:
// void f(float&, const int&);
@ -141,14 +141,20 @@ namespace CppSharp.Passes @@ -141,14 +141,20 @@ namespace CppSharp.Passes
if (functionParams.Count != 1)
return false;
var overloadParams = overload.Parameters.Where(
p => p.Kind == ParameterKind.Regular && p.Type.IsAddress()).ToList();
p => p.Kind == ParameterKind.Regular).ToList();
if (overloadParams.Count != 1)
return false;
var parameterFunction = functionParams[0];
var parameterOverload = overloadParams[0];
if (!parameterFunction.Type.GetPointee().Equals(parameterOverload.Type.GetPointee()))
var pointerParamFunction = parameterFunction.Type.Desugar() as PointerType;
var pointerParamOverload = parameterOverload.Type.Desugar() as PointerType;
if (pointerParamFunction == null || pointerParamOverload == null)
return false;
if (!pointerParamFunction.GetPointee().Equals(pointerParamOverload.GetPointee()))
return false;
if (parameterFunction.IsConst && !parameterOverload.IsConst)
@ -163,9 +169,6 @@ namespace CppSharp.Passes @@ -163,9 +169,6 @@ namespace CppSharp.Passes
return true;
}
var pointerParamFunction = (PointerType) parameterFunction.Type;
var pointerParamOverload = (PointerType) parameterOverload.Type;
if (pointerParamFunction.Modifier == PointerType.TypeModifier.RVReference &&
pointerParamOverload.Modifier != PointerType.TypeModifier.RVReference)
{

5
tests/Common/Common.Tests.cs

@ -195,6 +195,11 @@ public class CommonTests : GeneratorTestFixture @@ -195,6 +195,11 @@ public class CommonTests : GeneratorTestFixture
var def = new DefaultParameters();
def.Foo(1, 2);
def.Bar();
using (Foo foo = new Foo())
{
common.hasPointerParam(foo, 0);
common.hasPointerParam(foo);
}
}
[Test]

8
tests/Common/Common.cpp

@ -647,3 +647,11 @@ void HasOverloadsWithDifferentPointerKindsToSameType::overload(int&& i) @@ -647,3 +647,11 @@ void HasOverloadsWithDifferentPointerKindsToSameType::overload(int&& i)
void HasOverloadsWithDifferentPointerKindsToSameType::overload(const int& i)
{
}
void hasPointerParam(Foo* foo, int i)
{
}
void hasPointerParam(const Foo& foo)
{
}

3
tests/Common/Common.h

@ -1213,3 +1213,6 @@ public: @@ -1213,3 +1213,6 @@ public:
void overload(int&& i);
void overload(const int& i);
};
DLL_API void hasPointerParam(Foo* foo, int i);
DLL_API void hasPointerParam(const Foo& foo);

Loading…
Cancel
Save