summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-03-06 08:33:32 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-23 11:22:40 +0100
commite5ef496b5bd6a4650d765622c0690cdf47d7defc (patch)
treec40b82be6fc98d1b98217ff9e8d6e7bf69076501 /tests
parent9848c8b92c70006e55a7fa569d06d62efaf5ccc1 (diff)
tst_qsharedpointer: don't inherit from QSharedPointer
QSharedPointer is about to be made final. Instead of inheriting from it to gain access to the d-pointer, cast it to a layout-compatible struct and access the pointer from there. Assert liberally to ensure layout compatibility. Change-Id: Ifc0fa6a6608e861469286673844325663f4f7fcc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 5b697a3509..f8b9abb359 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -114,15 +114,19 @@ public:
}
};
-template <typename Base>
-class RefCountHack: public Base
+template<typename T> static inline
+QtSharedPointer::ExternalRefCountData *refCountData(const QtSharedPointer::ExternalRefCount<T> &b)
{
-public:
- using Base::d;
-};
-template<typename Base> static inline
-QtSharedPointer::ExternalRefCountData *refCountData(const Base &b)
-{ return static_cast<const RefCountHack<Base> *>(&b)->d; }
+ // access d-pointer:
+ struct Dummy {
+ void* value;
+ QtSharedPointer::ExternalRefCountData* data;
+ };
+ // sanity checks:
+ Q_STATIC_ASSERT(sizeof(QtSharedPointer::ExternalRefCount<T>) == sizeof(Dummy));
+ Q_ASSERT(static_cast<const Dummy*>(static_cast<const void*>(&b))->value == b.data());
+ return static_cast<const Dummy*>(static_cast<const void*>(&b))->data;
+}
class Data
{