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 <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2023-06-21 21:15:31 +02:00
parent 574a47dd5a
commit 01e1dc273d
10 changed files with 14 additions and 14 deletions

View File

@ -37,7 +37,7 @@ Q_CORE_EXPORT bool qEnableNtfsPermissionChecks() noexcept;
Q_CORE_EXPORT bool qDisableNtfsPermissionChecks() noexcept; Q_CORE_EXPORT bool qDisableNtfsPermissionChecks() noexcept;
Q_CORE_EXPORT bool qAreNtfsPermissionChecksEnabled() noexcept; Q_CORE_EXPORT bool qAreNtfsPermissionChecksEnabled() noexcept;
class [[nodiscard]] QNtfsPermissionCheckGuard class QNtfsPermissionCheckGuard
{ {
Q_DISABLE_COPY_MOVE(QNtfsPermissionCheckGuard) Q_DISABLE_COPY_MOVE(QNtfsPermissionCheckGuard)
public: public:

View File

@ -439,7 +439,7 @@ inline QBindingStorage *qGetBindingStorage(QObject *o)
Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *); Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *);
#endif #endif
class [[nodiscard]] QSignalBlocker class QSignalBlocker
{ {
public: public:
Q_NODISCARD_CTOR Q_NODISCARD_CTOR

View File

@ -53,7 +53,7 @@ Q_CORE_EXPORT void beginPropertyUpdateGroup();
Q_CORE_EXPORT void endPropertyUpdateGroup(); Q_CORE_EXPORT void endPropertyUpdateGroup();
} }
class [[nodiscard]] QScopedPropertyUpdateGroup class QScopedPropertyUpdateGroup
{ {
Q_DISABLE_COPY_MOVE(QScopedPropertyUpdateGroup) Q_DISABLE_COPY_MOVE(QScopedPropertyUpdateGroup)
public: public:
@ -287,7 +287,7 @@ private:
}; };
template <typename Functor> template <typename Functor>
class [[nodiscard]] QPropertyChangeHandler : public QPropertyObserver class QPropertyChangeHandler : public QPropertyObserver
{ {
Functor m_handler; Functor m_handler;
public: public:
@ -314,7 +314,7 @@ public:
} }
}; };
class [[nodiscard]] QPropertyNotifier : public QPropertyObserver class QPropertyNotifier : public QPropertyObserver
{ {
std::function<void()> m_handler; std::function<void()> m_handler;
public: public:

View File

@ -94,7 +94,7 @@ struct QPropertyBindingDataPointer
} }
}; };
struct [[nodiscard]] QPropertyObserverNodeProtector struct QPropertyObserverNodeProtector
{ {
Q_DISABLE_COPY_MOVE(QPropertyObserverNodeProtector) Q_DISABLE_COPY_MOVE(QPropertyObserverNodeProtector)

View File

@ -216,7 +216,7 @@ bool QRecursiveMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT
#endif #endif
template <typename Mutex> template <typename Mutex>
class [[nodiscard]] QMutexLocker class QMutexLocker
{ {
public: public:
Q_NODISCARD_CTOR Q_NODISCARD_CTOR
@ -313,7 +313,7 @@ private:
class QRecursiveMutex : public QMutex {}; class QRecursiveMutex : public QMutex {};
template <typename Mutex> template <typename Mutex>
class [[nodiscard]] QMutexLocker class QMutexLocker
{ {
public: public:
Q_NODISCARD_CTOR Q_NODISCARD_CTOR

View File

@ -28,7 +28,7 @@ QT_BEGIN_NAMESPACE
Locks 2 mutexes in a defined order, avoiding a recursive lock if Locks 2 mutexes in a defined order, avoiding a recursive lock if
we're trying to lock the same mutex twice. we're trying to lock the same mutex twice.
*/ */
class [[nodiscard]] QOrderedMutexLocker class QOrderedMutexLocker
{ {
public: public:
Q_NODISCARD_CTOR Q_NODISCARD_CTOR
@ -120,7 +120,7 @@ private:
#else #else
class [[nodiscard]] QOrderedMutexLocker class QOrderedMutexLocker
{ {
public: public:
Q_DISABLE_COPY(QOrderedMutexLocker) Q_DISABLE_COPY(QOrderedMutexLocker)

View File

@ -61,7 +61,7 @@ bool QSemaphore::tryAcquire(int n, int timeout)
} }
#endif #endif
class [[nodiscard]] QSemaphoreReleaser class QSemaphoreReleaser
{ {
public: public:
Q_NODISCARD_CTOR Q_NODISCARD_CTOR

View File

@ -23,7 +23,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
template <typename T> template <typename T>
class [[nodiscard]] QAtomicScopedValueRollback class QAtomicScopedValueRollback
{ {
std::atomic<T> &m_atomic; std::atomic<T> &m_atomic;
T m_value; T m_value;

View File

@ -9,7 +9,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
template <typename T> template <typename T>
class [[nodiscard]] QScopedValueRollback class QScopedValueRollback
{ {
public: public:
Q_NODISCARD_CTOR Q_NODISCARD_CTOR

View File

@ -13,7 +13,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
template <typename F> template <typename F>
class [[nodiscard]] QScopeGuard class QScopeGuard
{ {
public: public:
Q_NODISCARD_CTOR Q_NODISCARD_CTOR