Permalink
Browse files

Fixed the binding of a copy ctor when a move ctor exists too.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jun 12, 2017
1 parent 3298bc8 commit c740a34dfaa719d72c23fbe01a53bb6bce675820
@@ -31,9 +31,6 @@ public static bool CheckIgnoreMethod(Method method)
if (@class != null && @class.IsValueType && isEmptyCtor)
return true;
if (method.IsMoveConstructor)
return true;
if (method.IsDestructor)
return true;
@@ -302,6 +302,7 @@ public void SetupPasses(ILibrary library)
TranslationUnitPasses.AddPass(new GenerateAnonymousDelegatesPass());
TranslationUnitPasses.AddPass(new ConstructorToConversionOperatorPass());
TranslationUnitPasses.AddPass(new MarshalPrimitivePointersAsRefTypePass());
TranslationUnitPasses.AddPass(new IgnoreMoveConstructorsPass());
TranslationUnitPasses.AddPass(new CheckAmbiguousFunctions());
TranslationUnitPasses.AddPass(new CheckOperatorsOverloadsPass());
TranslationUnitPasses.AddPass(new CheckVirtualOverrideReturnCovariance());
@@ -494,7 +494,7 @@ public void GenerateClassInternals(Class @class)
{
foreach (var ctor in @class.Constructors)
{
if (@class.IsStatic || ctor.IsMoveConstructor)
if (@class.IsStatic)
continue;
if (!ctor.IsGenerated)
@@ -33,7 +33,7 @@ public override bool VisitFunctionDecl(AST.Function function)
if (!VisitDeclaration(function))
return false;
if (function.IsAmbiguous)
if (function.IsAmbiguous || !function.IsGenerated)
return false;
var overloads = function.Namespace.GetOverloads(function);
@@ -0,0 +1,36 @@
using CppSharp.AST;
using CppSharp.Passes;
namespace CppSharp.Passes
{
public class IgnoreMoveConstructorsPass : TranslationUnitPass
{
public IgnoreMoveConstructorsPass()
{
VisitOptions.VisitClassBases = false;
VisitOptions.VisitClassFields = false;
VisitOptions.VisitClassProperties = false;
VisitOptions.VisitEventParameters = false;
VisitOptions.VisitFunctionParameters = false;
VisitOptions.VisitFunctionReturnType = false;
VisitOptions.VisitNamespaceEnums = false;
VisitOptions.VisitNamespaceEvents = false;
VisitOptions.VisitNamespaceVariables = false;
VisitOptions.VisitTemplateArguments = false;
}
public override bool VisitMethodDecl(Method method)
{
if (!base.VisitMethodDecl(method))
return false;
if (method.IsMoveConstructor)
{
method.ExplicitlyIgnore();
return true;
}
return false;
}
}
}
@@ -355,15 +355,31 @@ public void TestStaticClasses()
[Test]
public void TestCopyConstructor()
{
Foo foo = new Foo { A = 5, B = 5.5f };
var copyFoo = new Foo(foo);
Assert.That(foo.A, Is.EqualTo(copyFoo.A));
Assert.That(foo.B, Is.EqualTo(copyFoo.B));
var testCopyConstructorRef = new TestCopyConstructorRef { A = 10, B = 5 };
var copyBar = new TestCopyConstructorRef(testCopyConstructorRef);
Assert.That(testCopyConstructorRef.A, Is.EqualTo(copyBar.A));
Assert.That(testCopyConstructorRef.B, Is.EqualTo(copyBar.B));
using (Foo foo = new Foo { A = 5, B = 5.5f })
{
using (var copyFoo = new Foo(foo))
{
Assert.That(foo.A, Is.EqualTo(copyFoo.A));
Assert.That(foo.B, Is.EqualTo(copyFoo.B));
}
}
using (var testCopyConstructorRef = new TestCopyConstructorRef { A = 10, B = 5 })
{
using (var copyBar = new TestCopyConstructorRef(testCopyConstructorRef))
{
Assert.That(testCopyConstructorRef.A, Is.EqualTo(copyBar.A));
Assert.That(testCopyConstructorRef.B, Is.EqualTo(copyBar.B));
}
}
using (var original = new HasCopyAndMoveConstructor(5))
{
using (var copy = new HasCopyAndMoveConstructor(original))
{
Assert.That(copy.Field, Is.EqualTo(original.Field));
}
}
}
[Test]
@@ -683,3 +683,27 @@ TestStaticClass& TestStaticClass::operator=(const TestStaticClass& oth)
{
return *this;
}
HasCopyAndMoveConstructor::HasCopyAndMoveConstructor(int value)
{
field = value;
}
HasCopyAndMoveConstructor::HasCopyAndMoveConstructor(const HasCopyAndMoveConstructor &other)
{
field = other.field;
}
HasCopyAndMoveConstructor::HasCopyAndMoveConstructor(HasCopyAndMoveConstructor&& other)
{
field = other.field;
}
HasCopyAndMoveConstructor::~HasCopyAndMoveConstructor()
{
}
int HasCopyAndMoveConstructor::getField()
{
return field;
}
@@ -763,7 +763,6 @@ struct DLL_API TestNestedTypes
class DLL_API HasStdString
{
// test if these are ignored with the C# back-end
public:
std::string testStdString(std::string s);
std::string s;
@@ -1223,3 +1222,15 @@ enum EmptyEnum { };
enum __enum_with_underscores { lOWER_BEFORE_CAPITAL, CAPITALS_More, underscore_at_end_, usesDigits1_0 };
void DLL_API sMallFollowedByCapital();
class DLL_API HasCopyAndMoveConstructor
{
public:
HasCopyAndMoveConstructor(int value);
HasCopyAndMoveConstructor(const HasCopyAndMoveConstructor& other);
HasCopyAndMoveConstructor(HasCopyAndMoveConstructor&& other);
~HasCopyAndMoveConstructor();
int getField();
private:
int field;
};

0 comments on commit c740a34

Please sign in to comment.