Fix compilation on MSVC 2008
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 23 May 2014 08:05:51 +0000 (10:05 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 27 May 2014 05:53:45 +0000 (07:53 +0200)
We are using std::lower_bound on a vector where the item we search for
is of a different type than the items in the container. MSVC 2008's STL
is very happy to check all sorts of constraints and also compare the order
of items within the container. That means it tries to call the compare function
not only with the key we're searching and one item but also two items from
the container. The existing compare function can't satisfy that constraint,
so instead we'll go back to the old approach of a proper functor that
operates outside of the class scope, in order to build with older compilers.

That functor now offers all necessary overloads.

Task-number: QTBUG-38873
Change-Id: I6f350106f98cb03a4ff7e1671a84e67f629cedd3
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
src/qml/compiler/qqmltypecompiler.cpp

index 1110b3f29dd4da8d4f8e85def5493196fa1d86ed..60a0829b9b483223be33bab4e63314195ee7b83d 100644 (file)
@@ -1759,10 +1759,21 @@ QString QQmlPropertyValidator::bindingAsString(int objectIndex, const QV4::Compi
 
 typedef QVarLengthArray<const QV4::CompiledData::Binding *, 8> GroupPropertyVector;
 
-static bool compareNameIndices(const QV4::CompiledData::Binding *binding, quint32 name)
+struct BindingFinder
 {
-    return binding->propertyNameIndex < name;
-}
+    bool operator()(quint32 name, const QV4::CompiledData::Binding *binding) const
+    {
+        return name < binding->propertyNameIndex;
+    }
+    bool operator()(const QV4::CompiledData::Binding *binding, quint32 name) const
+    {
+        return binding->propertyNameIndex < name;
+    }
+    bool operator()(const QV4::CompiledData::Binding *lhs, const QV4::CompiledData::Binding *rhs) const
+    {
+        return lhs->propertyNameIndex < rhs->propertyNameIndex;
+    }
+};
 
 bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledData::Binding *instantiatingBinding, bool populatingValueTypeGroupProperty)
 {
@@ -1810,7 +1821,7 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD
             return false;
         }
 
-        GroupPropertyVector::const_iterator pos = std::lower_bound(groupProperties.constBegin(), groupProperties.constEnd(), binding->propertyNameIndex, compareNameIndices);
+        GroupPropertyVector::const_iterator pos = std::lower_bound(groupProperties.constBegin(), groupProperties.constEnd(), binding->propertyNameIndex, BindingFinder());
         groupProperties.insert(pos, binding);
     }
 
@@ -1923,7 +1934,7 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD
         }
 
         if (pd) {
-            GroupPropertyVector::const_iterator assignedGroupProperty = std::lower_bound(groupProperties.constBegin(), groupProperties.constEnd(), binding->propertyNameIndex, compareNameIndices);
+            GroupPropertyVector::const_iterator assignedGroupProperty = std::lower_bound(groupProperties.constBegin(), groupProperties.constEnd(), binding->propertyNameIndex, BindingFinder());
             const bool assigningToGroupProperty = assignedGroupProperty != groupProperties.constEnd() && !(binding->propertyNameIndex < (*assignedGroupProperty)->propertyNameIndex);
 
             if (!pd->isWritable()