From bc9f8fd8de582c9a4f591e1ed194e1e9b65697fb Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 4 May 2016 01:01:06 +0200 Subject: QSharedPointer/QWeakPointer/QScopedPointer: plaster API with Q_DECL_NOTHROW Some methods were already marked, this adds noexcept to even more methods. Change-Id: I420bb1cc985058c7976ce3a1f251fadbba7ddceb Reviewed-by: Marc Mutz --- src/corelib/tools/qscopedpointer.h | 21 +++++++-------- src/corelib/tools/qsharedpointer_impl.h | 46 ++++++++++++++++----------------- 2 files changed, 33 insertions(+), 34 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index 3e6af97a33..18fbe2c808 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -97,7 +97,7 @@ class QScopedPointer { typedef T *QScopedPointer:: *RestrictedBool; public: - explicit inline QScopedPointer(T *p = Q_NULLPTR) : d(p) + explicit QScopedPointer(T *p = Q_NULLPTR) Q_DECL_NOTHROW : d(p) { } @@ -113,13 +113,12 @@ public: return *d; } - inline T *operator->() const + T *operator->() const Q_DECL_NOTHROW { - Q_ASSERT(d); return d; } - inline bool operator!() const + bool operator!() const Q_DECL_NOTHROW { return !d; } @@ -130,23 +129,23 @@ public: return isNull() ? Q_NULLPTR : &QScopedPointer::d; } #else - inline operator RestrictedBool() const + operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? Q_NULLPTR : &QScopedPointer::d; } #endif - inline T *data() const + T *data() const Q_DECL_NOTHROW { return d; } - inline bool isNull() const + bool isNull() const Q_DECL_NOTHROW { return !d; } - inline void reset(T *other = Q_NULLPTR) + void reset(T *other = Q_NULLPTR) Q_DECL_NOEXCEPT_EXPR(noexcept(Cleanup::cleanup(std::declval()))) { if (d == other) return; @@ -155,7 +154,7 @@ public: Cleanup::cleanup(oldD); } - inline T *take() + T *take() Q_DECL_NOTHROW { T *oldD = d; d = Q_NULLPTR; @@ -177,13 +176,13 @@ private: }; template -inline bool operator==(const QScopedPointer &lhs, const QScopedPointer &rhs) +inline bool operator==(const QScopedPointer &lhs, const QScopedPointer &rhs) Q_DECL_NOTHROW { return lhs.data() == rhs.data(); } template -inline bool operator!=(const QScopedPointer &lhs, const QScopedPointer &rhs) +inline bool operator!=(const QScopedPointer &lhs, const QScopedPointer &rhs) Q_DECL_NOTHROW { return lhs.data() != rhs.data(); } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index d051ed6099..dc118d7a68 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -305,12 +305,12 @@ public: typedef const value_type &const_reference; typedef qptrdiff difference_type; - inline T *data() const { return value; } - inline bool isNull() const { return !data(); } - inline operator RestrictedBool() const { return isNull() ? Q_NULLPTR : &QSharedPointer::value; } - inline bool operator !() const { return isNull(); } - inline T &operator*() const { return *data(); } - inline T *operator->() const { return data(); } + T *data() const Q_DECL_NOTHROW { return value; } + bool isNull() const Q_DECL_NOTHROW { return !data(); } + operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? Q_NULLPTR : &QSharedPointer::value; } + bool operator !() const Q_DECL_NOTHROW { return isNull(); } + T &operator*() const { return *data(); } + T *operator->() const Q_DECL_NOTHROW { return data(); } Q_DECL_CONSTEXPR QSharedPointer() Q_DECL_NOTHROW : value(nullptr), d(nullptr) { } ~QSharedPointer() { deref(); } @@ -369,7 +369,7 @@ public: #endif template - inline QSharedPointer(const QSharedPointer &other) : value(other.value), d(other.d) + QSharedPointer(const QSharedPointer &other) Q_DECL_NOTHROW : value(other.value), d(other.d) { if (d) ref(); } template @@ -604,10 +604,10 @@ public: typedef const value_type &const_reference; typedef qptrdiff difference_type; - inline bool isNull() const { return d == Q_NULLPTR || d->strongref.load() == 0 || value == Q_NULLPTR; } - inline operator RestrictedBool() const { return isNull() ? Q_NULLPTR : &QWeakPointer::value; } - inline bool operator !() const { return isNull(); } - inline T *data() const { return d == Q_NULLPTR || d->strongref.load() == 0 ? Q_NULLPTR : value; } + bool isNull() const Q_DECL_NOTHROW { return d == Q_NULLPTR || d->strongref.load() == 0 || value == Q_NULLPTR; } + operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? Q_NULLPTR : &QWeakPointer::value; } + bool operator !() const Q_DECL_NOTHROW { return isNull(); } + T *data() const Q_DECL_NOTHROW { return d == Q_NULLPTR || d->strongref.load() == 0 ? Q_NULLPTR : value; } inline QWeakPointer() Q_DECL_NOTHROW : d(Q_NULLPTR), value(Q_NULLPTR) { } inline ~QWeakPointer() { if (d && !d->weakref.deref()) delete d; } @@ -674,11 +674,11 @@ public: } template - inline bool operator==(const QWeakPointer &o) const + bool operator==(const QWeakPointer &o) const Q_DECL_NOTHROW { return d == o.d && value == static_cast(o.value); } template - inline bool operator!=(const QWeakPointer &o) const + bool operator!=(const QWeakPointer &o) const Q_DECL_NOTHROW { return !(*this == o); } template @@ -694,11 +694,11 @@ public: } template - inline bool operator==(const QSharedPointer &o) const + bool operator==(const QSharedPointer &o) const Q_DECL_NOTHROW { return d == o.d; } template - inline bool operator!=(const QSharedPointer &o) const + bool operator!=(const QSharedPointer &o) const Q_DECL_NOTHROW { return !(*this == o); } inline void clear() { *this = QWeakPointer(); } @@ -780,44 +780,44 @@ public: // operator== and operator!= // template -bool operator==(const QSharedPointer &ptr1, const QSharedPointer &ptr2) +bool operator==(const QSharedPointer &ptr1, const QSharedPointer &ptr2) Q_DECL_NOTHROW { return ptr1.data() == ptr2.data(); } template -bool operator!=(const QSharedPointer &ptr1, const QSharedPointer &ptr2) +bool operator!=(const QSharedPointer &ptr1, const QSharedPointer &ptr2) Q_DECL_NOTHROW { return ptr1.data() != ptr2.data(); } template -bool operator==(const QSharedPointer &ptr1, const X *ptr2) +bool operator==(const QSharedPointer &ptr1, const X *ptr2) Q_DECL_NOTHROW { return ptr1.data() == ptr2; } template -bool operator==(const T *ptr1, const QSharedPointer &ptr2) +bool operator==(const T *ptr1, const QSharedPointer &ptr2) Q_DECL_NOTHROW { return ptr1 == ptr2.data(); } template -bool operator!=(const QSharedPointer &ptr1, const X *ptr2) +bool operator!=(const QSharedPointer &ptr1, const X *ptr2) Q_DECL_NOTHROW { return !(ptr1 == ptr2); } template -bool operator!=(const T *ptr1, const QSharedPointer &ptr2) +bool operator!=(const T *ptr1, const QSharedPointer &ptr2) Q_DECL_NOTHROW { return !(ptr2 == ptr1); } template -bool operator==(const QSharedPointer &ptr1, const QWeakPointer &ptr2) +bool operator==(const QSharedPointer &ptr1, const QWeakPointer &ptr2) Q_DECL_NOTHROW { return ptr2 == ptr1; } template -bool operator!=(const QSharedPointer &ptr1, const QWeakPointer &ptr2) +bool operator!=(const QSharedPointer &ptr1, const QWeakPointer &ptr2) Q_DECL_NOTHROW { return ptr2 != ptr1; } -- cgit v1.2.3