From 348b641fee1def119ab396422a4ec2a517720c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Thu, 12 Sep 2013 16:28:08 +0000 Subject: 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 Reviewed-by: Olivier Goffart --- src/corelib/global/qglobalstatic.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/corelib/global/qglobalstatic.h') 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) \ -- cgit v1.2.3