diff options
author | Giuseppe D'Angelo <[email protected]> | 2020-08-21 22:48:43 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <[email protected]> | 2020-08-26 02:19:17 +0200 |
commit | 67c3c7a29c9bebf68a367aeb85162248b58675b3 (patch) | |
tree | 13bd2fe28bc1e845b2c4ea0e8b80a683e05f265f | |
parent | 8dd50ef206f384ac781d6bb9ca5e254851531298 (diff) |
Smart pointers: port to explicit operator bool
Enough with the restricted bool trick; use the established solution.
[ChangeLog][Potentially Source-Incompatible Changes] QScopedPointer,
QSharedPointer and QWeakPointer's conversion operator towards bool
is now explicit. In some cases this may require an explicit cast
towards bool that was not needed before (notably, when returning
an object of these types from a function that actually returns bool).
Change-Id: I02b89278e75b7e7493ee7e35460504719e00f028
Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r-- | src/corelib/tools/qscopedpointer.h | 12 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 6 | ||||
-rw-r--r-- | src/opengl/qopengltextureblitter.cpp | 2 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsdialoghelpers.h | 2 |
4 files changed, 6 insertions, 16 deletions
diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index af0c0ed3368..4acec9c1f6a 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -95,7 +95,6 @@ typedef QScopedPointerObjectDeleteLater<QObject> QScopedPointerDeleteLater; template <typename T, typename Cleanup = QScopedPointerDeleter<T> > class QScopedPointer { - typedef T *QScopedPointer:: *RestrictedBool; public: explicit QScopedPointer(T *p = nullptr) noexcept : d(p) { @@ -123,17 +122,10 @@ public: return !d; } -#if defined(Q_QDOC) - inline operator bool() const + explicit operator bool() const { - return isNull() ? nullptr : &QScopedPointer::d; + return !isNull(); } -#else - operator RestrictedBool() const noexcept - { - return isNull() ? nullptr : &QScopedPointer::d; - } -#endif T *data() const noexcept { diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 235cbe144b0..35058a1c6eb 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -283,7 +283,6 @@ namespace QtSharedPointer { template <class T> class QSharedPointer { - typedef T *QSharedPointer:: *RestrictedBool; typedef QtSharedPointer::ExternalRefCountData Data; template <typename X> using IfCompatible = typename std::enable_if<std::is_convertible<X*, T*>::value, bool>::type; @@ -301,7 +300,7 @@ public: T *data() const noexcept { return value; } T *get() const noexcept { return value; } bool isNull() const noexcept { return !data(); } - operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QSharedPointer::value; } + explicit operator bool() const noexcept { return !isNull(); } bool operator !() const noexcept { return isNull(); } T &operator*() const { return *data(); } T *operator->() const noexcept { return data(); } @@ -539,7 +538,6 @@ public: template <class T> class QWeakPointer { - typedef T *QWeakPointer:: *RestrictedBool; typedef QtSharedPointer::ExternalRefCountData Data; template <typename X> using IfCompatible = typename std::enable_if<std::is_convertible<X*, T*>::value, bool>::type; @@ -554,7 +552,7 @@ public: typedef qptrdiff difference_type; bool isNull() const noexcept { return d == nullptr || d->strongref.loadRelaxed() == 0 || value == nullptr; } - operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QWeakPointer::value; } + explicit operator bool() const noexcept { return !isNull(); } bool operator !() const noexcept { return isNull(); } #if QT_DEPRECATED_SINCE(5, 14) diff --git a/src/opengl/qopengltextureblitter.cpp b/src/opengl/qopengltextureblitter.cpp index b350e8e0e3b..0f389547cc6 100644 --- a/src/opengl/qopengltextureblitter.cpp +++ b/src/opengl/qopengltextureblitter.cpp @@ -440,7 +440,7 @@ bool QOpenGLTextureBlitter::create() bool QOpenGLTextureBlitter::isCreated() const { Q_D(const QOpenGLTextureBlitter); - return d->programs[QOpenGLTextureBlitterPrivate::TEXTURE_2D].glProgram; + return !d->programs[QOpenGLTextureBlitterPrivate::TEXTURE_2D].glProgram.isNull(); } /*! diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.h b/src/plugins/platforms/windows/qwindowsdialoghelpers.h index 86867490115..55167ad36d1 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.h +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.h @@ -80,7 +80,7 @@ public: protected: QWindowsDialogHelperBase() = default; QWindowsNativeDialogBase *nativeDialog() const; - inline bool hasNativeDialog() const { return m_nativeDialog; } + inline bool hasNativeDialog() const { return !m_nativeDialog.isNull(); } void timerEvent(QTimerEvent *) override; private: |