Throw exception in debug mode when thisRef()/thisWeakRef() is called from the object's constructor.

This commit is contained in:
Vincent Richard 2005-09-02 11:02:12 +00:00
parent 8cae762d46
commit 2dd861c907

View File

@ -35,6 +35,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testCast)
VMIME_TEST(testContainer)
VMIME_TEST(testCompare)
VMIME_TEST(testThisRefCtor)
VMIME_TEST_LIST_END
@ -60,6 +61,12 @@ VMIME_TEST_SUITE_BEGIN
bool* m_aliveFlag;
};
struct X : public vmime::object
{
X() { f(thisRef().dynamicCast <X>()); }
static void f(vmime::ref <X> /* x */) { }
};
void testNull()
{
@ -237,5 +244,11 @@ VMIME_TEST_SUITE_BEGIN
VASSERT("10", std::find(v.begin(), v.end(), r3) == v.end());
}
void testThisRefCtor()
{
// BUGFIX: thisRef() MUST NOT be called from the object constructor
VASSERT_THROW("1", vmime::create <X>(), std::runtime_error);
}
VMIME_TEST_SUITE_END