diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 5e53a970d4..d6fc881d50 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -1879,12 +1879,21 @@ private: } public: -#ifndef Q_CC_MSVC +#if defined(Q_CC_CLANG) || defined (Q_CC_GNU) // this is much simpler than the full type normalization below // the reason is that the signature returned by Q_FUNC_INFO is already // normalized to the largest degree, and we need to do only small adjustments constexpr int normalizeTypeFromSignature(const char *begin, const char *end) { + // bail out if there is an anonymous struct + std::string_view name(begin, end-begin); +#if defined (Q_CC_CLANG) + if (name.find("anonymous ") != std::string_view::npos) + return normalizeType(begin, end); +#else + if (name.find("unnamed ") != std::string_view::npos) + return normalizeType(begin, end); +#endif while (begin < end) { if (*begin == ' ') { if (last == ',' || last == '>' || last == '<' || last == '*' || last == '&') { @@ -1893,7 +1902,7 @@ public: } } if (last == ' ') { - if (*begin == '*' || *begin == '&') { + if (*begin == '*' || *begin == '&' || *begin == '(') { replaceLast(*begin); ++begin; continue; diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype2.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype2.cpp index 856b56941a..8567288c8b 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype2.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype2.cpp @@ -385,6 +385,11 @@ struct CharTemplate { int a; } x; + + union + { + int a; + } y; }; void tst_QMetaType::operatorEq_data() @@ -479,6 +484,16 @@ void tst_QMetaType::typeNameNormalization() // The string based normalization doesn't handle aliases, QMetaType::fromType() does // CHECK_TYPE_NORMALIZATION("qulonglong", quint64); QCOMPARE(QMetaType::fromType().name(), "qulonglong"); + + // noramlizedType and metatype name agree + { + auto type = QMetaType::fromType::x)>(); + QCOMPARE(type.name(), QMetaObject::normalizedType(type.name())); + } + { + auto type = QMetaType::fromType::y)>(); + QCOMPARE(type.name(), QMetaObject::normalizedType(type.name())); + } } // Compile-time test, it should be possible to register function pointer types