From e7c456d3395826a427b863c0cfc8c60aa4ab7d6c Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Sun, 11 Oct 2020 16:51:22 +0200 Subject: [PATCH] Cleanup qshareddata.h noexcept status Set noexcept on functions where it applies. Change-Id: I5efa632bd1652e1215e9c6d3b06dc40c948420d3 Reviewed-by: Thiago Macieira --- src/corelib/tools/qshareddata.h | 90 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index ffd4d4cf0b..1484aafe25 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -72,24 +72,27 @@ public: inline T &operator*() { detach(); return *d; } inline const T &operator*() const { return *d; } inline T *operator->() { detach(); return d; } - inline const T *operator->() const { return d; } + inline const T *operator->() const noexcept { return d; } inline operator T *() { detach(); return d; } - inline operator const T *() const { return d; } + inline operator const T *() const noexcept { return d; } inline T *data() { detach(); return d; } inline T *get() { detach(); return d; } - inline const T *data() const { return d; } - inline const T *get() const { return d; } - inline const T *constData() const { return d; } + inline const T *data() const noexcept { return d; } + inline const T *get() const noexcept { return d; } + inline const T *constData() const noexcept { return d; } - inline bool operator==(const QSharedDataPointer &other) const { return d == other.d; } - inline bool operator!=(const QSharedDataPointer &other) const { return d != other.d; } + inline bool operator==(const QSharedDataPointer &other) const noexcept { return d == other.d; } + inline bool operator!=(const QSharedDataPointer &other) const noexcept { return d != other.d; } - inline QSharedDataPointer() { d = nullptr; } + inline QSharedDataPointer() noexcept : d(nullptr) { } inline ~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; } - explicit QSharedDataPointer(T *data) noexcept; - inline QSharedDataPointer(const QSharedDataPointer &o) : d(o.d) { if (d) d->ref.ref(); } - inline QSharedDataPointer & operator=(const QSharedDataPointer &o) { + explicit inline QSharedDataPointer(T *data) noexcept : d(data) + { if (d) d->ref.ref(); } + inline QSharedDataPointer(const QSharedDataPointer &o) noexcept : d(o.d) + { if (d) d->ref.ref(); } + inline QSharedDataPointer &operator=(const QSharedDataPointer &o) noexcept + { if (o.d != d) { if (o.d) o.d->ref.ref(); @@ -100,7 +103,8 @@ public: } return *this; } - inline QSharedDataPointer &operator=(T *o) { + inline QSharedDataPointer &operator=(T *o) noexcept + { if (o != d) { if (o) o->ref.ref(); @@ -114,7 +118,7 @@ public: QSharedDataPointer(QSharedDataPointer &&o) noexcept : d(qExchange(o.d, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSharedDataPointer) - inline bool operator!() const { return !d; } + inline bool operator!() const noexcept { return !d; } inline void swap(QSharedDataPointer &other) noexcept { qSwap(d, other.d); } @@ -128,13 +132,13 @@ private: T *d; }; -template inline bool operator==(std::nullptr_t p1, const QSharedDataPointer &p2) +template inline bool operator==(std::nullptr_t p1, const QSharedDataPointer &p2) noexcept { Q_UNUSED(p1); return !p2; } -template inline bool operator==(const QSharedDataPointer &p1, std::nullptr_t p2) +template inline bool operator==(const QSharedDataPointer &p1, std::nullptr_t p2) noexcept { Q_UNUSED(p2); return !p1; @@ -147,16 +151,16 @@ public: typedef T *pointer; inline T &operator*() const { return *d; } - inline T *operator->() { return d; } - inline T *operator->() const { return d; } - inline T *data() const { return d; } - inline T *get() const { return d; } - inline const T *constData() const { return d; } - inline T *take() { T *x = d; d = nullptr; return x; } + inline T *operator->() noexcept { return d; } + inline T *operator->() const noexcept { return d; } + inline T *data() const noexcept { return d; } + inline T *get() const noexcept { return d; } + inline const T *constData() const noexcept { return d; } + inline T *take() noexcept { T *x = d; d = nullptr; return x; } inline void detach() { if (d && d->ref.loadRelaxed() != 1) detach_helper(); } - inline void reset() + inline void reset() noexcept { if(d && !d->ref.deref()) delete d; @@ -164,21 +168,23 @@ public: d = nullptr; } - inline operator bool () const { return d != nullptr; } + inline operator bool () const noexcept { return d != nullptr; } - inline bool operator==(const QExplicitlySharedDataPointer &other) const { return d == other.d; } - inline bool operator!=(const QExplicitlySharedDataPointer &other) const { return d != other.d; } - inline bool operator==(const T *ptr) const { return d == ptr; } - inline bool operator!=(const T *ptr) const { return d != ptr; } + inline bool operator==(const QExplicitlySharedDataPointer &other) const noexcept { return d == other.d; } + inline bool operator!=(const QExplicitlySharedDataPointer &other) const noexcept { return d != other.d; } + inline bool operator==(const T *ptr) const noexcept { return d == ptr; } + inline bool operator!=(const T *ptr) const noexcept { return d != ptr; } - inline QExplicitlySharedDataPointer() { d = nullptr; } + inline QExplicitlySharedDataPointer() noexcept : d(nullptr) { } inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; } - explicit QExplicitlySharedDataPointer(T *data) noexcept; - inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer &o) : d(o.d) { if (d) d->ref.ref(); } + explicit inline QExplicitlySharedDataPointer(T *data) noexcept : d(data) + { if (d) d->ref.ref(); } + inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer &o) noexcept : d(o.d) + { if (d) d->ref.ref(); } template - inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer &o) + inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer &o) noexcept #ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST : d(static_cast(o.data())) #else @@ -189,7 +195,8 @@ public: d->ref.ref(); } - inline QExplicitlySharedDataPointer & operator=(const QExplicitlySharedDataPointer &o) { + inline QExplicitlySharedDataPointer &operator=(const QExplicitlySharedDataPointer &o) noexcept + { if (o.d != d) { if (o.d) o.d->ref.ref(); @@ -200,7 +207,8 @@ public: } return *this; } - inline QExplicitlySharedDataPointer &operator=(T *o) { + inline QExplicitlySharedDataPointer &operator=(T *o) noexcept + { if (o != d) { if (o) o->ref.ref(); @@ -214,7 +222,7 @@ public: inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) noexcept : d(qExchange(o.d, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QExplicitlySharedDataPointer) - inline bool operator!() const { return !d; } + inline bool operator!() const noexcept { return !d; } inline void swap(QExplicitlySharedDataPointer &other) noexcept { qSwap(d, other.d); } @@ -228,11 +236,6 @@ private: T *d; }; -template -Q_INLINE_TEMPLATE QSharedDataPointer::QSharedDataPointer(T *adata) noexcept - : d(adata) -{ if (d) d->ref.ref(); } - template Q_INLINE_TEMPLATE T *QSharedDataPointer::clone() { @@ -265,18 +268,13 @@ Q_OUTOFLINE_TEMPLATE void QExplicitlySharedDataPointer::detach_helper() d = x; } -template -Q_INLINE_TEMPLATE QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(T *adata) noexcept - : d(adata) -{ if (d) d->ref.ref(); } - -template inline bool operator==(std::nullptr_t p1, const QExplicitlySharedDataPointer &p2) +template inline bool operator==(std::nullptr_t p1, const QExplicitlySharedDataPointer &p2) noexcept { Q_UNUSED(p1); return !p2; } -template inline bool operator==(const QExplicitlySharedDataPointer &p1, std::nullptr_t p2) +template inline bool operator==(const QExplicitlySharedDataPointer &p1, std::nullptr_t p2) noexcept { Q_UNUSED(p2); return !p1;