QPointer: fix missing converting move-assignment operator

When 6c504f2519 added the conversion
copy-constructor to fix an ambiguity, its commit message argued at
length why a move-assignment conversion operator was not possible. But
we actually have the existing converting move and copy ctors, so we
can just use copy-and-swap and move-and-swap, so do that.

As a drive-by, make the copy-assignment operator use copy-and-swap.

[ChangeLog][QtCore][QPointer] Added missing converting move-assignment
operator. This is forwards-compatible with Qt 6.6.0: compiling against
6.6.0 will just use the lvalue overload.

This is BC and SC, forwards and backwards (inline code, and going back
in time will just use the lvalue overload), so picking to 6.6.

Pick-to: 6.6
Change-Id: Ibbefb0927c08d8c716a952c6c592a02df2a89008
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2023-09-28 14:19:22 +02:00
parent fc9d9c1a2b
commit b6c7335635
2 changed files with 19 additions and 1 deletions

View File

@ -122,6 +122,17 @@
is convertible to \c{T*}.
*/
/*!
\fn template <class T> template <class X> QPointer<T> &QPointer<T>::operator=(QPointer<X> &&other)
\since 6.6.1
Conversion move-assignment operator. Makes this guarded pointer guard the
same object guarded by \a other and resets \a other to nullptr.
\note This operator participates in overload resolution only if \c{X*}
is convertible to \c{T*}.
*/
/*!
\fn template <class T> void QPointer<T>::swap(QPointer &other)
\since 5.6

View File

@ -46,7 +46,14 @@ public:
template <typename X, if_convertible<X> = true>
QPointer &operator=(const QPointer<X> &other)
{
wp.assign(other.data());
QPointer(other).swap(*this);
return *this;
}
template <typename X, if_convertible<X> = true>
QPointer &operator=(QPointer<X> &&other)
{
QPointer(std::move(other)).swap(*this);
return *this;
}