Fix self assignment bug in mpfr_float

Fixes: https://svn.boost.org/trac/boost/ticket/11193
This commit is contained in:
jzmaddock
2015-04-17 08:30:45 +01:00
parent 2919a6375e
commit c36e15bd29
2 changed files with 14 additions and 5 deletions

View File

@@ -831,11 +831,14 @@ struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0
mpfr_float_backend& operator=(const mpfr_float_backend& o)
{
if(this->m_data[0]._mpfr_d == 0)
mpfr_init2(this->m_data, mpfr_get_prec(o.data()));
else
mpfr_set_prec(this->m_data, mpfr_get_prec(o.data()));
mpfr_set(this->m_data, o.data(), GMP_RNDN);
if(this != &o)
{
if(this->m_data[0]._mpfr_d == 0)
mpfr_init2(this->m_data, mpfr_get_prec(o.data()));
else
mpfr_set_prec(this->m_data, mpfr_get_prec(o.data()));
mpfr_set(this->m_data, o.data(), GMP_RNDN);
}
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES

View File

@@ -1927,5 +1927,11 @@ void test()
// Destructor of "a" checks destruction of moved-from-object...
Real m3(static_cast<Real&&>(a));
#endif
//
// Bug cases, self assignment first:
//
a = 20;
a = a;
BOOST_CHECK_EQUAL(a, 20);
}