|
Boost : |
Subject: Re: [boost] Movable but not copyable bug?
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2014-08-25 12:09:31
On Mon, 25 Aug 2014 03:23:59 -0700, Ion Gaztañaga <igaztanaga_at_[hidden]>
wrote:
> 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.
???
> Otherwise, please be a bit more explicit about the error, which
> operations, fails, etc.
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.
//Start Code
#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;
};
int main()
{
// (2)
Bar<Foo> b(( Bar<Foo>() ));
return 0;
}
//End Code
//Start Error Messages
boost_move_default_copy_ctor.cc: In instantiation of âBar<T>::Bar(const
Bar<T>&) [with T = Foo]â:
boost_move_default_copy_ctor.cc:47:28: required from here
boost_move_default_copy_ctor.cc:28:12: error: invalid user-defined
conversion from âconst Fooâ to âboost::rv<Foo>&â [-fpermissive]
: f(rhs.f)
^
In file included from boost_move_default_copy_ctor.cc:1:0:
/home/HPC/boost_installed/v1_56_0/include/boost/move/core.hpp:219:7: note:
candidate is: Foo::operator boost::rv<Foo>&() <near match>
operator ::boost::rv<TYPE>&() \
^
boost_move_default_copy_ctor.cc:16:3: note: in expansion of macro
âBOOST_MOVABLE_BUT_NOT_COPYABLEâ
BOOST_MOVABLE_BUT_NOT_COPYABLE(Foo)
^
/home/HPC/boost_installed/v1_56_0/include/boost/move/core.hpp:219:7:
note: no known conversion for implicit âthisâ parameter from âconst
Foo*â to âFoo*â
operator ::boost::rv<TYPE>&() \
^
boost_move_default_copy_ctor.cc:16:3: note: in expansion of macro
âBOOST_MOVABLE_BUT_NOT_COPYABLEâ
BOOST_MOVABLE_BUT_NOT_COPYABLE(Foo)
^
boost_move_default_copy_ctor.cc:28:12: error: passing âconst Fooâ as
âthisâ argument of âFoo::operator boost::rv<Foo>&()â discards qualifiers
[-fpermissive]
: f(rhs.f)
^
//End Error Messages
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk