El 26/08/2014 1:18, Peter Dimov escribió:
Mostafa wrote:
Then why is it that in C++03 with g++ 4.8.2 the code sample compiles if the copy ctor for Bar is not explicitly defined?
C++03 12.8/5:
The implicitly-declared copy constructor for a class X will have the form X::X(const X&) if — each direct or virtual base class B of X has a copy constructor whose first parameter is of type const B& or const volatile B&, and — for all the nonstatic data members of X that are of a class type M (or array thereof), each such class type has a copy constructor whose first parameter is of type const M& or const volatile M&.107) Otherwise, the implicitly declared copy constructor will have the form X::X(X&)
My guess is that Boost.Move declares Foo's copy constructor to take Foo&. This causes Bar's implicit copy constructor to take Bar&, which doesn't match rvalues.
Right. From boost/move/core.hpp: #define BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)\ BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE)\ public:\ operator ::boost::rv<TYPE>&() \ { return *static_cast< ::boost::rv<TYPE>* >(this); }\ operator const ::boost::rv<TYPE>&() const \ { return *static_cast<const ::boost::rv<TYPE>* >(this); }\ private:\ // and #if defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) #define BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE) \ private:\ TYPE(TYPE &);\ TYPE& operator=(TYPE &);\ public:\ typedef int boost_move_no_copy_constructor_or_assign; \ private:\ // #else #define BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE) \ public:\ TYPE(TYPE const &) = delete;\ TYPE& operator=(TYPE const &) = delete;\ public:\ typedef int boost_move_no_copy_constructor_or_assign; \ private:\ // #endif //BOOST_NO_CXX11_DELETED_FUNCTIONS Best, Ion