summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2013-09-12 16:28:08 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-13 09:21:42 +0200
commit348b641fee1def119ab396422a4ec2a517720c34 (patch)
treecafc99fed402122146efe8cb591d4b1da9730b22
parenta02e430db99cd41d357069cd8740425684f6f497 (diff)
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>
-rw-r--r--src/corelib/global/qglobalstatic.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h
index a6268e057e..5d0b1e8514 100644
--- a/src/corelib/global/qglobalstatic.h
+++ b/src/corelib/global/qglobalstatic.h
@@ -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) \