From dc9c43b115ec8f76f6ffea00092c721dce8369fa Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 May 2021 10:41:29 +0200 Subject: QVector: fix compilation failure in C++20 mode w/strict iterators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given QVector v(count, 0); GCC 10 in C++2a mode complained: /d/Qt/5.15.2/gcc_64/include/QtCore/qvector.h:532:18: error: ambiguous overload for ‘operator!=’ (operand types are ‘int*’ and ‘QTypedArrayData::iterator’) 532 | while (i != d->begin()) | ~~^~~~~~~~~~~~~ /d/Qt/5.15.2/gcc_64/include/QtCore/qarraydata.h:148:21: note: candidate: ‘bool QTypedArrayData::iterator::operator==(const QTypedArrayData::iterator&) const [with T = int]’ (reversed) 148 | inline bool operator==(const iterator &o) const { return i == o.i; } | ^~~~~~~~ /d/Qt/5.15.2/gcc_64/include/QtCore/qvector.h:532:18: note: candidate: ‘operator!=(int*, int*)’ (built-in) 532 | while (i != d->begin()) | ~~^~~~~~~~~~~~~ Fix by making `i` an QTypedArrayData::iterator, not a T*. A more thorough fix would systematically evaluate the impact of C++20 relational operator changes on the whole Qt codebase, but this is out of scope for this patch. [ChangeLog][QtCore][QVector] Fixed a compile error in QVector(int, T) that occurred in C++20 mode with QT_STRICT_ITERATORS. Change-Id: Ia71e2bb7d9e252b13fb31cca00ed58a011d52971 Reviewed-by: Volker Hilsheimer Reviewed-by: Giuseppe D'Angelo --- src/corelib/tools/qvector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/tools/qvector.h') diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 75e01cfa3a..efdea05714 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -523,7 +523,7 @@ QVector::QVector(int asize, const T &t) d = Data::allocate(asize); Q_CHECK_PTR(d); d->size = asize; - T* i = d->end(); + auto i = d->end(); while (i != d->begin()) new (--i) T(t); } else { -- cgit v1.2.3-59-g8ed1b