shiboken2/clang: Fix clashes between type name and enumeration values
authorFriedemann Kleint <Friedemann.Kleint@qt.io>
Tue, 25 Apr 2023 13:30:30 +0000 (15:30 +0200)
committerDmitry Shachnev <mitya57@debian.org>
Sun, 17 Nov 2024 11:20:58 +0000 (14:20 +0300)
Remove all constant and enum value type entries found in the type lookup
unless it is looking for template arguments; where it may be a
non-type template argument.

Task-number: PYSIDE-2288
Pick-to: 6.5 5.15
Change-Id: If0609ce0d0223f551ed6dee1d1e0ea3ef49d6917
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit e22f717153a5e9855531f45c0bf82ff2461a3f7e)

Gbp-Pq: Name shiboken2-clang-Fix-clashes-between-type-name-and-enumera.patch

sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
sources/shiboken2/ApiExtractor/abstractmetabuilder.h
sources/shiboken2/ApiExtractor/typesystem_typedefs.h

index 5a413ecaa82b9f2257784b53c8bf512043dee6c3..2f34e16b6d0ffbb358db028dbd02905048c40b2f 100644 (file)
@@ -2144,6 +2144,13 @@ static bool isNumber(const QString &s)
                        [](QChar c) { return c.isDigit(); });
 }
 
+// A type entry relevant only for non type template "X<5>"
+static bool isNonTypeTemplateArgument(const TypeEntryCPtr &te)
+{
+    const auto type = te->type();
+    return type == TypeEntry::EnumValue || type == TypeEntry::ConstantValueType;
+}
+
 AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo &_typei,
                                                                   AbstractMetaClass *currentClass,
                                                                   AbstractMetaBuilderPrivate *d,
@@ -2271,7 +2278,15 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
         typeInfo.clearInstantiations();
     }
 
-    const TypeEntries types = findTypeEntries(qualifiedName, name, currentClass, d);
+    TypeEntries types = findTypeEntries(qualifiedName, name, currentClass, d);
+    if (!flags.testFlag(AbstractMetaBuilder::TemplateArgument)) {
+        // Avoid clashes between QByteArray and enum value QMetaType::QByteArray
+        // unless we are looking for template arguments.
+        auto end = std::remove_if(types.begin(), types.end(),
+                                  isNonTypeTemplateArgument);
+        types.erase(end, types.end());
+    }
+
     if (types.isEmpty()) {
         if (errorMessageIn) {
             *errorMessageIn =
@@ -2293,7 +2308,9 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
     const auto &templateArguments = typeInfo.instantiations();
     for (int t = 0, size = templateArguments.size(); t < size; ++t) {
         const  TypeInfo &ti = templateArguments.at(t);
-        AbstractMetaType *targType = translateTypeStatic(ti, currentClass, d, flags, &errorMessage);
+        AbstractMetaType *targType = translateTypeStatic(ti, currentClass, d,
+                                                         flags | AbstractMetaBuilder::TemplateArgument,
+                                                         &errorMessage);
         // For non-type template parameters, create a dummy type entry on the fly
         // as is done for classes.
         if (!targType) {
index d2dc080a2cbcb8abfd9dc9ff5f28df5525139f81..8916eaf25db8a15fa1a661055e72a64b85c18347 100644 (file)
@@ -93,7 +93,8 @@ public:
     void setSkipDeprecated(bool value);
 
     enum TranslateTypeFlag {
-        DontResolveType = 0x1
+        DontResolveType = 0x1,
+        TemplateArgument = 0x2
     };
     Q_DECLARE_FLAGS(TranslateTypeFlags, TranslateTypeFlag);
 
index 73f92b294a871ce949c63f412cc0914424ab7e2c..5dcc65c6513f2995751a35cf3c1e44739ed4a707 100644 (file)
@@ -48,6 +48,7 @@ using CodeSnipList = QVector<CodeSnip>;
 using DocModificationList = QVector<DocModification>;
 using FieldModificationList = QVector<FieldModification>;
 using FunctionModificationList = QVector<FunctionModification>;
+using TypeEntryCPtr = const TypeEntry *;
 using TypeEntries = QVector<const TypeEntry *>;
 
 #endif // TYPESYSTEM_TYPEDEFS_H