diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 6f98ef4d5bb..60c48d30e58 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -120,8 +120,8 @@ public: using value_type = T; #ifdef QT_COMPILER_HAS_LWG3346 using iterator_concept = std::contiguous_iterator_tag; - using element_type = value_type; #endif + using element_type = value_type; using iterator_category = std::random_access_iterator_tag; using pointer = T *; using reference = T &; @@ -190,8 +190,8 @@ public: using value_type = T; #ifdef QT_COMPILER_HAS_LWG3346 using iterator_concept = std::contiguous_iterator_tag; - using element_type = const value_type; #endif + using element_type = const value_type; using iterator_category = std::random_access_iterator_tag; using pointer = const T *; using reference = const T &; diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp index d879467da37..9ebfd7aee05 100644 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp @@ -15,6 +15,7 @@ #include #include +#include #ifdef QT_COMPILER_HAS_LWG3346 # if __has_include() @@ -340,6 +341,7 @@ private slots: void swapInt() const { swap(); } void swapMovable() const { swap(); } void swapCustom() const { swap(); } + void toAddress() const; void toList() const; #if QT_VERSION < QT_VERSION_CHECK(6,0,0) void fromStdVector() const; @@ -2935,6 +2937,23 @@ void tst_QList::startsWith() const QVERIFY(myvec.startsWith(1)); } +void tst_QList::toAddress() const +{ + // Annoyingly, QList::iterator is a class; make sure std::to_address works on them + QList l = {1, 2, 3, 4, 5}; + auto check = [&](auto b, auto e) { + QCOMPARE_EQ(q20::to_address(b), l.data()); + QCOMPARE_EQ(q20::to_address(e), l.data() + l.size()); + }; + // begin QTBUG-130643 + check(l.begin(), l.end()); + check(l.cbegin(), l.cend()); + // end QTBUG-130643 + // for reverse_iterator, account for the off-by-one to its ::base(): + check(l.rend() - 1, l.rbegin() - 1); + check(l.crend() - 1, l.crbegin() - 1); +} + template void tst_QList::swap() const {