[Boost-bugs] [Boost C++ Libraries] #12307: Copy assignment from const ref handled differently in C++11/C++98

Subject: [Boost-bugs] [Boost C++ Libraries] #12307: Copy assignment from const ref handled differently in C++11/C++98
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-06-30 11:09:43


#12307: Copy assignment from const ref handled differently in C++11/C++98
------------------------------+------------------------
 Reporter: a.grund@… | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: move
  Version: Boost 1.59.0 | Severity: Problem
 Keywords: |
------------------------------+------------------------
 There is a difference in the handling of copy assignment when using
 Boost.Move between C++11 and C++98:


 {{{
     #include <boost/move/move.hpp>
     #include <cassert>

     class Foo{
         BOOST_COPYABLE_AND_MOVABLE(Foo)
     public:
         int i;
         explicit Foo(int val): i(val){}
         Foo(BOOST_RV_REF(Foo) obj): i(obj.i) {}
         Foo& operator=(BOOST_RV_REF(Foo) rhs){ i = rhs.i; rhs.i = 0;
 return *this; }
         Foo& operator=(BOOST_COPY_ASSIGN_REF(Foo) rhs){ i = rhs.i; return
 *this; } //(1)
         template<class OTHER>
         Foo& operator=(const OTHER& rhs){ i = rhs.j; return *this; } //(2)
     };

     struct Bar{
         int j;
         explicit Bar(int val): j(val){}
     };

     int main(){
         Foo foo2(2);
         // Working cases
         Foo foo1(1);
         Bar bar(3);
         assert(foo1.i == 1);
         assert(foo2.i == 2);
         assert(bar.j == 3);
         foo2 = foo1;
         assert(foo1.i == 1);
         assert(foo2.i == 1);
         foo1 = bar;
         assert(foo1.i == 3);
         foo2 = boost::move(foo1);
         assert(foo1.i == 0);
         assert(foo2.i == 3);
         // BUG
         const Foo foo4(4);
         foo2 = foo4; // Calls (1) in C++11 but (2) in C++98 which fails
         assert(foo2.i == 4);
         assert(foo4.i == 4);
         return 0;
     }
 }}}

 This is slighlty different than
 https://svn.boost.org/trac/boost/ticket/12194 which was fixed with
 https://github.com/boostorg/move/pull/9 but kind of releated.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12307>
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:20 UTC