From 31c232d3b7297cbc288815297c75968d5c80ac18 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 3 Aug 2020 16:42:30 +0200 Subject: QList: properly declare operator== for MSVC The operators were declared as friend function templates (so, free functions in the Qt namespace). Unfortunately, the template argument of the operators was also defaulted -- causing MSVC trying to instantiate those functions at all times, causing interesting recursive template instantiation errors (C2968). It's extremely likely that we're facing a MSVC bug, but work around it by not defaulting the template argument. This in turn requires to move the function definition outside QList's definition, otherwise an extern template definition (like the ones we have for QList) would cause a template redefinition error... Change-Id: If03477ac1fa0a72aa252bb9e08e2a19c2b517b1b Reviewed-by: Lars Knoll --- src/corelib/tools/qlist.h | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 443789b411..35dc286191 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -162,22 +162,10 @@ public: void swap(QList &other) noexcept { qSwap(d, other.d); } - template - friend QTypeTraits::compare_eq_result operator==(const QList &l, const QList &r) - { - if (l.size() != r.size()) - return false; - if (l.begin() == r.begin()) - return true; - - // do element-by-element comparison - return l.d->compare(l.begin(), r.begin(), l.size()); - } - template - friend QTypeTraits::compare_eq_result operator!=(const QList &l, const QList &r) - { - return !(l == r); - } + template + friend QTypeTraits::compare_eq_result operator==(const QList &l, const QList &r); + template + friend QTypeTraits::compare_eq_result operator!=(const QList &l, const QList &r); qsizetype size() const noexcept { return d->size; } qsizetype count() const noexcept { return size(); } @@ -792,6 +780,24 @@ size_t qHash(const QList &key, size_t seed = 0) return qHashRange(key.cbegin(), key.cend(), seed); } +template +QTypeTraits::compare_eq_result operator==(const QList &l, const QList &r) +{ + if (l.size() != r.size()) + return false; + if (l.begin() == r.begin()) + return true; + + // do element-by-element comparison + return l.d->compare(l.begin(), r.begin(), l.size()); +} + +template +QTypeTraits::compare_eq_result operator!=(const QList &l, const QList &r) +{ + return !(l == r); +} + template auto operator<(const QList &lhs, const QList &rhs) noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), -- cgit v1.2.3