QVariant: add support for numeric comparisons for char16_t and char32_t

Change-Id: I3d74c753055744deb8acfffd17248af45fd20556
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Thiago Macieira 2022-11-04 18:09:04 -07:00
parent cf0a1c2e51
commit bdc8778d7a
2 changed files with 13 additions and 1 deletions

View File

@ -157,6 +157,8 @@ static std::optional<qlonglong> qConvertToNumber(const QVariant::Private *d, boo
case QMetaType::ULongLong:
case QMetaType::UInt:
case QMetaType::UChar:
case QMetaType::Char16:
case QMetaType::Char32:
case QMetaType::UShort:
case QMetaType::ULong:
return qlonglong(qMetaTypeUNumber(d));
@ -184,6 +186,8 @@ static std::optional<qreal> qConvertToRealNumber(const QVariant::Private *d)
case QMetaType::ULongLong:
case QMetaType::UInt:
case QMetaType::UChar:
case QMetaType::Char16:
case QMetaType::Char32:
case QMetaType::UShort:
case QMetaType::ULong:
return qreal(qMetaTypeUNumber(d));
@ -2140,6 +2144,8 @@ static bool qIsNumericType(uint tp)
Q_UINT64_C(1) << QMetaType::Double |
Q_UINT64_C(1) << QMetaType::Float |
Q_UINT64_C(1) << QMetaType::Char |
Q_UINT64_C(1) << QMetaType::Char16 |
Q_UINT64_C(1) << QMetaType::Char32 |
Q_UINT64_C(1) << QMetaType::SChar |
Q_UINT64_C(1) << QMetaType::UChar |
Q_UINT64_C(1) << QMetaType::Short |
@ -2227,7 +2233,7 @@ static int numericTypePromotion(const QtPrivate::QMetaTypeInterface *iface1,
auto isUnsigned = [](uint tp) {
// only types for which sizeof(T) >= sizeof(int); lesser ones promote to int
return tp == QMetaType::ULongLong || tp == QMetaType::ULong ||
tp == QMetaType::UInt;
tp == QMetaType::UInt || tp == QMetaType::Char32;
};
bool isUnsigned1 = isUnsigned(t1);
bool isUnsigned2 = isUnsigned(t2);

View File

@ -2836,6 +2836,8 @@ QT_WARNING_POP
addList(std::array{ false, true });
addList(std::array{ QCborSimpleType{}, QCborSimpleType::False, QCborSimpleType(0xff) });
addSingleType(char(0));
addSingleType(char16_t(0));
addSingleType(char32_t(0));
addSingleType(qint8(0));
addSingleType(quint8(0));
addSingleType(qint16(0));
@ -2856,6 +2858,10 @@ QT_WARNING_POP
addComparePair(char(127), qint8(127));
addComparePair(char(127), quint8(127));
addComparePair(qint8(-1), quint8(255));
addComparePair(char16_t(256), qint8(-1));
addComparePair(char16_t(256), short(-1));
addComparePair(char16_t(256), int(-1));
addComparePair(char32_t(256), int(-1));
addComparePair(0U, -1);
addComparePair(~0U, -1);
addComparePair(Q_UINT64_C(0), -1);