Subject: [Boost-bugs] [Boost C++ Libraries] #12194: Copy assignment on moveable and copyable classes uses wrong type
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-05-12 11:31:32
#12194: Copy assignment on moveable and copyable classes uses wrong type
--------------------------+------------------------
Reporter: a.grund@⦠| Owner: igaztanaga
Type: Bugs | Status: new
Milestone: Boost 1.61.0 | Component: move
Version: Boost 1.59.0 | Severity: Regression
Keywords: |
--------------------------+------------------------
A patch introduced a breaking change to classes that are copyable and
movable:
https://github.com/boostorg/move/commit/4f9c2b62fbdcf5995ecf50a2ecf2494048a6696d
#diff-6a11d48d06dd33c1193ffb3d794787fbR252
The macro was changed so the {{{TYPE& operator=(TYPE &t)}}} calls the
assignement operator with a type {{{ const TYPE& }}} instead of {{{ const
::boost::rv<TYPE> & }}}
This change is not described and seems to be a mistake that was not caught
in the review process. As the macro {{{ BOOST_COPY_ASSIGN_REF }}} still
expands to the original rv-type a wrong operator might get called. A
minimum example:
{{{
#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; return *this; }
Foo& operator=(BOOST_COPY_ASSIGN_REF(Foo) rhs){ i = rhs.i; return
*this; }
template<class OTHER>
Foo& operator=(const OTHER& rhs){ i = rhs.j; return *this; }
};
struct Bar{
int j;
explicit Bar(int val): j(val){}
};
int main(){
Foo foo1(1);
Foo foo2(2);
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);
return 0;
}
}}}
This compiles and works fine in boost <=1.58 but fails in >=1.59 as the
template version is called.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12194> 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