From 4e7f92bf0dc535f90e6d50ee4739a455951fa397 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 11 May 2022 10:14:45 +0200 Subject: [PATCH] QMetaType: Fix normalization on MSVC if name contains enum During type normalization, we remove the struct, class and enum keywords (see the skipStructClassOrEnum function). However, we only want to do that for actual keywords, not for a name that happens to start with e.g. "enum", as in "enumerationNameSpacce". Adjust the MSVC check to still require no identifier character after the keyword, while still allowing for some remaining characters. Fixes: QTBUG-97813 Pick-to: 6.3 6.2 Change-Id: I82b873d02ff454cce4b75f2814a52a66f2268208 Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira --- src/corelib/kernel/qmetatype.h | 2 +- tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 58bbb5f813..847685c8ae 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -1765,7 +1765,7 @@ private: #ifdef Q_CC_MSVC /// On MSVC, keywords like class or struct are not separated with spaces in constexpr /// context - if (msvcKw) + if (msvcKw && !is_ident_char(*b)) return true; #endif Q_UNUSED(msvcKw); diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index f69327a3f1..7bf3d9756a 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -585,6 +585,10 @@ void tst_QMetaType::normalizedTypes() #define TYPENAME_DATA(MetaTypeName, MetaTypeId, RealType)\ QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << #RealType; +namespace enumerations { + enum Test { a = 0 }; +} + void tst_QMetaType::typeName_data() { QTest::addColumn("aType"); @@ -621,6 +625,8 @@ void tst_QMetaType::typeName_data() // template instance class derived from Q_GADGET enabled class QTest::newRow("GadgetDerivedAndTyped") << ::qMetaTypeId>() << QString::fromLatin1("GadgetDerivedAndTyped"); QTest::newRow("GadgetDerivedAndTyped*") << ::qMetaTypeId*>() << QString::fromLatin1("GadgetDerivedAndTyped*"); + + QTest::newRow("msvcKeywordPartOfName") << ::qMetaTypeId() << QString::fromLatin1("enumerations::Test"); } void tst_QMetaType::typeName()