Boost logo

Boost :

Subject: [boost] [move] const rvalue failure.
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2014-08-24 20:03:15


The following fails to compile on both g++ 4.8.2 and VS2005 using Boost
1.56:

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

struct MOC
{
   MOC() : value(121) {}
   MOC(BOOST_RV_REF(MOC) rhs) : value(rhs.value) {}
   int value;
private:
   //Declared and purposefully not defined.
   MOC & operator=(MOC);
private:
   BOOST_MOVABLE_BUT_NOT_COPYABLE(MOC)
};

MOC moveonlyMutableRValue()
{
   return MOC();
}

MOC const moveonlyConstRValue()
{
   return MOC();
}

int main()
{
   MOC m(moveonlyConstRValue());

   return 0;
}

with g++, I get the following error messages:

boost_move_const_rvalue.cc: In function ‘int main()’:
boost_move_const_rvalue.cc:28:30: error: invalid user-defined conversion
 from ‘const MOC’ to ‘boost::rv<MOC>&’ [-fpermissive]
    MOC m(moveonlyConstRValue());
                               ^
In file included from boost_move_const_rvalue.cc:1:0:
/home/HPC/boost_installed/v1_56_0/include/boost/move/core.hpp:219:7: note:
candidate is: MOC::operator boost::rv<MOC>&() <near match>
        operator ::boost::rv<TYPE>&() \
        ^
boost_move_const_rvalue.cc:13:3: note: in expansion of macro
‘BOOST_MOVABLE_BUT_NOT_COPYABLE’
    BOOST_MOVABLE_BUT_NOT_COPYABLE(MOC)
    ^
/home/HPC/boost_installed/v1_56_0/include/boost/move/core.hpp:219:7:
note: no known conversion for implicit ‘this’ parameter from ‘const
MOC*’ to ‘MOC*’
        operator ::boost::rv<TYPE>&() \
        ^
boost_move_const_rvalue.cc:13:3: note: in expansion of macro
‘BOOST_MOVABLE_BUT_NOT_COPYABLE’
    BOOST_MOVABLE_BUT_NOT_COPYABLE(MOC)
    ^
boost_move_const_rvalue.cc:28:30: error: passing ‘const MOC’ as ‘this’
argument of ‘MOC::operator boost::rv<MOC>&()’ discards qualifiers
[-fpermissive]
    MOC m(moveonlyConstRValue());


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