Boost logo

Boost :

Subject: [boost] Movable but not copyable bug?
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2014-08-24 20:29:01


I had posted this on the user's list but I think this should be brought to
the attention of the developers. The following code contains a templated
copy constructible Boost.Move enabled class (Bar) with a single non-copy
constructible Boost.Enabled member (Foo). If Bar's copy constructor is not
explicitly defined then the code compiles with both g++ 4.8.2 and VS2005,
else if it's explicitly defined then it fails to compile on g++ 4.8.2 I
think this is due to the fact that g++ 4.8.2 erroneously instantiates
Bar's default copy constructor in the latter case. Is this a Boost.Move
bug or a gcc bug?

#include <boost/move/core.hpp>
#include <boost/move/utility.hpp>

struct Foo
{
   Foo(int x, int y)
   {}

   Foo(BOOST_RV_REF(Foo) rhs)
   {}

private:
   //Purposefully declared and not defined.
   Foo & operator=(Foo);
private:
   BOOST_MOVABLE_BUT_NOT_COPYABLE(Foo)
};

template <typename T>
struct Bar
{
   Bar()
   : f(0, 1)
   {}

   // (1)
   //Bar(Bar const & rhs)
   //: f(rhs.f)
   //{}

   Bar(BOOST_RV_REF(Bar) rhs)
   : f(::boost::move(rhs.f))
   {}

private:
   //Purposefully declared and not defined.
   Bar & operator=(Bar);
private:
   BOOST_COPYABLE_AND_MOVABLE(Bar)
private:
   T f;
};

Foo f1()
{
   return Foo(0, 1);
}

Bar<Foo> f2()
{
   return Bar<Foo>();
}

int main()
{
   // Foo f( f1() );

   Bar<Foo> b(( Bar<Foo>() ));

   // Bar<Foo> b1;
   // Bar<Foo> b2(b1);

   return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk