From b7c7beacda529edd642d979064748bdad27b989b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 1 Apr 2016 09:24:51 +0200 Subject: QPointer: add a test for const QPointer People use this, so make sure there's a test for it. I don't expect this test to fail, but static and dynamic checkers should be presented with this use-case, so they have a chance of warning, because certain implementation strategies of QPointer may make this code undefined. Change-Id: I334bd73204ba4e186c4098fc6b7188917407e020 Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp') diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp index d7cce4ada4..f3f485297a 100644 --- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp +++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp @@ -59,6 +59,7 @@ private slots: void qvariantCast(); void constPointer(); + void constQPointer(); }; void tst_QPointer::constructors() @@ -402,6 +403,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 p = o; + delete o; + QVERIFY(!p); +} + QTEST_MAIN(tst_QPointer) #include "tst_qpointer.moc" -- cgit v1.2.3