From 6d054270fc74b4c866305185b2891e9c7e454c14 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 13 Mar 2023 09:36:09 +0100 Subject: [PATCH] QMetaType: Ensure that qfloat16 gets correct id Code initially compiled against Qt <= 6.2 does not have a qfloat16 metatype that unconditionally gets registeret from QtBase. Therefore, any preexisting metatype instance for qfloat16 will hit the custom type registry code path. As builtin metatypes are not part of the custom registry, we will create a new type-id, and the type will thus not compare equal to new code using the builtin type-id. Avoid this issue by inserting an alias to the type in QMetaTypeCustomRegistry's constructor. Change-Id: I825265ad16e274c08b2c4a3a4814475b6c6c6187 Reviewed-by: Volker Hilsheimer Reviewed-by: Marc Mutz (cherry picked from commit b68ad5ef7fd8df0ef4aea03f33dfe05fd8272469) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qmetatype.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 4006b348e15..b476451ed0c 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -84,6 +84,20 @@ struct QMetaTypeDeleter struct QMetaTypeCustomRegistry { + +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) + QMetaTypeCustomRegistry() + { + /* qfloat16 was neither a builtin, nor unconditionally registered + in QtCore in Qt <= 6.2. + Inserting it as an alias ensures that a QMetaType::id call + will get the correct built-in type-id (the interface pointers + might still not match, but we already deal with that case. + */ + aliases.insert("qfloat16", QtPrivate::qMetaTypeInterfaceForType()); + } +#endif + QReadWriteLock lock; QList registry; QHash aliases;