From c359df5ca6c70e254de2014d9a7c02c68017f772 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 16 May 2018 14:48:57 -0700 Subject: Add support for QSharedPointer::create() [ChangeLog][QtCore][QSharedPointer] Fixed a problem that made create() on a type with const qualification fail to compile. Task-number: QTBUG-68300 Change-Id: I0825ff5b5f6f4c85939ffffd152f3e55e5b9caae Reviewed-by: Ville Voutilainen Reviewed-by: Simon Hausmann --- src/corelib/tools/qsharedpointer_impl.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index a0e408b94a..bccf8c5740 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -246,7 +246,8 @@ namespace QtSharedPointer { struct ExternalRefCountWithContiguousData: public ExternalRefCountData { typedef ExternalRefCountData Parent; - T data; + typedef typename std::remove_cv::type NoCVType; + NoCVType data; static void deleter(ExternalRefCountData *self) { @@ -262,7 +263,7 @@ namespace QtSharedPointer { } static void noDeleter(ExternalRefCountData *) { } - static inline ExternalRefCountData *create(T **ptr, DestroyerFn destroy) + static inline ExternalRefCountData *create(NoCVType **ptr, DestroyerFn destroy) { ExternalRefCountWithContiguousData *d = static_cast(::operator new(sizeof(ExternalRefCountWithContiguousData))); @@ -437,10 +438,12 @@ public: # endif typename Private::DestroyerFn noDestroy = &Private::noDeleter; QSharedPointer result(Qt::Uninitialized); - result.d = Private::create(&result.value, noDestroy); + typename std::remove_cv::type *ptr; + result.d = Private::create(&ptr, noDestroy); // now initialize the data - new (result.data()) T(std::forward(arguments)...); + new (ptr) T(std::forward(arguments)...); + result.value = ptr; result.d->destroyer = destroy; result.d->setQObjectShared(result.value, true); # ifdef QT_SHAREDPOINTER_TRACK_POINTERS -- cgit v1.2.3