diff options
Diffstat (limited to 'src/corelib/tools/qtaggedpointer.h')
-rw-r--r-- | src/corelib/tools/qtaggedpointer.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/corelib/tools/qtaggedpointer.h b/src/corelib/tools/qtaggedpointer.h index 504645993a..a08912c4a5 100644 --- a/src/corelib/tools/qtaggedpointer.h +++ b/src/corelib/tools/qtaggedpointer.h @@ -72,11 +72,30 @@ public: return !isNull(); } - QTaggedPointer &operator=(T *other) noexcept +#ifdef Q_QDOC + QTaggedPointer &operator=(T *other) noexcept; +#else + // Disables the usage of `ptr = {}`, which would go through this operator + // (rather than using the implicitly-generated assignment operator). + // The operators have different semantics: the ones here leave the tag intact, + // the implicitly-generated one overwrites it. + template <typename U, + std::enable_if_t<std::is_convertible_v<U *, T *>, bool> = false> + QTaggedPointer &operator=(U *other) noexcept + { + T *otherT = other; + d = reinterpret_cast<quintptr>(otherT) | (d & tagMask()); + return *this; + } + + template <typename U, + std::enable_if_t<std::is_null_pointer_v<U>, bool> = false> + QTaggedPointer &operator=(U) noexcept { - d = reinterpret_cast<quintptr>(other) | (d & tagMask()); + d = reinterpret_cast<quintptr>(static_cast<T *>(nullptr)) | (d & tagMask()); return *this; } +#endif static constexpr Tag maximumTag() noexcept { |