QVariant of nullptr should always be null
Implements isNull for QVariants of a nullptr so they always return true to isNull(), instead of depending on how they were constructed. Task-number: QTBUG-58296 Change-Id: Ibddec795cdadedef7e17d22c265c29e752d8f99f Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
374a173d14
commit
f823af43f2
@ -177,6 +177,26 @@ inline void v_clear(QVariant::Private *d, T* = 0)
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct PrimitiveIsNull
|
||||
{
|
||||
public:
|
||||
static bool isNull(const QVariant::Private *d)
|
||||
{
|
||||
return d->is_null;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct PrimitiveIsNull<std::nullptr_t>
|
||||
{
|
||||
public:
|
||||
static bool isNull(const QVariant::Private *)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Filter>
|
||||
class QVariantComparator {
|
||||
template<typename T, bool IsAcceptedType = Filter::template Acceptor<T>::IsAccepted>
|
||||
@ -268,7 +288,7 @@ class QVariantIsNull
|
||||
{
|
||||
static bool isNull(const QVariant::Private *d)
|
||||
{
|
||||
return d->is_null;
|
||||
return PrimitiveIsNull<T>::isNull(d);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -400,6 +400,17 @@ void tst_QVariant::isNull()
|
||||
QVERIFY( !varLL.isNull() );
|
||||
QVariant var7(QString::null);
|
||||
QVERIFY(var7.isNull());
|
||||
var7 = QVariant::fromValue<QString>(QString::null);
|
||||
QVERIFY(var7.isNull());
|
||||
|
||||
QVariant var8(QMetaType::Nullptr, nullptr);
|
||||
QVERIFY(var8.isNull());
|
||||
var8 = QVariant::fromValue<std::nullptr_t>(nullptr);
|
||||
QVERIFY(var8.isNull());
|
||||
QVariant var9 = QVariant(QJsonValue(QJsonValue::Null));
|
||||
QVERIFY(var9.isNull());
|
||||
var9 = QVariant::fromValue<QJsonValue>(QJsonValue(QJsonValue::Null));
|
||||
QVERIFY(var9.isNull());
|
||||
}
|
||||
|
||||
void tst_QVariant::swap()
|
||||
|
Loading…
Reference in New Issue
Block a user