Add assert if a global static is used after deletion.

Q_GLOBAL_STATIC accessor is documented to return dangling pointer if
called after destruction.

Change-Id: Ieafd5619b20ad256d9d5ad007d939f1430ef681f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Jędrzej Nowacki 2013-09-12 16:28:08 +00:00 committed by The Qt Project
parent a02e430db9
commit 348b641fee

View File

@ -121,8 +121,16 @@ struct QGlobalStatic
bool exists() const { return guard.load() == QtGlobalStatic::Initialized; }
operator Type *() { if (isDestroyed()) return 0; return innerFunction(); }
Type *operator()() { if (isDestroyed()) return 0; return innerFunction(); }
Type *operator->() { return innerFunction(); }
Type &operator*() { return *innerFunction(); }
Type *operator->()
{
Q_ASSERT_X(!isDestroyed(), "Q_GLOBAL_STATIC", "The global static was used after being destroyed");
return innerFunction();
}
Type &operator*()
{
Q_ASSERT_X(!isDestroyed(), "Q_GLOBAL_STATIC", "The global static was used after being destroyed");
return *innerFunction();
}
};
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \