summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-01-03 17:18:02 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-10-03 11:47:17 +0200
commit889d40ebe2d9d0e92caea2749608720f7c088173 (patch)
treea68214fbf5a0dc9b1488e4ae79a499dabc1cc445 /src/corelib/io
parent990e2e4fb8ef546b89b5e83e659771edd5b4ed3e (diff)
Centralize the implementation of move assignment operators
At the moment we have two main strategies for dealing with move assignment in Qt: 1) move-and-swap, used by "containers" (in the broad sense): containers, but also smart pointers and similar classes that can hold user-defined types; 2) pure swap, used by containers that hold only memory (e.g. QString, QByteArray, ...) as well as most implicitly shared datatypes. Given the fact that a move assignment operator's code is just boilerplate (whether it's move-and-swap or pure swap), provide two _strictly internal_ macros to help write them, and apply the macros across corelib and gui, porting away from the hand-rolled implementations. The rule of thumb when porting to the new macros is: * Try to stick to the existing code behavior, unless broken * if changing, then follow this checklist: * if the class does not have a move constructor => pure swap (but consider ADDING a move constructor, if possible!) * if the class does have a move constructor, try to follow the criteria above, namely: * if the class holds only memory, pure swap; * if the class may hold anything else but memory (file handles, etc.), then move and swap. Noteworthy details: * some operators planned to be removed in Qt 6 were not ported; * as drive-by, some move constructors were simplified to be using qExchange(); others were outright broken and got fixed; * some contained some more interesting code and were not touched. Change-Id: Idaab3489247dcbabb6df3fa1e5286b69e1d372e9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdebug.h3
-rw-r--r--src/corelib/io/qdir.h2
-rw-r--r--src/corelib/io/qfileinfo.h2
-rw-r--r--src/corelib/io/qprocess.h2
-rw-r--r--src/corelib/io/qstorageinfo.h2
-rw-r--r--src/corelib/io/qurl.h3
-rw-r--r--src/corelib/io/qurlquery.h2
7 files changed, 7 insertions, 9 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 45af766db9..3498351639 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -102,8 +102,7 @@ public:
QDebug(const QDebug &o) : stream(o.stream) { ++stream->ref; }
QDebug(QDebug &&other) noexcept : stream{qExchange(other.stream, nullptr)} {}
inline QDebug &operator=(const QDebug &other);
- QDebug &operator=(QDebug &&other) noexcept
- { QDebug{std::move(other)}.swap(*this); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QDebug)
~QDebug();
inline void swap(QDebug &other) noexcept { qSwap(stream, other.stream); }
diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h
index 8b8aa05223..92b3faee7e 100644
--- a/src/corelib/io/qdir.h
+++ b/src/corelib/io/qdir.h
@@ -121,7 +121,7 @@ public:
~QDir();
QDir &operator=(const QDir &);
- QDir &operator=(QDir &&other) noexcept { swap(other); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QDir)
void swap(QDir &other) noexcept
{ qSwap(d_ptr, other.d_ptr); }
diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h
index e578848be0..344c16abf8 100644
--- a/src/corelib/io/qfileinfo.h
+++ b/src/corelib/io/qfileinfo.h
@@ -79,7 +79,7 @@ public:
~QFileInfo();
QFileInfo &operator=(const QFileInfo &fileinfo);
- QFileInfo &operator=(QFileInfo &&other) noexcept { swap(other); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFileInfo)
void swap(QFileInfo &other) noexcept
{ qSwap(d_ptr, other.d_ptr); }
diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h
index 4ed01197b3..cfa86c8508 100644
--- a/src/corelib/io/qprocess.h
+++ b/src/corelib/io/qprocess.h
@@ -68,7 +68,7 @@ public:
QProcessEnvironment();
QProcessEnvironment(const QProcessEnvironment &other);
~QProcessEnvironment();
- QProcessEnvironment &operator=(QProcessEnvironment && other) noexcept { swap(other); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QProcessEnvironment)
QProcessEnvironment &operator=(const QProcessEnvironment &other);
void swap(QProcessEnvironment &other) noexcept { qSwap(d, other.d); }
diff --git a/src/corelib/io/qstorageinfo.h b/src/corelib/io/qstorageinfo.h
index 237e68d2a1..ec95ea3b23 100644
--- a/src/corelib/io/qstorageinfo.h
+++ b/src/corelib/io/qstorageinfo.h
@@ -62,7 +62,7 @@ public:
~QStorageInfo();
QStorageInfo &operator=(const QStorageInfo &other);
- QStorageInfo &operator=(QStorageInfo &&other) noexcept { swap(other); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QStorageInfo)
inline void swap(QStorageInfo &other) noexcept
{ qSwap(d, other.d); }
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index c4903ebce4..c13b21ef44 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -184,8 +184,7 @@ public:
#endif
QUrl(QUrl &&other) noexcept : d(other.d)
{ other.d = nullptr; }
- inline QUrl &operator=(QUrl &&other) noexcept
- { qSwap(d, other.d); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUrl)
~QUrl();
inline void swap(QUrl &other) noexcept { qSwap(d, other.d); }
diff --git a/src/corelib/io/qurlquery.h b/src/corelib/io/qurlquery.h
index c1917a4bf5..de474924ce 100644
--- a/src/corelib/io/qurlquery.h
+++ b/src/corelib/io/qurlquery.h
@@ -67,7 +67,7 @@ public:
QUrlQuery(const QUrlQuery &other);
QUrlQuery &operator=(const QUrlQuery &other);
- QUrlQuery &operator=(QUrlQuery &&other) noexcept { swap(other); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUrlQuery)
~QUrlQuery();
bool operator==(const QUrlQuery &other) const;