summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdebug.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-06-04 12:43:16 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-06-06 22:25:58 +0200
commitac608b7bd2fc3876d1a521cb3542b6b56133fd0f (patch)
treee8ddabe0144b58815b5052a3d9af4178b3af6238 /src/corelib/io/qdebug.h
parent8c9e41cc7803929aafb200c44276f4059b6ead6c (diff)
QDebug: add nothrow move special member functions
This requires making QDebugStateSaver hold QDebug::Stream directly, not QDebug by reference, as the referenced object will have been moved from when ~QDebugStateSaver executes. The stream object, however, will still be around. Change-Id: I0ca2eb60cb9b68ea3835d9a9ff5e295d9b1c5fb5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/io/qdebug.h')
-rw-r--r--src/corelib/io/qdebug.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 889fb6b571..421c5d933b 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -65,6 +65,7 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QDebug
{
friend class QMessageLogger;
+ friend class QDebugStateSaver;
friend class QDebugStateSaverPrivate;
struct Stream {
enum { VerbosityShift = 29, VerbosityMask = 0x7 };
@@ -114,7 +115,10 @@ public:
inline QDebug(QString *string) : stream(new Stream(string)) {}
inline QDebug(QtMsgType t) : stream(new Stream(t)) {}
inline 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; }
~QDebug();
inline void swap(QDebug &other) noexcept { qSwap(stream, other.stream); }
@@ -203,10 +207,7 @@ public:
inline QDebug &QDebug::operator=(const QDebug &other)
{
- if (this != &other) {
- QDebug copy(other);
- qSwap(stream, copy.stream);
- }
+ QDebug{other}.swap(*this);
return *this;
}