summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorVille Voutilainen <ville.voutilainen@qt.io>2021-04-27 11:30:47 +0300
committerVille Voutilainen <ville.voutilainen@qt.io>2021-04-28 23:33:06 +0300
commit0e4cc15da330fb25b913fbc8089e60f80a08f49f (patch)
treecd961968ba314f1297748537d7dd7794f042cf36 /src/corelib
parent776734576c2ba7bd4bdba6e09bc5dad5e093670a (diff)
Fix comparison between nullptr and QWeakPointer
The comparison between nullptr and QWeakPointer was just bogus and ill-formed. The INTEGRITY compiler catches that even if nothing tries to use the comparison. It is an ill-formed, no diagnostic required case of a function template never being able to produce a valid specialization. And while we're at it, this patch makes the result of comparing a nullptr to a QWeakPointer or vice versa the same as asking .isNull() from the weak pointer, because it seems mind-boggling if those are not the same operation. Task-number: QTBUG-93093 Change-Id: I0cc80e795c9af2be1b76de05157aa458ef260f2e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 222aecb018..cf88456096 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -457,6 +457,7 @@ public:
DECLARE_COMPARE_SET(const QSharedPointer &p1, p1.data(), std::nullptr_t, nullptr)
DECLARE_COMPARE_SET(std::nullptr_t, nullptr, const QSharedPointer &p2, p2.data())
#undef DECLARE_TEMPLATE_COMPARE_SET
+#undef DECLARE_COMPARE_SET
private:
explicit QSharedPointer(Qt::Initialization) {}
@@ -658,9 +659,14 @@ public:
friend bool operator!=(const QSharedPointer<X> &p1, const QWeakPointer &p2) noexcept
{ return p2 != p1; }
- DECLARE_COMPARE_SET(const QWeakPointer &p1, p1.d, std::nullptr_t, nullptr)
- DECLARE_COMPARE_SET(std::nullptr_t, nullptr, const QWeakPointer &p2, p2.data())
-#undef DECLARE_COMPARE_SET
+ friend bool operator==(const QWeakPointer &p, std::nullptr_t)
+ { return p.isNull(); }
+ friend bool operator==(std::nullptr_t, const QWeakPointer &p)
+ { return p.isNull(); }
+ friend bool operator!=(const QWeakPointer &p, std::nullptr_t)
+ { return !p.isNull(); }
+ friend bool operator!=(std::nullptr_t, const QWeakPointer &p)
+ { return !p.isNull(); }
private:
friend struct QtPrivate::EnableInternalData;