QtCore: Use Q_NULLPTR instead of 0 in smart pointer headers
This is in preparation of adding -Wzero-as-null-pointer-constant (or similar) to the headers check. Not caught by the headersclean check, because they are in template code. Task-number: QTBUG-45291 Change-Id: I7294404225a19a1c58f91e6e47a9d650179ea83c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
0aa5092576
commit
cdd2f8eb34
@ -91,7 +91,7 @@ class QScopedPointer
|
||||
{
|
||||
typedef T *QScopedPointer:: *RestrictedBool;
|
||||
public:
|
||||
explicit inline QScopedPointer(T *p = 0) : d(p)
|
||||
explicit inline QScopedPointer(T *p = Q_NULLPTR) : d(p)
|
||||
{
|
||||
}
|
||||
|
||||
@ -121,12 +121,12 @@ public:
|
||||
#if defined(Q_QDOC)
|
||||
inline operator bool() const
|
||||
{
|
||||
return isNull() ? 0 : &QScopedPointer::d;
|
||||
return isNull() ? Q_NULLPTR : &QScopedPointer::d;
|
||||
}
|
||||
#else
|
||||
inline operator RestrictedBool() const
|
||||
{
|
||||
return isNull() ? 0 : &QScopedPointer::d;
|
||||
return isNull() ? Q_NULLPTR : &QScopedPointer::d;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -140,7 +140,7 @@ public:
|
||||
return !d;
|
||||
}
|
||||
|
||||
inline void reset(T *other = 0)
|
||||
inline void reset(T *other = Q_NULLPTR)
|
||||
{
|
||||
if (d == other)
|
||||
return;
|
||||
@ -152,7 +152,7 @@ public:
|
||||
inline T *take()
|
||||
{
|
||||
T *oldD = d;
|
||||
d = 0;
|
||||
d = Q_NULLPTR;
|
||||
return oldD;
|
||||
}
|
||||
|
||||
@ -206,10 +206,10 @@ template <typename T, typename Cleanup = QScopedPointerArrayDeleter<T> >
|
||||
class QScopedArrayPointer : public QScopedPointer<T, Cleanup>
|
||||
{
|
||||
public:
|
||||
inline QScopedArrayPointer() : QScopedPointer<T, Cleanup>(0) {}
|
||||
inline QScopedArrayPointer() : QScopedPointer<T, Cleanup>(Q_NULLPTR) {}
|
||||
|
||||
template <typename D>
|
||||
explicit inline QScopedArrayPointer(D *p, typename QtPrivate::QScopedArrayEnsureSameType<T,D>::Type = 0)
|
||||
explicit inline QScopedArrayPointer(D *p, typename QtPrivate::QScopedArrayEnsureSameType<T,D>::Type = Q_NULLPTR)
|
||||
: QScopedPointer<T, Cleanup>(p)
|
||||
{
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
inline bool operator==(const QSharedDataPointer<T> &other) const { return d == other.d; }
|
||||
inline bool operator!=(const QSharedDataPointer<T> &other) const { return d != other.d; }
|
||||
|
||||
inline QSharedDataPointer() { d = 0; }
|
||||
inline QSharedDataPointer() { d = Q_NULLPTR; }
|
||||
inline ~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; }
|
||||
|
||||
explicit QSharedDataPointer(T *data) Q_DECL_NOTHROW;
|
||||
@ -145,17 +145,17 @@ public:
|
||||
if(d && !d->ref.deref())
|
||||
delete d;
|
||||
|
||||
d = 0;
|
||||
d = Q_NULLPTR;
|
||||
}
|
||||
|
||||
inline operator bool () const { return d != 0; }
|
||||
inline operator bool () const { return d != Q_NULLPTR; }
|
||||
|
||||
inline bool operator==(const QExplicitlySharedDataPointer<T> &other) const { return d == other.d; }
|
||||
inline bool operator!=(const QExplicitlySharedDataPointer<T> &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 QExplicitlySharedDataPointer() { d = 0; }
|
||||
inline QExplicitlySharedDataPointer() { d = Q_NULLPTR; }
|
||||
inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
|
||||
|
||||
explicit QExplicitlySharedDataPointer(T *data) Q_DECL_NOTHROW;
|
||||
|
@ -300,12 +300,12 @@ public:
|
||||
|
||||
inline T *data() const { return value; }
|
||||
inline bool isNull() const { return !data(); }
|
||||
inline operator RestrictedBool() const { return isNull() ? 0 : &QSharedPointer::value; }
|
||||
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(); }
|
||||
|
||||
QSharedPointer() : value(0), d(0) { }
|
||||
QSharedPointer() : value(Q_NULLPTR), d(Q_NULLPTR) { }
|
||||
~QSharedPointer() { deref(); }
|
||||
|
||||
inline explicit QSharedPointer(T *ptr) : value(ptr) // noexcept
|
||||
@ -327,8 +327,8 @@ public:
|
||||
inline QSharedPointer(QSharedPointer &&other)
|
||||
: value(other.value), d(other.d)
|
||||
{
|
||||
other.d = 0;
|
||||
other.value = 0;
|
||||
other.d = Q_NULLPTR;
|
||||
other.value = Q_NULLPTR;
|
||||
}
|
||||
inline QSharedPointer &operator=(QSharedPointer &&other)
|
||||
{
|
||||
@ -351,7 +351,7 @@ public:
|
||||
}
|
||||
|
||||
template <class X>
|
||||
inline QSharedPointer(const QWeakPointer<X> &other) : value(0), d(0)
|
||||
inline QSharedPointer(const QWeakPointer<X> &other) : value(Q_NULLPTR), d(Q_NULLPTR)
|
||||
{ *this = other; }
|
||||
|
||||
template <class X>
|
||||
@ -491,7 +491,7 @@ private:
|
||||
inline void internalConstruct(T *ptr, Deleter deleter)
|
||||
{
|
||||
if (!ptr) {
|
||||
d = 0;
|
||||
d = Q_NULLPTR;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -554,14 +554,14 @@ public:
|
||||
o->weakref.ref();
|
||||
} else {
|
||||
o->checkQObjectShared(actual);
|
||||
o = 0;
|
||||
o = Q_NULLPTR;
|
||||
}
|
||||
}
|
||||
|
||||
qSwap(d, o);
|
||||
qSwap(this->value, actual);
|
||||
if (!d || d->strongref.load() == 0)
|
||||
this->value = 0;
|
||||
this->value = Q_NULLPTR;
|
||||
|
||||
// dereference saved data
|
||||
deref(o);
|
||||
@ -586,19 +586,19 @@ public:
|
||||
typedef const value_type &const_reference;
|
||||
typedef qptrdiff difference_type;
|
||||
|
||||
inline bool isNull() const { return d == 0 || d->strongref.load() == 0 || value == 0; }
|
||||
inline operator RestrictedBool() const { return isNull() ? 0 : &QWeakPointer::value; }
|
||||
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 == 0 || d->strongref.load() == 0 ? 0 : value; }
|
||||
inline T *data() const { return d == Q_NULLPTR || d->strongref.load() == 0 ? Q_NULLPTR : value; }
|
||||
|
||||
inline QWeakPointer() : d(0), value(0) { }
|
||||
inline QWeakPointer() : d(Q_NULLPTR), value(Q_NULLPTR) { }
|
||||
inline ~QWeakPointer() { if (d && !d->weakref.deref()) delete d; }
|
||||
|
||||
#ifndef QT_NO_QOBJECT
|
||||
// special constructor that is enabled only if X derives from QObject
|
||||
#if QT_DEPRECATED_SINCE(5, 0)
|
||||
template <class X>
|
||||
QT_DEPRECATED inline QWeakPointer(X *ptr) : d(ptr ? Data::getAndRef(ptr) : 0), value(ptr)
|
||||
QT_DEPRECATED inline QWeakPointer(X *ptr) : d(ptr ? Data::getAndRef(ptr) : Q_NULLPTR), value(ptr)
|
||||
{ }
|
||||
#endif
|
||||
#endif
|
||||
@ -632,7 +632,7 @@ public:
|
||||
}
|
||||
|
||||
template <class X>
|
||||
inline QWeakPointer(const QWeakPointer<X> &o) : d(0), value(0)
|
||||
inline QWeakPointer(const QWeakPointer<X> &o) : d(Q_NULLPTR), value(Q_NULLPTR)
|
||||
{ *this = o; }
|
||||
|
||||
template <class X>
|
||||
@ -653,7 +653,7 @@ public:
|
||||
{ return !(*this == o); }
|
||||
|
||||
template <class X>
|
||||
inline QWeakPointer(const QSharedPointer<X> &o) : d(0), value(0)
|
||||
inline QWeakPointer(const QSharedPointer<X> &o) : d(Q_NULLPTR), value(Q_NULLPTR)
|
||||
{ *this = o; }
|
||||
|
||||
template <class X>
|
||||
@ -697,7 +697,7 @@ public:
|
||||
|
||||
#ifndef QT_NO_QOBJECT
|
||||
template <class X>
|
||||
inline QWeakPointer(X *ptr, bool) : d(ptr ? Data::getAndRef(ptr) : 0), value(ptr)
|
||||
inline QWeakPointer(X *ptr, bool) : d(ptr ? Data::getAndRef(ptr) : Q_NULLPTR), value(ptr)
|
||||
{ }
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user