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:
parent
a02e430db9
commit
348b641fee
@ -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) \
|
||||
|
Loading…
Reference in New Issue
Block a user