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:
parent
574a47dd5a
commit
01e1dc273d
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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 <typename Functor>
|
||||
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<void()> m_handler;
|
||||
public:
|
||||
|
@ -94,7 +94,7 @@ struct QPropertyBindingDataPointer
|
||||
}
|
||||
};
|
||||
|
||||
struct [[nodiscard]] QPropertyObserverNodeProtector
|
||||
struct QPropertyObserverNodeProtector
|
||||
{
|
||||
Q_DISABLE_COPY_MOVE(QPropertyObserverNodeProtector)
|
||||
|
||||
|
@ -216,7 +216,7 @@ bool QRecursiveMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT
|
||||
#endif
|
||||
|
||||
template <typename Mutex>
|
||||
class [[nodiscard]] QMutexLocker
|
||||
class QMutexLocker
|
||||
{
|
||||
public:
|
||||
Q_NODISCARD_CTOR
|
||||
@ -313,7 +313,7 @@ private:
|
||||
class QRecursiveMutex : public QMutex {};
|
||||
|
||||
template <typename Mutex>
|
||||
class [[nodiscard]] QMutexLocker
|
||||
class QMutexLocker
|
||||
{
|
||||
public:
|
||||
Q_NODISCARD_CTOR
|
||||
|
@ -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)
|
||||
|
@ -61,7 +61,7 @@ bool QSemaphore::tryAcquire(int n, int timeout)
|
||||
}
|
||||
#endif
|
||||
|
||||
class [[nodiscard]] QSemaphoreReleaser
|
||||
class QSemaphoreReleaser
|
||||
{
|
||||
public:
|
||||
Q_NODISCARD_CTOR
|
||||
|
@ -23,7 +23,7 @@
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
template <typename T>
|
||||
class [[nodiscard]] QAtomicScopedValueRollback
|
||||
class QAtomicScopedValueRollback
|
||||
{
|
||||
std::atomic<T> &m_atomic;
|
||||
T m_value;
|
||||
|
@ -9,7 +9,7 @@
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
template <typename T>
|
||||
class [[nodiscard]] QScopedValueRollback
|
||||
class QScopedValueRollback
|
||||
{
|
||||
public:
|
||||
Q_NODISCARD_CTOR
|
||||
|
@ -13,7 +13,7 @@
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
template <typename F>
|
||||
class [[nodiscard]] QScopeGuard
|
||||
class QScopeGuard
|
||||
{
|
||||
public:
|
||||
Q_NODISCARD_CTOR
|
||||
|
Loading…
Reference in New Issue
Block a user