mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 05:54:28 +02:00
- Add asserts to detect self-move bugs.
- Fix return type in life_count::check functions
This commit is contained in:
@@ -54,10 +54,16 @@ class movable_int
|
|||||||
|
|
||||||
movable_int(BOOST_RV_REF(movable_int) mmi)
|
movable_int(BOOST_RV_REF(movable_int) mmi)
|
||||||
: m_int(mmi.m_int)
|
: m_int(mmi.m_int)
|
||||||
{ mmi.m_int = 0; ++count; }
|
{
|
||||||
|
BOOST_ASSERT(&mmi != this);
|
||||||
|
mmi.m_int = 0; ++count;
|
||||||
|
}
|
||||||
|
|
||||||
movable_int & operator= (BOOST_RV_REF(movable_int) mmi)
|
movable_int & operator= (BOOST_RV_REF(movable_int) mmi)
|
||||||
{ this->m_int = mmi.m_int; mmi.m_int = 0; return *this; }
|
{
|
||||||
|
BOOST_ASSERT(&mmi != this);
|
||||||
|
this->m_int = mmi.m_int; mmi.m_int = 0; return *this;
|
||||||
|
}
|
||||||
|
|
||||||
movable_int & operator= (int i)
|
movable_int & operator= (int i)
|
||||||
{ this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
|
{ this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
|
||||||
@@ -152,11 +158,17 @@ class movable_and_copyable_int
|
|||||||
|
|
||||||
movable_and_copyable_int(const movable_and_copyable_int& mmi)
|
movable_and_copyable_int(const movable_and_copyable_int& mmi)
|
||||||
: m_int(mmi.m_int)
|
: m_int(mmi.m_int)
|
||||||
{ ++count; }
|
{
|
||||||
|
BOOST_ASSERT(&mmi != this);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
|
||||||
movable_and_copyable_int(BOOST_RV_REF(movable_and_copyable_int) mmi)
|
movable_and_copyable_int(BOOST_RV_REF(movable_and_copyable_int) mmi)
|
||||||
: m_int(mmi.m_int)
|
: m_int(mmi.m_int)
|
||||||
{ mmi.m_int = 0; ++count; }
|
{
|
||||||
|
BOOST_ASSERT(&mmi != this);
|
||||||
|
mmi.m_int = 0; ++count;
|
||||||
|
}
|
||||||
|
|
||||||
~movable_and_copyable_int()
|
~movable_and_copyable_int()
|
||||||
{
|
{
|
||||||
@@ -170,7 +182,10 @@ class movable_and_copyable_int
|
|||||||
{ this->m_int = mi.m_int; return *this; }
|
{ this->m_int = mi.m_int; return *this; }
|
||||||
|
|
||||||
movable_and_copyable_int & operator= (BOOST_RV_REF(movable_and_copyable_int) mmi)
|
movable_and_copyable_int & operator= (BOOST_RV_REF(movable_and_copyable_int) mmi)
|
||||||
{ this->m_int = mmi.m_int; mmi.m_int = 0; return *this; }
|
{
|
||||||
|
BOOST_ASSERT(&mmi != this);
|
||||||
|
this->m_int = mmi.m_int; mmi.m_int = 0; return *this;
|
||||||
|
}
|
||||||
|
|
||||||
movable_and_copyable_int & operator= (int i)
|
movable_and_copyable_int & operator= (int i)
|
||||||
{ this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
|
{ this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
|
||||||
@@ -396,38 +411,37 @@ unsigned int non_copymovable_int::count = 0;
|
|||||||
template<class T>
|
template<class T>
|
||||||
struct life_count
|
struct life_count
|
||||||
{
|
{
|
||||||
static unsigned check(unsigned) { return true; }
|
static bool check(unsigned) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct life_count< movable_int >
|
struct life_count< movable_int >
|
||||||
{
|
{
|
||||||
static unsigned check(unsigned c)
|
static bool check(unsigned c)
|
||||||
{ return c == movable_int::count; }
|
{ return c == movable_int::count; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct life_count< copyable_int >
|
struct life_count< copyable_int >
|
||||||
{
|
{
|
||||||
static unsigned check(unsigned c)
|
static bool check(unsigned c)
|
||||||
{ return c == copyable_int::count; }
|
{ return c == copyable_int::count; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct life_count< movable_and_copyable_int >
|
struct life_count< movable_and_copyable_int >
|
||||||
{
|
{
|
||||||
static unsigned check(unsigned c)
|
static bool check(unsigned c)
|
||||||
{ return c == movable_and_copyable_int::count; }
|
{ return c == movable_and_copyable_int::count; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct life_count< non_copymovable_int >
|
struct life_count< non_copymovable_int >
|
||||||
{
|
{
|
||||||
static unsigned check(unsigned c)
|
static bool check(unsigned c)
|
||||||
{ return c == non_copymovable_int::count; }
|
{ return c == non_copymovable_int::count; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} //namespace test {
|
} //namespace test {
|
||||||
} //namespace container {
|
} //namespace container {
|
||||||
} //namespace boost {
|
} //namespace boost {
|
||||||
|
Reference in New Issue
Block a user