summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qvariant
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-04-27 09:40:17 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2023-04-28 12:37:03 +0200
commitc2f01d4cfb1b144bcc2bf295399ef0d4ad70dae2 (patch)
tree55ca367e0d18d1eb03a9540cb1617ddeb0d5d7e1 /tests/auto/corelib/kernel/qvariant
parentfdb287e6207476773fa242c5b7a465ab3903356d (diff)
QVariant: Fix support for metatypes created by Qt < 6.5
In Qt >= 6.1, < 6.5, a trivially constructible type would have the NeedsDestruction flag set, but it's dtor pointer would have been null. In Qt 6.5, the meaning of the NeedsDestruction flag was changed to be more aligned with what the name suggests, and thus would only be set for non-trivially destructible types. For QMetaType this was fine, but QVariant has a check for acceptable metatypes which attempts to verify whether a QMetaType is usable for QVariant. The check assumes the semantics of Qt 6.5, and thus fails for metatypes created by older Qt versions. To fix this issue, we increment the QMetaType revision field, and only check the metatype's destruction support if the revision is high enough. In theory, that allows passing unsuitable metatypes from older Qt versions to QVariant; however, such code would have been broken in prior Qt releases already (which didn't attempt the check), and no code that used to work in any released Qt version will break (as we simply skip a check that was passing before). Fixes: QTBUG-113227 Pick-to: 6.5 Change-Id: I12e02bd97d2c410ea1a36efb0ce2389f21d50a30 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel/qvariant')
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index 698d117f70..4fa42a1d52 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -376,6 +376,7 @@ private slots:
void constructFromIncompatibleMetaType_data();
void constructFromIncompatibleMetaType();
+ void constructFromQtLT65MetaType();
void copyNonDefaultConstructible();
void inplaceConstruct();
@@ -5702,6 +5703,33 @@ void tst_QVariant::constructFromIncompatibleMetaType()
QVERIFY(!QVariant(regular).convert(type));
}
+void tst_QVariant::constructFromQtLT65MetaType()
+{
+ auto qsizeIface = QtPrivate::qMetaTypeInterfaceForType<QSize>();
+
+ QtPrivate::QMetaTypeInterface qsize64Iface = {
+ /*revision*/0,
+ 8,
+ 8,
+ QMetaType::NeedsConstruction | QMetaType::NeedsDestruction,
+ 0,
+ qsizeIface->metaObjectFn,
+ "FakeQSize",
+ qsizeIface->defaultCtr,
+ qsizeIface->copyCtr,
+ qsizeIface->moveCtr,
+ /*dtor =*/ nullptr,
+ qsizeIface->equals,
+ qsizeIface->lessThan,
+ qsizeIface->debugStream,
+ qsizeIface->dataStreamOut,
+ qsizeIface->dataStreamIn,
+ /*legacyregop =*/ nullptr
+ };
+ QVariant var{ QMetaType(&qsize64Iface) };
+ QVERIFY(var.isValid());
+}
+
void tst_QVariant::copyNonDefaultConstructible()
{
NonDefaultConstructible ndc(42);