From 99fc96fd373b6ffdf9a66e4a346885de20645533 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 9 Mar 2017 13:44:00 +0100 Subject: QMetaType & QVariant: "load" and "save" std::nullptr_t We don't load and save pointers usually because the pointer value cannot be guaranteed to remain across program invocations. However, nullptr is an exception: a null pointer is always a null pointer. We don't actually have to read or write anything: there's only one value possible for a std::nullptr_t and it is nullptr. [ChangeLog][Important Behavior Changes] A QVariant containing a std::nullptr_t is now streamable to/from QDataStream. Task-number: QTBUG-59391 Change-Id: Iae839f6a131a4f0784bffffd14aa374f6475d283 Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Lars Knoll --- tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 7d9f56ef38..7e1979dfb3 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1559,7 +1559,6 @@ DECLARE_NONSTREAMABLE(QJsonArray) DECLARE_NONSTREAMABLE(QJsonDocument) DECLARE_NONSTREAMABLE(QObject*) DECLARE_NONSTREAMABLE(QWidget*) -DECLARE_NONSTREAMABLE(std::nullptr_t) #define DECLARE_GUI_CLASS_NONSTREAMABLE(MetaTypeName, MetaTypeId, RealType) \ DECLARE_NONSTREAMABLE(RealType) @@ -1598,7 +1597,10 @@ void tst_QMetaType::saveAndLoadBuiltin() if (isStreamable) { QVERIFY(QMetaType::load(stream, type, value)); // Hmmm, shouldn't it return false? - QCOMPARE(stream.status(), QDataStream::ReadPastEnd); + + // std::nullptr_t is nullary: it doesn't actually read anything + if (type != QMetaType::Nullptr) + QCOMPARE(stream.status(), QDataStream::ReadPastEnd); } stream.device()->seek(0); @@ -1608,7 +1610,10 @@ void tst_QMetaType::saveAndLoadBuiltin() if (isStreamable) { QVERIFY(QMetaType::load(stream, type, value)); // Hmmm, shouldn't it return false? - QCOMPARE(stream.status(), QDataStream::ReadPastEnd); + + // std::nullptr_t is nullary: it doesn't actually read anything + if (type != QMetaType::Nullptr) + QCOMPARE(stream.status(), QDataStream::ReadPastEnd); } QMetaType::destroy(type, value); -- cgit v1.2.3