[Boost-bugs] [Boost C++ Libraries] #7969: BOOST_MOVABLE_BUT_NOT_COPYABLE makes it impossible to use type in GCC containners in C++11

Subject: [Boost-bugs] [Boost C++ Libraries] #7969: BOOST_MOVABLE_BUT_NOT_COPYABLE makes it impossible to use type in GCC containners in C++11
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-03 13:16:31


#7969: BOOST_MOVABLE_BUT_NOT_COPYABLE makes it impossible to use type in GCC
containners in C++11
-----------------------------------------+----------------------------------
 Reporter: apolukhin | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: move
  Version: Boost Development Trunk | Severity: Problem
 Keywords: c++11 c++0x noncopyable stl |
-----------------------------------------+----------------------------------
 BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE) defines:

 TYPE(const TYPE &);
 TYPE& operator=(const TYPE &);

 which makes GCC assume that class have copy constructor and assignment
 operator. That makes STL containers to choose assignment operator instead
 of move assignment.

 The solution would be to mark them in c++11 with '= delete' or not write
 them at all (compiler shall not generate copy constructors if there is a
 move constructor, but this may not work on some compilers):
 {{{
 #ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
 #define BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)\
       public:\
       typedef int boost_move_emulation_t;\
       private:\
       TYPE(const TYPE &) = delete;\
       TYPE& operator=(const TYPE &) = delete;\
 #else
 #define BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)\
       public:\
       typedef int boost_move_emulation_t;\
       private:\
 #endif
 }}}

 Example to reproduce the error:
 {{{
 #include <boost/move/move.hpp>
 #include <vector>

 class descriptor_owner_movable {
     void* descriptor_;

     BOOST_MOVABLE_BUT_NOT_COPYABLE(descriptor_owner_movable)
 public:
     descriptor_owner_movable(){}

     descriptor_owner_movable(BOOST_RV_REF(descriptor_owner_movable) param)
 {}

     descriptor_owner_movable&
 operator=(BOOST_RV_REF(descriptor_owner_movable) param) {
         return *this;
     }
 };


 int main() {
     std::vector<descriptor_owner_movable> vec;
     vec.resize(10);
     return 0;
 }

 }}}

 Tested on GCC 4.7.2 with -std=c++0x flag

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7969>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC