summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp')
-rw-r--r--tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
index 838120bb68..914f9e2b9b 100644
--- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
+++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
@@ -54,6 +54,7 @@ private slots:
void qvariantCast();
void constPointer();
+ void constQPointer();
};
void tst_QPointer::constructors()
@@ -397,6 +398,21 @@ void tst_QPointer::constPointer()
delete fp.data();
}
+void tst_QPointer::constQPointer()
+{
+ // Check that const QPointers work. It's a bit weird to mark a pointer
+ // const if its value can change, but the shallow-const principle in C/C++
+ // allows this, and people use it, so document it with a test.
+ //
+ // It's unlikely that this test will fail in and out of itself, but it
+ // presents the use-case to static and dynamic checkers that can raise
+ // a warning (hopefully) should this become an issue.
+ QObject *o = new QObject(this);
+ const QPointer<QObject> p = o;
+ delete o;
+ QVERIFY(!p);
+}
+
QTEST_MAIN(tst_QPointer)
#include "tst_qpointer.moc"