diff options
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 11 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp | 8 |
2 files changed, 15 insertions, 4 deletions
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<T>::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<ExternalRefCountWithContiguousData *>(::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<T>::type *ptr; + result.d = Private::create(&ptr, noDestroy); // now initialize the data - new (result.data()) T(std::forward<Args>(arguments)...); + new (ptr) T(std::forward<Args>(arguments)...); + result.value = ptr; result.d->destroyer = destroy; result.d->setQObjectShared(result.value, true); # ifdef QT_SHAREDPOINTER_TRACK_POINTERS diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 203d9d8683..ade9c5e754 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -93,6 +93,7 @@ private slots: void lambdaCustomDeleter(); #endif void creating(); + void creatingCvQualified(); void creatingVariadic(); void creatingQObject(); void mixTrackingPointerCode(); @@ -1771,6 +1772,13 @@ void tst_QSharedPointer::creating() safetyCheck(); } +void tst_QSharedPointer::creatingCvQualified() +{ + auto cptr = QSharedPointer<const Data>::create(); + auto vptr = QSharedPointer<volatile Data>::create(); + auto cvptr = QSharedPointer<const volatile Data>::create(); +} + void tst_QSharedPointer::creatingVariadic() { int i = 42; |