Subject: Re: [boost] Movable but not copyable bug?
From: Ion GaztaÃ±aga (igaztanaga_at_[hidden])
Date: 2014-08-25 17:14:07
El 25/08/2014 18:09, Mostafa escribiÃ³:
> On Mon, 25 Aug 2014 03:23:59 -0700, Ion GaztaÃ±aga <igaztanaga_at_[hidden]>
>> El 25/08/2014 2:29, Mostafa escribiÃ³:
>>> 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?
>> The copy constructor shall not be defined.
If you declare a class as BOOST_MOVABLE_BUT_NOT_COPYABLE(Foo) you must
not declare the assignment operator. Follow the steps explained here:
> Here's the updated code with error messages. Note, that on g++ 4.8.2 if
> (1) is commented out then it compiles fine but if uncommented then the
> error messages that follow the code are produced. In the latter case,
> the error messages are due to (2). Note also that (1) is the copy
> constructor for the movable *and* copyable type Bar which has a single
> member of type Foo that is movable but *not* copyable. Also note that
> Bar is a template class.
If Foo is not copyable, then you have a logic error in your code:
Bar(Bar const & rhs)
: f(rhs.f) <---- Tries to COPY Foo
If this copy constructor is instantiated, and in many compilers
Bar<Foo> b(( Bar<Foo>() ));
requires the copy constructor, then you get a compilation error. Just
try this equivalent (but more inefficient) code:
Then the copy constructor of Bar<Foo> is called and tries to COPY Foo.
As Foo is noncopyable, a compilation error is triggered.
Maybe you should design your code in C++11 and port it to Boost.Move,
you might get better compiler help.