mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-02-15 13:12:21 +00:00
Fix self assignment bug in mpfr_float
Fixes: https://svn.boost.org/trac/boost/ticket/11193
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user