Update tests to exercise move-construct/copy better.

Fix exposed bug in tommath backend.
See also https://svn.boost.org/trac/boost/ticket/9497.
This commit is contained in:
jzmaddock
2013-12-22 09:57:01 +00:00
parent f9a4e93a5d
commit 787cd1101e
2 changed files with 20 additions and 1 deletions

View File

@@ -58,7 +58,7 @@ struct tommath_int
}
tommath_int& operator = (tommath_int&& o)
{
mp_exch(&m_data, &o.data());
mp_exch(&m_data, &o.m_data);
return *this;
}
#endif

View File

@@ -1777,5 +1777,24 @@ void test()
test_conditional(a, (a + 0));
test_signed_ops<Real>(boost::mpl::bool_<std::numeric_limits<Real>::is_signed>());
//
// Test move:
//
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
Real m(static_cast<Real&&>(a));
BOOST_CHECK_EQUAL(m, 20);
// Move from already moved from object:
Real m2(static_cast<Real&&>(a));
// assign from moved from object
// (may result in "a" being left in valid state as implementation artifact):
c = static_cast<Real&&>(a);
// assignment to moved-from objects:
c = static_cast<Real&&>(m);
BOOST_CHECK_EQUAL(c, 20);
m2 = c;
BOOST_CHECK_EQUAL(c, 20);
// Destructor of "a" checks destruction of moved-from-object...
Real m3(static_cast<Real&&>(a));
#endif
}