debug: check sanity at end of scope for CHECK_SANITY

This commit is contained in:
Danny Robson 2018-04-18 21:43:58 +10:00
parent fe88708c50
commit 5ba9da1828

View File

@ -96,14 +96,9 @@
///////////////////////////////////////////////////////////////////////////////
#define CHECK_SANITY(A) do { \
DEBUG_ONLY ( \
const auto &__a = (A); \
if (!::util::debug::is_valid (__a)) { \
_CHECK_PANIC("failed sanity test for %s, %!\n", #A, __a); \
} \
); \
} while (0)
#define CHECK_SANITY(A) \
::util::debug::scoped_sanity PASTE(__scoped_sanity_checker,__LINE__) (A); \
(void)PASTE(__scoped_sanity_checker,__LINE__);
///////////////////////////////////////////////////////////////////////////////
@ -615,8 +610,27 @@ namespace util::debug {
(void)t;
CHECK (is_valid (t));
}
template <typename ValueT>
class scoped_sanity {
public:
scoped_sanity (ValueT &_value):
m_value (_value)
{
sanity (m_value);
}
~scoped_sanity ()
{
sanity (m_value);
}
private:
const ValueT& m_value;
};
};
///////////////////////////////////////////////////////////////////////////////
// XXX: maths needs to be included so that CHECK_EQ/NEQ can call almost_equal,