Browse Source

When checking const-ness for ambiguity, ensure parameters are the same.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/398/head
Dimitar Dobrev 11 years ago
parent
commit
6fb15efd50
  1. 7
      src/Generator/Passes/CheckAmbiguousFunctions.cs
  2. 16
      tests/Basic/Basic.Tests.cs
  3. 10
      tests/Basic/Basic.cpp
  4. 7
      tests/Basic/Basic.h

7
src/Generator/Passes/CheckAmbiguousFunctions.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using CppSharp.AST; using CppSharp.AST;
namespace CppSharp.Passes namespace CppSharp.Passes
@ -104,13 +105,15 @@ namespace CppSharp.Passes
var method1 = function as Method; var method1 = function as Method;
var method2 = overload as Method; var method2 = overload as Method;
if (method1.IsConst && !method2.IsConst) var sameParams = method1.Parameters.SequenceEqual(method2.Parameters, new ParameterTypeComparer());
if (method1.IsConst && !method2.IsConst && sameParams)
{ {
method1.ExplicitlyIgnore(); method1.ExplicitlyIgnore();
return false; return false;
} }
if (method2.IsConst && !method1.IsConst) if (method2.IsConst && !method1.IsConst && sameParams)
{ {
method2.ExplicitlyIgnore(); method2.ExplicitlyIgnore();
return false; return false;

16
tests/Basic/Basic.Tests.cs

@ -467,5 +467,21 @@ public class BasicTests : GeneratorTestFixture
Assert.AreEqual(new Bar { A = 5, B = 5.5f }, new Bar { A = 5, B = 5.5f }); Assert.AreEqual(new Bar { A = 5, B = 5.5f }, new Bar { A = 5, B = 5.5f });
Assert.AreNotEqual(new Bar { A = 5, B = 5.6f }, new Bar { A = 5, B = 5.5f }); Assert.AreNotEqual(new Bar { A = 5, B = 5.6f }, new Bar { A = 5, B = 5.5f });
} }
[Test]
public void TestFriendOperator()
{
HasFriend h1 = 5;
HasFriend h2 = 10;
Assert.AreEqual(15, (h1 + h2).M);
}
[Test]
public void TestOperatorOverloads()
{
var differentConstOverloads = new DifferentConstOverloads();
Assert.IsTrue(differentConstOverloads == new DifferentConstOverloads());
Assert.IsFalse(differentConstOverloads == 5);
}
} }

10
tests/Basic/Basic.cpp

@ -357,3 +357,13 @@ DLL_API inline const HasFriend operator+(const HasFriend& f1, const HasFriend& f
{ {
return HasFriend(f1.m + f2.m); return HasFriend(f1.m + f2.m);
} }
bool DifferentConstOverloads::operator ==(const DifferentConstOverloads& other)
{
return true;
}
bool DifferentConstOverloads::operator ==(int number) const
{
return false;
}

7
tests/Basic/Basic.h

@ -671,3 +671,10 @@ public:
private: private:
int m; int m;
}; };
class DLL_API DifferentConstOverloads
{
public:
bool operator ==(const DifferentConstOverloads& other);
bool operator ==(int number) const;
};

Loading…
Cancel
Save