summaryrefslogtreecommitdiffstats
path: root/tests
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 /tests
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 'tests')
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 42df800b14..db67ab3a5a 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -341,6 +341,11 @@ void tst_QSharedPointer::basics()
QCOMPARE(!weak, isNull);
QCOMPARE(bool(weak), !isNull);
+ QCOMPARE(weak.isNull(), (weak == nullptr));
+ QCOMPARE(weak.isNull(), (nullptr == weak));
+ QCOMPARE(!weak.isNull(), (weak != nullptr));
+ QCOMPARE(!weak.isNull(), (nullptr != weak));
+
QVERIFY(ptr == weak);
QVERIFY(weak == ptr);
QVERIFY(! (ptr != weak));
@@ -426,6 +431,12 @@ void tst_QSharedPointer::nullptrOps()
QVERIFY(!p2.get());
QVERIFY(p1 == p2);
+ QWeakPointer<char> wp1 = p1;
+ QVERIFY(wp1 == nullptr);
+ QVERIFY(nullptr == wp1);
+ QCOMPARE(wp1, nullptr);
+ QCOMPARE(nullptr, wp1);
+
QSharedPointer<char> p3 = p1;
QVERIFY(p3 == p1);
QVERIFY(p3 == null);
@@ -452,6 +463,10 @@ void tst_QSharedPointer::nullptrOps()
QVERIFY(p4 != p2);
QVERIFY(p4 != null);
QVERIFY(p4 != p3);
+
+ QWeakPointer<char> wp2 = p4;
+ QVERIFY(wp2 != nullptr);
+ QVERIFY(nullptr != wp2);
}
void tst_QSharedPointer::swap()