Throw exception in debug mode when thisRef()/thisWeakRef() is called from the object's constructor.
This commit is contained in:
parent
8cae762d46
commit
2dd861c907
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user