diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2023-06-26 08:41:12 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2023-06-26 16:23:23 +0200 |
| commit | bfec2150e24d240c767d7798a761dafaf8236c7c (patch) | |
| tree | b8697adf6c567bcce169a75728139859d2fc7d86 /src/qmlcompiler/qdeferredpointer_p.h | |
| parent | d57d71dec0d860d845f0f0e9b3810c5eff3f7067 (diff) | |
QDeferred(Shared|Weak)Pointer: mark certain operation [[nodiscard]]
Mark operations [[nodiscard]] which (directly or indirectly) execute
lazyLoad(). Rationale: we should warn if deferred initialization is
triggered without using the result. Intended uses can still use
casting to void (and hopefully a comment) or [[maybe_unused]] to
indicate the code works as intended.
QUIP: QUIP-0019
Task-number: QTBUG-104168
Pick-to: 6.6 6.5
Change-Id: Iece9b36079c4af8d790b19703f81b284d507bf46
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlcompiler/qdeferredpointer_p.h')
| -rw-r--r-- | src/qmlcompiler/qdeferredpointer_p.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/qmlcompiler/qdeferredpointer_p.h b/src/qmlcompiler/qdeferredpointer_p.h index f4d8696f69..587cdd14d4 100644 --- a/src/qmlcompiler/qdeferredpointer_p.h +++ b/src/qmlcompiler/qdeferredpointer_p.h @@ -66,7 +66,7 @@ public: Q_ASSERT(!m_data.isNull() || m_factory.isNull()); } - operator QSharedPointer<T>() const + [[nodiscard]] operator QSharedPointer<T>() const { lazyLoad(); return m_data; @@ -74,8 +74,8 @@ public: operator QDeferredSharedPointer<const T>() const { return { m_data, m_factory }; } - T &operator*() const { return QSharedPointer<T>(*this).operator*(); } - T *operator->() const { return QSharedPointer<T>(*this).operator->(); } + [[nodiscard]] T &operator*() const { return QSharedPointer<T>(*this).operator*(); } + [[nodiscard]] T *operator->() const { return QSharedPointer<T>(*this).operator->(); } bool isNull() const { @@ -85,8 +85,8 @@ public: explicit operator bool() const noexcept { return !isNull(); } bool operator !() const noexcept { return isNull(); } - T *data() const { return QSharedPointer<T>(*this).data(); } - T *get() const { return data(); } + [[nodiscard]] T *data() const { return QSharedPointer<T>(*this).data(); } + [[nodiscard]] T *get() const { return data(); } friend size_t qHash(const QDeferredSharedPointer &ptr, size_t seed = 0) { @@ -188,20 +188,20 @@ public: : m_data(data), m_factory(factory) {} - operator QWeakPointer<T>() const + [[nodiscard]] operator QWeakPointer<T>() const { lazyLoad(); return m_data; } - operator QDeferredSharedPointer<T>() const + [[nodiscard]] operator QDeferredSharedPointer<T>() const { return QDeferredSharedPointer<T>(m_data.toStrongRef(), m_factory.toStrongRef()); } operator QDeferredWeakPointer<const T>() const { return {m_data, m_factory}; } - QSharedPointer<T> toStrongRef() const + [[nodiscard]] QSharedPointer<T> toStrongRef() const { return QWeakPointer<T>(*this).toStrongRef(); } |
