From 83a156cd1139950dd333b3151d16a86ce19b06d2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 13 Jun 2023 09:34:12 +0200 Subject: [PATCH] QAppleRefCounted hierarchy: mark ctors [[nodiscard]] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They're RAII/smart pointer-like classes. QUIP-0019 says such classes' ctors should be marked [[nodiscard]]. Pick-to: 6.6 Task-number: QTBUG-104164 Change-Id: I830badfa56fbdfb5819866f67b84cd4fa93acbde Reviewed-by: Tor Arne Vestbø --- src/corelib/kernel/qcore_mac_p.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index 502b9746be..f69eb693a3 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -85,15 +85,18 @@ template class QAppleRefCounted { public: - QAppleRefCounted() : value() {} - QAppleRefCounted(const T &t) : value(t) {} - QAppleRefCounted(T &&t) noexcept(std::is_nothrow_move_constructible::value) + Q_NODISCARD_CTOR QAppleRefCounted() : value() {} + Q_NODISCARD_CTOR QAppleRefCounted(const T &t) : value(t) {} + Q_NODISCARD_CTOR QAppleRefCounted(T &&t) + noexcept(std::is_nothrow_move_constructible::value) : value(std::move(t)) {} - QAppleRefCounted(QAppleRefCounted &&other) + Q_NODISCARD_CTOR QAppleRefCounted(QAppleRefCounted &&other) noexcept(std::is_nothrow_move_assignable::value && std::is_nothrow_move_constructible::value) : value(std::exchange(other.value, T())) {} - QAppleRefCounted(const QAppleRefCounted &other) : value(other.value) { if (value) RetainFunction(value); } + Q_NODISCARD_CTOR QAppleRefCounted(const QAppleRefCounted &other) + : value(other.value) + { if (value) RetainFunction(value); } ~QAppleRefCounted() { if (value) ReleaseFunction(value); } operator T() const { return value; } void swap(QAppleRefCounted &other) noexcept(noexcept(qSwap(value, other.value))) @@ -148,7 +151,7 @@ class QCFType : public QAppleRefCounted using Base = QAppleRefCounted; public: using Base::Base; - explicit QCFType(CFTypeRef r) : Base(static_cast(r)) {} + Q_NODISCARD_CTOR explicit QCFType(CFTypeRef r) : Base(static_cast(r)) {} template X as() const { return reinterpret_cast(this->value); } static QCFType constructFromGet(const T &t) { @@ -170,9 +173,9 @@ class Q_CORE_EXPORT QCFString : public QCFType { public: using QCFType::QCFType; - inline QCFString(const QString &str) : QCFType(0), string(str) {} - inline QCFString(const CFStringRef cfstr = 0) : QCFType(cfstr) {} - inline QCFString(const QCFType &other) : QCFType(other) {} + Q_NODISCARD_CTOR QCFString(const QString &str) : QCFType(0), string(str) {} + Q_NODISCARD_CTOR QCFString(const CFStringRef cfstr = 0) : QCFType(cfstr) {} + Q_NODISCARD_CTOR QCFString(const QCFType &other) : QCFType(other) {} operator QString() const; operator CFStringRef() const;