From 1a6e1660b175ba1c5c203746daeae03734e40a87 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jun 2023 15:00:43 +0200 Subject: [PATCH] QWeakPointer: mark lock() [[nodiscard]] The lock() function, added for std::weak_ptr compatibility, sounds like QMutex::lock(), but is, in fact, a const function. QUIP-0019 says such functions must be marked [[nodiscard]]. For symmetry, also mark toStrongRef() and toWeakRef() as [[nodiscard]]. Change-Id: Ifb6e447d2cd96fedd9a78decdfac6bc57c1d282a Reviewed-by: Thiago Macieira (cherry picked from commit 81d357ff8a7af8704ba5657caef04f28e7099625) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qsharedpointer_impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index dd6bd22fca8..ac9bd2d77eb 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -383,7 +383,7 @@ public: inline void clear() { QSharedPointer copy; swap(copy); } - QWeakPointer toWeakRef() const; + [[nodiscard]] QWeakPointer toWeakRef() const; template static QSharedPointer create(Args && ...arguments) @@ -615,9 +615,9 @@ public: inline void clear() { *this = QWeakPointer(); } - inline QSharedPointer toStrongRef() const { return QSharedPointer(*this); } + [[nodiscard]] QSharedPointer toStrongRef() const { return QSharedPointer(*this); } // std::weak_ptr compatibility: - inline QSharedPointer lock() const { return toStrongRef(); } + [[nodiscard]] QSharedPointer lock() const { return toStrongRef(); } template bool operator==(const QWeakPointer &o) const noexcept