From 720de98824cf8243df6c191a5c5d0bf98d05a142 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 23 May 2022 15:55:42 +0200 Subject: [PATCH] QDateTime::Data, QTimeZone: rule-of-five and noexcept MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeChecker noted that both QDateTime::Data and QTimeZone have incomplete rule-of-five method sets; and two of the former's methods should be noexcept. Marc tells me the copy constructor can be noexcept. Added the missing methods and noexcepts. Change-Id: I8ddaa86207320606a890e90bd2b1593ee82f5a4a Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira Reviewed-by: MÃ¥rten Nordheim --- src/corelib/time/qdatetime.cpp | 6 +++--- src/corelib/time/qdatetime.h | 7 ++++--- src/corelib/time/qtimezone.cpp | 9 +++++++++ src/corelib/time/qtimezone.h | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 189c474bfd..2bb925c60b 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -2980,7 +2980,7 @@ inline QDateTime::Data::Data(Qt::TimeSpec spec) } } -inline QDateTime::Data::Data(const Data &other) +inline QDateTime::Data::Data(const Data &other) noexcept : d(other.d) { if (!isShort()) { @@ -2997,7 +2997,7 @@ inline QDateTime::Data::Data(const Data &other) } } -inline QDateTime::Data::Data(Data &&other) +inline QDateTime::Data::Data(Data &&other) noexcept : d(other.d) { // reset the other to a short state @@ -3006,7 +3006,7 @@ inline QDateTime::Data::Data(Data &&other) other.d = dummy.d; } -inline QDateTime::Data &QDateTime::Data::operator=(const Data &other) +inline QDateTime::Data &QDateTime::Data::operator=(const Data &other) noexcept { if (d == other.d) return *this; diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h index 79ae281774..08f0a1a533 100644 --- a/src/corelib/time/qdatetime.h +++ b/src/corelib/time/qdatetime.h @@ -286,9 +286,10 @@ class Q_CORE_EXPORT QDateTime Data() noexcept; Data(Qt::TimeSpec); - Data(const Data &other); - Data(Data &&other); - Data &operator=(const Data &other); + Data(const Data &other) noexcept; + Data(Data &&other) noexcept; + Data &operator=(const Data &other) noexcept; + Data &operator=(Data &&other) noexcept { swap(other); return *this; } ~Data(); void swap(Data &other) noexcept diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index 3b357cb455..c57e9e77fb 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -386,6 +386,15 @@ QTimeZone::QTimeZone(const QTimeZone &other) { } +/*! + Move constructor of this from \a other. +*/ + +QTimeZone::QTimeZone(QTimeZone &&other) noexcept + : d(std::move(other.d)) +{ +} + /*! Destroys the time zone. */ diff --git a/src/corelib/time/qtimezone.h b/src/corelib/time/qtimezone.h index b43f1f2af2..825caf1740 100644 --- a/src/corelib/time/qtimezone.h +++ b/src/corelib/time/qtimezone.h @@ -62,6 +62,7 @@ public: const QString &abbreviation, QLocale::Territory territory = QLocale::AnyTerritory, const QString &comment = QString()); QTimeZone(const QTimeZone &other); + QTimeZone(QTimeZone &&other) noexcept; ~QTimeZone(); QTimeZone &operator=(const QTimeZone &other);