From e5ef496b5bd6a4650d765622c0690cdf47d7defc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 6 Mar 2012 08:33:32 +0100 Subject: 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 --- .../tools/qsharedpointer/tst_qsharedpointer.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'tests') 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 -class RefCountHack: public Base +template static inline +QtSharedPointer::ExternalRefCountData *refCountData(const QtSharedPointer::ExternalRefCount &b) { -public: - using Base::d; -}; -template static inline -QtSharedPointer::ExternalRefCountData *refCountData(const Base &b) -{ return static_cast *>(&b)->d; } + // access d-pointer: + struct Dummy { + void* value; + QtSharedPointer::ExternalRefCountData* data; + }; + // sanity checks: + Q_STATIC_ASSERT(sizeof(QtSharedPointer::ExternalRefCount) == sizeof(Dummy)); + Q_ASSERT(static_cast(static_cast(&b))->value == b.data()); + return static_cast(static_cast(&b))->data; +} class Data { -- cgit v1.2.3