From 01e1dc273d0fd95e4e4f57ae0af1862196f72bd6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jun 2023 21:15:31 +0200 Subject: [PATCH] Remove all class-level [[nodiscard]] from the code-base A class-level [[nodiscard]] used to be the only way to get a waring for code such as QMutexLocker(&mutex); with original C++17 means. This was because a few of our compilers would warn about the presence of [[nodiscard]] on ctors, which is really the semantics we want: we don't want to prevent users from passing QMutexLocker out of functions and users of those functions from ignoring the return value, if they so choose. That should be the choice of the author of the function returning such types, not ours. So QUIP-0019 makes class-level [[nodiscard]] conditional on proper rationale in the user docs (or the commit message in case of private API). Since none of the existing uses really strikes this author as particularly convincing, remove them all. All these classes have gotten Q_NODISCARD_CTOR on all their ctors, so we continue to provide the same true positive warnings, minus the false positives when returning from functions, at least on the majority of compilers (and it's not as if all compilers interpreted a class-level [[nodiscard]] as a trigger to warn on the initial example of this commit message). Task-number: QTBUG-104164 Pick-to: 6.6 Change-Id: I163356486e7c80f9d69bf67023010a88233fe662 Reviewed-by: Thiago Macieira --- src/corelib/io/qfile.h | 2 +- src/corelib/kernel/qobject.h | 2 +- src/corelib/kernel/qproperty.h | 6 +++--- src/corelib/kernel/qproperty_p.h | 2 +- src/corelib/thread/qmutex.h | 4 ++-- src/corelib/thread/qorderedmutexlocker_p.h | 4 ++-- src/corelib/thread/qsemaphore.h | 2 +- src/corelib/tools/qatomicscopedvaluerollback_p.h | 2 +- src/corelib/tools/qscopedvaluerollback.h | 2 +- src/corelib/tools/qscopeguard.h | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/corelib/io/qfile.h b/src/corelib/io/qfile.h index 1153ba7686..839a2b51fe 100644 --- a/src/corelib/io/qfile.h +++ b/src/corelib/io/qfile.h @@ -37,7 +37,7 @@ Q_CORE_EXPORT bool qEnableNtfsPermissionChecks() noexcept; Q_CORE_EXPORT bool qDisableNtfsPermissionChecks() noexcept; Q_CORE_EXPORT bool qAreNtfsPermissionChecksEnabled() noexcept; -class [[nodiscard]] QNtfsPermissionCheckGuard +class QNtfsPermissionCheckGuard { Q_DISABLE_COPY_MOVE(QNtfsPermissionCheckGuard) public: diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 3d1c102fc5..88ba5318a1 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -439,7 +439,7 @@ inline QBindingStorage *qGetBindingStorage(QObject *o) Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *); #endif -class [[nodiscard]] QSignalBlocker +class QSignalBlocker { public: Q_NODISCARD_CTOR diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index 3ed977d16e..070907c608 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -53,7 +53,7 @@ Q_CORE_EXPORT void beginPropertyUpdateGroup(); Q_CORE_EXPORT void endPropertyUpdateGroup(); } -class [[nodiscard]] QScopedPropertyUpdateGroup +class QScopedPropertyUpdateGroup { Q_DISABLE_COPY_MOVE(QScopedPropertyUpdateGroup) public: @@ -287,7 +287,7 @@ private: }; template -class [[nodiscard]] QPropertyChangeHandler : public QPropertyObserver +class QPropertyChangeHandler : public QPropertyObserver { Functor m_handler; public: @@ -314,7 +314,7 @@ public: } }; -class [[nodiscard]] QPropertyNotifier : public QPropertyObserver +class QPropertyNotifier : public QPropertyObserver { std::function m_handler; public: diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index 9946482d7f..277767b3c0 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -94,7 +94,7 @@ struct QPropertyBindingDataPointer } }; -struct [[nodiscard]] QPropertyObserverNodeProtector +struct QPropertyObserverNodeProtector { Q_DISABLE_COPY_MOVE(QPropertyObserverNodeProtector) diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 7a6bd1a3ba..496d0ea502 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -216,7 +216,7 @@ bool QRecursiveMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT #endif template -class [[nodiscard]] QMutexLocker +class QMutexLocker { public: Q_NODISCARD_CTOR @@ -313,7 +313,7 @@ private: class QRecursiveMutex : public QMutex {}; template -class [[nodiscard]] QMutexLocker +class QMutexLocker { public: Q_NODISCARD_CTOR diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h index 43985a3faa..fb2e223e01 100644 --- a/src/corelib/thread/qorderedmutexlocker_p.h +++ b/src/corelib/thread/qorderedmutexlocker_p.h @@ -28,7 +28,7 @@ QT_BEGIN_NAMESPACE Locks 2 mutexes in a defined order, avoiding a recursive lock if we're trying to lock the same mutex twice. */ -class [[nodiscard]] QOrderedMutexLocker +class QOrderedMutexLocker { public: Q_NODISCARD_CTOR @@ -120,7 +120,7 @@ private: #else -class [[nodiscard]] QOrderedMutexLocker +class QOrderedMutexLocker { public: Q_DISABLE_COPY(QOrderedMutexLocker) diff --git a/src/corelib/thread/qsemaphore.h b/src/corelib/thread/qsemaphore.h index 0b9db83471..28f3f62664 100644 --- a/src/corelib/thread/qsemaphore.h +++ b/src/corelib/thread/qsemaphore.h @@ -61,7 +61,7 @@ bool QSemaphore::tryAcquire(int n, int timeout) } #endif -class [[nodiscard]] QSemaphoreReleaser +class QSemaphoreReleaser { public: Q_NODISCARD_CTOR diff --git a/src/corelib/tools/qatomicscopedvaluerollback_p.h b/src/corelib/tools/qatomicscopedvaluerollback_p.h index e70889c288..67299327fc 100644 --- a/src/corelib/tools/qatomicscopedvaluerollback_p.h +++ b/src/corelib/tools/qatomicscopedvaluerollback_p.h @@ -23,7 +23,7 @@ QT_BEGIN_NAMESPACE template -class [[nodiscard]] QAtomicScopedValueRollback +class QAtomicScopedValueRollback { std::atomic &m_atomic; T m_value; diff --git a/src/corelib/tools/qscopedvaluerollback.h b/src/corelib/tools/qscopedvaluerollback.h index 6e724886f4..0ae3efd0c0 100644 --- a/src/corelib/tools/qscopedvaluerollback.h +++ b/src/corelib/tools/qscopedvaluerollback.h @@ -9,7 +9,7 @@ QT_BEGIN_NAMESPACE template -class [[nodiscard]] QScopedValueRollback +class QScopedValueRollback { public: Q_NODISCARD_CTOR diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h index 0d756ebbd9..9be6634cc8 100644 --- a/src/corelib/tools/qscopeguard.h +++ b/src/corelib/tools/qscopeguard.h @@ -13,7 +13,7 @@ QT_BEGIN_NAMESPACE template -class [[nodiscard]] QScopeGuard +class QScopeGuard { public: Q_NODISCARD_CTOR