QList: fix std::to_address(QList::iterator) on older compilers
Need to enable element_type unconditionally, to direct the default std::pointer_traits::to_address to fall back to operator->(). [ChangeLog][QtCore][QList] Fixed std::to_address() on QList::iterator on older compilers. Fixes: QTBUG-130643 Change-Id: I521f327933c51ca87c511a7741b2dce65094032b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit b8c879f273533d87f52dbc8e9d2f9b3b3566cd60) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
21c839636c
commit
6535b6d5f3
@ -120,8 +120,8 @@ public:
|
|||||||
using value_type = T;
|
using value_type = T;
|
||||||
#ifdef QT_COMPILER_HAS_LWG3346
|
#ifdef QT_COMPILER_HAS_LWG3346
|
||||||
using iterator_concept = std::contiguous_iterator_tag;
|
using iterator_concept = std::contiguous_iterator_tag;
|
||||||
using element_type = value_type;
|
|
||||||
#endif
|
#endif
|
||||||
|
using element_type = value_type;
|
||||||
using iterator_category = std::random_access_iterator_tag;
|
using iterator_category = std::random_access_iterator_tag;
|
||||||
using pointer = T *;
|
using pointer = T *;
|
||||||
using reference = T &;
|
using reference = T &;
|
||||||
@ -190,8 +190,8 @@ public:
|
|||||||
using value_type = T;
|
using value_type = T;
|
||||||
#ifdef QT_COMPILER_HAS_LWG3346
|
#ifdef QT_COMPILER_HAS_LWG3346
|
||||||
using iterator_concept = std::contiguous_iterator_tag;
|
using iterator_concept = std::contiguous_iterator_tag;
|
||||||
using element_type = const value_type;
|
|
||||||
#endif
|
#endif
|
||||||
|
using element_type = const value_type;
|
||||||
using iterator_category = std::random_access_iterator_tag;
|
using iterator_category = std::random_access_iterator_tag;
|
||||||
using pointer = const T *;
|
using pointer = const T *;
|
||||||
using reference = const T &;
|
using reference = const T &;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <qlist.h>
|
#include <qlist.h>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <QtCore/q20memory.h>
|
||||||
|
|
||||||
#ifdef QT_COMPILER_HAS_LWG3346
|
#ifdef QT_COMPILER_HAS_LWG3346
|
||||||
# if __has_include(<concepts>)
|
# if __has_include(<concepts>)
|
||||||
@ -340,6 +341,7 @@ private slots:
|
|||||||
void swapInt() const { swap<int>(); }
|
void swapInt() const { swap<int>(); }
|
||||||
void swapMovable() const { swap<Movable>(); }
|
void swapMovable() const { swap<Movable>(); }
|
||||||
void swapCustom() const { swap<Custom>(); }
|
void swapCustom() const { swap<Custom>(); }
|
||||||
|
void toAddress() const;
|
||||||
void toList() const;
|
void toList() const;
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||||
void fromStdVector() const;
|
void fromStdVector() const;
|
||||||
@ -2935,6 +2937,23 @@ void tst_QList::startsWith() const
|
|||||||
QVERIFY(myvec.startsWith(1));
|
QVERIFY(myvec.startsWith(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QList::toAddress() const
|
||||||
|
{
|
||||||
|
// Annoyingly, QList::iterator is a class; make sure std::to_address works on them
|
||||||
|
QList<int> 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<typename T>
|
template<typename T>
|
||||||
void tst_QList::swap() const
|
void tst_QList::swap() const
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user