Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array& operator=(Array&& rhs) fails to compile. #6

Open
JackCibc opened this issue Jan 16, 2018 · 4 comments
Open

Array& operator=(Array&& rhs) fails to compile. #6

JackCibc opened this issue Jan 16, 2018 · 4 comments

Comments

@JackCibc
Copy link

0001-Initial-move-assign-fixes.txt

The following test case (a call to Array(.) move assignment) fails to compile on Visual Studio 15.5.3 and Clang, with error message:

'1>aad\adept-2\adept-2.0.4\include\adept\array.h(402): error C2660: 'adept::internal::GradientIndex::swap': function does not take 2 arguments'
'1>aad\adept-2\adept-2.0.4\include\adept\array.h(385): note: while compiling class template member function 'adept::Array<1,adept::Real,false> &adept::Array<1,adept::Real,false>::operator =(adept::Array<1,adept::Real,false> &&)''

I've attached a simple fix, but it may not be the best way to resolve this issue.

Regards,

John.

#include <adept.h>
#include <adept/array_shortcuts.h>
#include < iostream >

using adept::adouble;
using adept::Vector;

Vector generateVector(void)
{
Vector x = { 3.0 };
return x;
}

void testMoveAssign(void)
{
#ifdef ADEPT_MOVE_SEMANTICS
std::cout << "\n Move on" << std::endl;
#else
std::cout << "\n Move off" << std::endl;
#endif
Vector v;
v = generateVector(); // This fails to compile.
}

@rjhogan
Copy link
Owner

rjhogan commented Jan 20, 2018 via email

@JackCibc
Copy link
Author

JackCibc commented Feb 5, 2018

Thanks. This was Visual Studio 2017 - confusingly the version number is 15.5.x. I've now also tested with 15.5.6 and Adept-2\master from today and I get the same result. The Clang is the one that ships with Visual Studio, "Clang parser and MS code-gen", so may also have some Microsoft specific changes unfortunately.

I take your point on swap(.) - I've moved it into the class by making it static. VS isn't finding it otherwise, and I didn't find a good way to make it a free function.

Cheers,

John.

@manuelnp
Copy link

manuelnp commented Feb 7, 2018

Hi Jack,

I was able to build you example in my VS2012 successfully (removing the initialization list being that c++11 subset in VS2012 does not include them) so it seems more like a VS2017 issue. I will perform further test and let you know.

Regards.

@JackCibc
Copy link
Author

JackCibc commented Feb 7, 2018

Could you check if the move assignment is being compiled in? From the docs it looks like _MSVC_LANG wasn't defined until VS 2015, so you may not be getting move semantics at all. I can't check right now I'm afraid.

An easy check would be to do

#ifdef ADEPT_MOVE_SEMANTICS
#pragma message( "\n Move on")
#else
#pragma message( "\n Move off")
#endif

in the test program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants