summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qpointer.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-09-28 14:19:22 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-10-05 19:40:02 +0200
commitb6c73356355de752755dc54214818dac6d0a8694 (patch)
tree4d1f45da39df86db337d0c6d4911f08f8261f973 /src/corelib/kernel/qpointer.h
parentfc9d9c1a2b72bd6ff6e0300744dcead2a19a804c (diff)
QPointer: fix missing converting move-assignment operator
When 6c504f2519e1180dbcfd77d5bb08b0db9742eeaa 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>
Diffstat (limited to 'src/corelib/kernel/qpointer.h')
-rw-r--r--src/corelib/kernel/qpointer.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h
index 7138258050..a279576493 100644
--- a/src/corelib/kernel/qpointer.h
+++ b/src/corelib/kernel/qpointer.h
@@ -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;
}