From 6fb15efd5037d62b2f70b969454dd84f89986181 Mon Sep 17 00:00:00 2001
From: Dimitar Dobrev <dpldobrev@yahoo.com>
Date: Mon, 5 Jan 2015 02:55:27 +0200
Subject: [PATCH] When checking const-ness for ambiguity, ensure parameters are
 the same.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
---
 src/Generator/Passes/CheckAmbiguousFunctions.cs |  7 +++++--
 tests/Basic/Basic.Tests.cs                      | 16 ++++++++++++++++
 tests/Basic/Basic.cpp                           | 10 ++++++++++
 tests/Basic/Basic.h                             |  7 +++++++
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/Generator/Passes/CheckAmbiguousFunctions.cs b/src/Generator/Passes/CheckAmbiguousFunctions.cs
index 5627dbaf..e4958827 100644
--- a/src/Generator/Passes/CheckAmbiguousFunctions.cs
+++ b/src/Generator/Passes/CheckAmbiguousFunctions.cs
@@ -1,4 +1,5 @@
 using System;
+using System.Linq;
 using CppSharp.AST;
 
 namespace CppSharp.Passes
@@ -104,13 +105,15 @@ namespace CppSharp.Passes
                 var method1 = function 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();
                     return false;
                 }
 
-                if (method2.IsConst && !method1.IsConst)
+                if (method2.IsConst && !method1.IsConst && sameParams)
                 {
                     method2.ExplicitlyIgnore();
                     return false;
diff --git a/tests/Basic/Basic.Tests.cs b/tests/Basic/Basic.Tests.cs
index 9ee4cbd2..b5debc4f 100644
--- a/tests/Basic/Basic.Tests.cs
+++ b/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.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);
+    }
 }
  
\ No newline at end of file
diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp
index 94b4216d..8be51b31 100644
--- a/tests/Basic/Basic.cpp
+++ b/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);
 }
+
+bool DifferentConstOverloads::operator ==(const DifferentConstOverloads& other)
+{
+    return true;
+}
+
+bool DifferentConstOverloads::operator ==(int number) const
+{
+    return false;
+}
diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h
index a0d06901..ec6f533e 100644
--- a/tests/Basic/Basic.h
+++ b/tests/Basic/Basic.h
@@ -671,3 +671,10 @@ public:
 private:
     int m;
 };
+
+class DLL_API DifferentConstOverloads
+{
+public:
+    bool operator ==(const DifferentConstOverloads& other);
+    bool operator ==(int number) const;
+};