From 5893f103909ee0adc253f50adde841ba50582b29 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 18 Feb 2020 13:55:31 +0100 Subject: [PATCH] QMultiMap: Work around compiler problem in MSVC 2017 In more complex projects (like MuseScore) it is possible, that MSVC 2017 chokes on the usage of "using typename ...". Just fully specify the iterators when they are used. Fixes: QTBUG-82166 Change-Id: I5e7882a0963445fc8529cfcb59d2aae606a2777e Reviewed-by: Lars Knoll --- src/corelib/tools/qmap.h | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 281812b5e6..2abdc5e60e 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -1112,13 +1112,11 @@ public: QList uniqueKeys() const; QList values(const Key &key) const; - using typename QMap::iterator; - using typename QMap::const_iterator; - inline typename QMap::iterator replace(const Key &key, const T &value) { return QMap::insert(key, value); } - iterator insert(const Key &key, const T &value); - iterator insert(const_iterator pos, const Key &key, const T &value); + typename QMap::iterator insert(const Key &key, const T &value); + typename QMap::iterator insert(typename QMap::const_iterator pos, + const Key &keyi, const T &value); QMultiMap &unite(const QMultiMap &other); inline QMultiMap &operator+=(const QMultiMap &other) @@ -1177,7 +1175,7 @@ Q_OUTOFLINE_TEMPLATE QList QMultiMap::uniqueKeys() const { QList res; res.reserve(size()); // May be too much, but assume short lifetime - const_iterator i = this->begin(); + typename QMap::const_iterator i = this->begin(); if (i != this->end()) { for (;;) { const Key &aKey = i.key(); @@ -1198,7 +1196,7 @@ Q_OUTOFLINE_TEMPLATE QList QMultiMap::values(const Key &akey) const QList res; Node *n = this->d->findNode(akey); if (n) { - const_iterator it(n); + typename QMap::const_iterator it(n); do { res.append(*it); ++it; @@ -1208,8 +1206,8 @@ Q_OUTOFLINE_TEMPLATE QList QMultiMap::values(const Key &akey) const } template -Q_INLINE_TEMPLATE typename QMultiMap::iterator QMultiMap::insert(const Key &akey, - const T &avalue) +Q_INLINE_TEMPLATE typename QMap::iterator QMultiMap::insert(const Key &akey, + const T &avalue) { detach(); Node* y = this->d->end(); @@ -1221,11 +1219,12 @@ Q_INLINE_TEMPLATE typename QMultiMap::iterator QMultiMap::insert x = left ? x->leftNode() : x->rightNode(); } Node *z = this->d->createNode(akey, avalue, y, left); - return iterator(z); + return typename QMap::iterator(z); } template -typename QMultiMap::iterator QMultiMap::insert(const_iterator pos, const Key &akey, const T &avalue) +typename QMap::iterator QMultiMap::insert(typename QMap::const_iterator pos, + const Key &akey, const T &avalue) { if (this->d->ref.isShared()) return insert(akey, avalue); @@ -1242,7 +1241,7 @@ typename QMultiMap::iterator QMultiMap::insert(const_iterator po if (!qMapLessThanKey(n->key, akey)) return insert(akey, avalue); // ignore hint Node *z = this->d->createNode(akey, avalue, n, false); // insert right most - return iterator(z); + return typename QMap::iterator(z); } return insert(akey, avalue); } else { @@ -1255,7 +1254,7 @@ typename QMultiMap::iterator QMultiMap::insert(const_iterator po if (pos == this->constBegin()) { // There is no previous value (insert left most) Node *z = this->d->createNode(akey, avalue, this->begin().i, true); - return iterator(z); + return typename QMap::iterator(z); } else { Node *prev = const_cast(pos.i->previousNode()); if (!qMapLessThanKey(prev->key, akey)) @@ -1264,11 +1263,11 @@ typename QMultiMap::iterator QMultiMap::insert(const_iterator po // Hint is ok - do insert if (prev->right == nullptr) { Node *z = this->d->createNode(akey, avalue, prev, false); - return iterator(z); + return typename QMap::iterator(z); } if (next->left == nullptr) { Node *z = this->d->createNode(akey, avalue, next, true); - return iterator(z); + return typename QMap::iterator(z); } Q_ASSERT(false); // We should have prev->right == nullptr or next->left == nullptr. return insert(akey, avalue); @@ -1280,8 +1279,8 @@ template Q_INLINE_TEMPLATE QMultiMap &QMultiMap::unite(const QMultiMap &other) { QMultiMap copy(other); - const_iterator it = copy.constEnd(); - const const_iterator b = copy.constBegin(); + typename QMap::const_iterator it = copy.constEnd(); + const typename QMap::const_iterator b = copy.constBegin(); while (it != b) { --it; insert(it.key(), it.value()); @@ -1319,8 +1318,8 @@ Q_INLINE_TEMPLATE int QMultiMap::count(const Key &akey) const QMultiMap::Node *lastNode; this->d->nodeRange(akey, &firstNode, &lastNode); - const_iterator ci_first(firstNode); - const const_iterator ci_last(lastNode); + typename QMap::const_iterator ci_first(firstNode); + const typename QMap::const_iterator ci_last(lastNode); int cnt = 0; while (ci_first != ci_last) { ++cnt;