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 <lars.knoll@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Fabian Kosmale 2022-05-11 10:14:45 +02:00
parent bb334e8181
commit 4e7f92bf0d
2 changed files with 7 additions and 1 deletions

View File

@ -1765,7 +1765,7 @@ private:
#ifdef Q_CC_MSVC #ifdef Q_CC_MSVC
/// On MSVC, keywords like class or struct are not separated with spaces in constexpr /// On MSVC, keywords like class or struct are not separated with spaces in constexpr
/// context /// context
if (msvcKw) if (msvcKw && !is_ident_char(*b))
return true; return true;
#endif #endif
Q_UNUSED(msvcKw); Q_UNUSED(msvcKw);

View File

@ -585,6 +585,10 @@ void tst_QMetaType::normalizedTypes()
#define TYPENAME_DATA(MetaTypeName, MetaTypeId, RealType)\ #define TYPENAME_DATA(MetaTypeName, MetaTypeId, RealType)\
QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << #RealType; QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << #RealType;
namespace enumerations {
enum Test { a = 0 };
}
void tst_QMetaType::typeName_data() void tst_QMetaType::typeName_data()
{ {
QTest::addColumn<int>("aType"); QTest::addColumn<int>("aType");
@ -621,6 +625,8 @@ void tst_QMetaType::typeName_data()
// template instance class derived from Q_GADGET enabled class // template instance class derived from Q_GADGET enabled class
QTest::newRow("GadgetDerivedAndTyped<int>") << ::qMetaTypeId<GadgetDerivedAndTyped<int>>() << QString::fromLatin1("GadgetDerivedAndTyped<int>"); QTest::newRow("GadgetDerivedAndTyped<int>") << ::qMetaTypeId<GadgetDerivedAndTyped<int>>() << QString::fromLatin1("GadgetDerivedAndTyped<int>");
QTest::newRow("GadgetDerivedAndTyped<int>*") << ::qMetaTypeId<GadgetDerivedAndTyped<int>*>() << QString::fromLatin1("GadgetDerivedAndTyped<int>*"); QTest::newRow("GadgetDerivedAndTyped<int>*") << ::qMetaTypeId<GadgetDerivedAndTyped<int>*>() << QString::fromLatin1("GadgetDerivedAndTyped<int>*");
QTest::newRow("msvcKeywordPartOfName") << ::qMetaTypeId<enumerations::Test>() << QString::fromLatin1("enumerations::Test");
} }
void tst_QMetaType::typeName() void tst_QMetaType::typeName()