diff options
Diffstat (limited to 'tests/auto/corelib/tools/qlist')
-rw-r--r-- | tests/auto/corelib/tools/qlist/tst_qlist.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp index f37633b64c..8a7100d14c 100644 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp @@ -332,6 +332,7 @@ private slots: void emplaceConsistentWithStdVectorInt(); void emplaceConsistentWithStdVectorCustom(); void emplaceConsistentWithStdVectorMovable(); + void emplaceConsistentWithStdVectorQString(); void emplaceReturnsIterator(); void emplaceBack(); void emplaceBackReturnsRef(); @@ -874,7 +875,7 @@ void tst_QList::appendList() const v6 << (QList<ConstructionCounted>() << 3 << 4); QCOMPARE(v6, expectedFour); QCOMPARE(v6.at(0).copies, 2); - QCOMPARE(v6.at(0).moves, 1); + QCOMPARE(v6.at(0).moves, 2); // += QList<ConstructionCounted> v7; @@ -2916,6 +2917,11 @@ void tst_QList::emplaceConsistentWithStdVectorMovable() emplaceConsistentWithStdVectorImpl<Movable>(); } +void tst_QList::emplaceConsistentWithStdVectorQString() +{ + emplaceConsistentWithStdVectorImpl<QString>(); +} + void tst_QList::emplaceReturnsIterator() { QList<Movable> vec; @@ -3008,20 +3014,29 @@ static void squeezeVec(QList<T> &qVec, std::vector<T> &stdVec) template<typename T> void tst_QList::emplaceConsistentWithStdVectorImpl() const { - QList<T> qVec {'a', 'b', 'c', 'd', 'e'}; - std::vector<T> stdVec {'a', 'b', 'c', 'd', 'e'}; + // fast-patch to make QString work with the old logic + const auto convert = [] (char i) { + if constexpr (std::is_same_v<QString, T>) { + return QChar(i); + } else { + return i; + } + }; + + QList<T> qVec {convert('a'), convert('b'), convert('c'), convert('d'), convert('e')}; + std::vector<T> stdVec {convert('a'), convert('b'), convert('c'), convert('d'), convert('e')}; vecEq(qVec, stdVec); - qVec.emplaceBack('f'); - stdVec.emplace_back('f'); + qVec.emplaceBack(convert('f')); + stdVec.emplace_back(convert('f')); vecEq(qVec, stdVec); - qVec.emplace(3, 'g'); - stdVec.emplace(stdVec.begin() + 3, 'g'); + qVec.emplace(3, convert('g')); + stdVec.emplace(stdVec.begin() + 3, convert('g')); vecEq(qVec, stdVec); T t; - // while QList is safe with regards to emplacing elements moved form itself, it's UB + // while QList is safe with regards to emplacing elements moved from itself, it's UB // for std::vector, so do the moving in two steps there. qVec.emplaceBack(std::move(qVec[0])); stdVec.emplace_back(std::move(t = std::move(stdVec[0]))); |