summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qcompilerdetection.h9
-rw-r--r--src/corelib/thread/qmutex.h3
2 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index 5baa69270e..d52722afb7 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -970,6 +970,15 @@
#define Q_DECL_ENUMERATOR_DEPRECATED Q_DECL_DEPRECATED
#define Q_DECL_ENUMERATOR_DEPRECATED_X(x) Q_DECL_DEPRECATED_X(x)
+// [[nodiscard]] constructor
+#ifndef Q_NODISCARD_CTOR
+# if __has_cpp_attribute(nodiscard) >= 201907L
+# define Q_NODISCARD_CTOR [[nodiscard]]
+# else
+# define Q_NODISCARD_CTOR
+# endif
+#endif
+
/*
* Fallback macros to certain compiler features
*/
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index af77f556fd..407473c799 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -231,6 +231,7 @@ template <typename Mutex>
class [[nodiscard]] QMutexLocker
{
public:
+ Q_NODISCARD_CTOR
inline explicit QMutexLocker(Mutex *mutex) QT_MUTEX_LOCK_NOEXCEPT
{
m_mutex = mutex;
@@ -240,6 +241,7 @@ public:
}
}
+ Q_NODISCARD_CTOR
inline QMutexLocker(QMutexLocker &&other) noexcept
: m_mutex(std::exchange(other.m_mutex, nullptr)),
m_isLocked(std::exchange(other.m_isLocked, false))
@@ -326,6 +328,7 @@ template <typename Mutex>
class [[nodiscard]] QMutexLocker
{
public:
+ Q_NODISCARD_CTOR
inline explicit QMutexLocker(Mutex *) noexcept {}
inline ~QMutexLocker() noexcept {}