1 From: Friedemann Kleint <Friedemann.Kleint@qt.io>
2 Date: Tue, 25 Apr 2023 15:30:30 +0200
3 Subject: shiboken2/clang: Fix clashes between type name and enumeration
6 Remove all constant and enum value type entries found in the type lookup
7 unless it is looking for template arguments; where it may be a
8 non-type template argument.
10 Task-number: PYSIDE-2288
12 Change-Id: If0609ce0d0223f551ed6dee1d1e0ea3ef49d6917
13 Reviewed-by: Christian Tismer <tismer@stackless.com>
14 (cherry picked from commit e22f717153a5e9855531f45c0bf82ff2461a3f7e)
16 .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 21 +++++++++++++++++++--
17 .../shiboken2/ApiExtractor/abstractmetabuilder.h | 3 ++-
18 .../shiboken2/ApiExtractor/typesystem_typedefs.h | 1 +
19 3 files changed, 22 insertions(+), 3 deletions(-)
21 diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
22 index 5a413ec..2f34e16 100644
23 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
24 +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
25 @@ -2144,6 +2144,13 @@ static bool isNumber(const QString &s)
26 [](QChar c) { return c.isDigit(); });
29 +// A type entry relevant only for non type template "X<5>"
30 +static bool isNonTypeTemplateArgument(const TypeEntryCPtr &te)
32 + const auto type = te->type();
33 + return type == TypeEntry::EnumValue || type == TypeEntry::ConstantValueType;
36 AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo &_typei,
37 AbstractMetaClass *currentClass,
38 AbstractMetaBuilderPrivate *d,
39 @@ -2271,7 +2278,15 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
40 typeInfo.clearInstantiations();
43 - const TypeEntries types = findTypeEntries(qualifiedName, name, currentClass, d);
44 + TypeEntries types = findTypeEntries(qualifiedName, name, currentClass, d);
45 + if (!flags.testFlag(AbstractMetaBuilder::TemplateArgument)) {
46 + // Avoid clashes between QByteArray and enum value QMetaType::QByteArray
47 + // unless we are looking for template arguments.
48 + auto end = std::remove_if(types.begin(), types.end(),
49 + isNonTypeTemplateArgument);
50 + types.erase(end, types.end());
53 if (types.isEmpty()) {
56 @@ -2293,7 +2308,9 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
57 const auto &templateArguments = typeInfo.instantiations();
58 for (int t = 0, size = templateArguments.size(); t < size; ++t) {
59 const TypeInfo &ti = templateArguments.at(t);
60 - AbstractMetaType *targType = translateTypeStatic(ti, currentClass, d, flags, &errorMessage);
61 + AbstractMetaType *targType = translateTypeStatic(ti, currentClass, d,
62 + flags | AbstractMetaBuilder::TemplateArgument,
64 // For non-type template parameters, create a dummy type entry on the fly
65 // as is done for classes.
67 diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
68 index d2dc080..8916eaf 100644
69 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
70 +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
71 @@ -93,7 +93,8 @@ public:
72 void setSkipDeprecated(bool value);
74 enum TranslateTypeFlag {
75 - DontResolveType = 0x1
76 + DontResolveType = 0x1,
77 + TemplateArgument = 0x2
79 Q_DECLARE_FLAGS(TranslateTypeFlags, TranslateTypeFlag);
81 diff --git a/sources/shiboken2/ApiExtractor/typesystem_typedefs.h b/sources/shiboken2/ApiExtractor/typesystem_typedefs.h
82 index 73f92b2..5dcc65c 100644
83 --- a/sources/shiboken2/ApiExtractor/typesystem_typedefs.h
84 +++ b/sources/shiboken2/ApiExtractor/typesystem_typedefs.h
85 @@ -48,6 +48,7 @@ using CodeSnipList = QVector<CodeSnip>;
86 using DocModificationList = QVector<DocModification>;
87 using FieldModificationList = QVector<FieldModification>;
88 using FunctionModificationList = QVector<FunctionModification>;
89 +using TypeEntryCPtr = const TypeEntry *;
90 using TypeEntries = QVector<const TypeEntry *>;
92 #endif // TYPESYSTEM_TYPEDEFS_H