summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-10-06 11:08:21 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-10-11 23:17:18 +0200
commitaa37e67ef7f5ff22da0ef95fb5221bc1fff9b3ca (patch)
treebe5e1a9733987aed8602eb47618cd1673a594570 /tests/auto/corelib
parentfd2685c2f0a219c091e028a98ba6cdd154986fec (diff)
Port from qAsConst() to std::as_const()
We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qlogging.cpp2
-rw-r--r--tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp2
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp2
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp10
-rw-r--r--tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp2
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp2
-rw-r--r--tests/auto/corelib/serialization/json/tst_qtjson.cpp2
-rw-r--r--tests/auto/corelib/serialization/qcborstreamwriter/tst_qcborstreamwriter.cpp4
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp24
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp4
-rw-r--r--tests/auto/corelib/text/qstringview/tst_qstringview.cpp2
-rw-r--r--tests/auto/corelib/thread/qfuture/tst_qfuture.cpp4
-rw-r--r--tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp8
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp2
14 files changed, 35 insertions, 35 deletions
diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
index be27ab65b9..1b80287250 100644
--- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
@@ -784,7 +784,7 @@ void tst_qmessagehandler::qMessagePattern()
QVERIFY(!output.isEmpty());
QCOMPARE(!output.contains("QT_MESSAGE_PATTERN"), valid);
- for (const QByteArray &e : qAsConst(expected)) {
+ for (const QByteArray &e : std::as_const(expected)) {
if (!output.contains(e)) {
// use QDebug so we get proper string escaping for the newlines
QString buf;
diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
index 9ada7352b4..d0b1803d55 100644
--- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
+++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
@@ -610,7 +610,7 @@ template <typename UInt> static void boundedQuality_template()
QVector<UInt> buffer(BufferCount, filler);
generate(buffer.begin(), buffer.end(), [&] { return rng.bounded(Bound); });
- for (UInt value : qAsConst(buffer)) {
+ for (UInt value : std::as_const(buffer)) {
QVERIFY(value < Bound);
histogram[value]++;
}
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index f6933b7fdb..817c550c6e 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -1847,7 +1847,7 @@ void ListenerObject::slotAboutToBeReset()
void ListenerObject::slotReset()
{
- for (const auto &idx : qAsConst(m_persistentIndexes)) {
+ for (const auto &idx : std::as_const(m_persistentIndexes)) {
QVERIFY(!idx.isValid());
}
}
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 6e62c3de0b..d89c1fe004 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -3214,15 +3214,15 @@ void tst_QSortFilterProxyModel::removeRowsRecursive()
QList<QPersistentModelIndex> sourceIndexes;
QList<QPersistentModelIndex> proxyIndexes;
- for (const auto item : qAsConst(items)) {
+ for (const auto item : std::as_const(items)) {
QModelIndex idx = item->index();
sourceIndexes << idx;
proxyIndexes << proxy.mapFromSource(idx);
}
- for (const auto &pidx : qAsConst(sourceIndexes))
+ for (const auto &pidx : std::as_const(sourceIndexes))
QVERIFY(pidx.isValid());
- for (const auto &pidx : qAsConst(proxyIndexes))
+ for (const auto &pidx : std::as_const(proxyIndexes))
QVERIFY(pidx.isValid());
QList<QStandardItem*> itemRow = pItem1->takeRow(0);
@@ -3230,9 +3230,9 @@ void tst_QSortFilterProxyModel::removeRowsRecursive()
QCOMPARE(itemRow.size(), 1);
QCOMPARE(itemRow.first(), pItem11);
- for (const auto &pidx : qAsConst(sourceIndexes))
+ for (const auto &pidx : std::as_const(sourceIndexes))
QVERIFY(!pidx.isValid());
- for (const auto &pidx : qAsConst(proxyIndexes))
+ for (const auto &pidx : std::as_const(proxyIndexes))
QVERIFY(!pidx.isValid());
delete pItem11;
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
index bdcab06078..e805b7e8cc 100644
--- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
+++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
@@ -863,7 +863,7 @@ void tst_QMetaObject::invokeMetaMemberNoMacros()
QVERIFY(QMetaObject::invokeMethod(&obj, "sl1", t1));
QCOMPARE(obj.slotResult, QString("sl1:1"));
- QVERIFY(QMetaObject::invokeMethod(&obj, "sl2", qAsConst(t1), t2));
+ QVERIFY(QMetaObject::invokeMethod(&obj, "sl2", std::as_const(t1), t2));
QCOMPARE(obj.slotResult, QString("sl2:12"));
QVERIFY(QMetaObject::invokeMethod(&obj, "sl3", t1, t2, t3));
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index ba15b4a3a7..14d17f0e03 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -4333,7 +4333,7 @@ void testSequentialIteration()
int numSeen = 0;
auto varList = listVariant.value<QVariantList>();
auto varIter = varList.begin();
- for (const QVariant &v : qAsConst(listIter)) {
+ for (const QVariant &v : std::as_const(listIter)) {
QVERIFY(ContainerAPI<Container>::compare(v, *varIter));
++varIter;
++numSeen;
diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
index c7043ca433..6b553322b7 100644
--- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
@@ -940,7 +940,7 @@ void tst_QtJson::testValueRef()
QCOMPARE(object.value(QLatin1String("null")), QJsonValue());
object[QLatin1String("null")] = 100.;
QCOMPARE(object.value(QLatin1String("null")).type(), QJsonValue::Double);
- QJsonValue val = qAsConst(object)[QLatin1String("null")];
+ QJsonValue val = std::as_const(object)[QLatin1String("null")];
QCOMPARE(val.toDouble(), 100.);
QCOMPARE(object.size(), 2);
diff --git a/tests/auto/corelib/serialization/qcborstreamwriter/tst_qcborstreamwriter.cpp b/tests/auto/corelib/serialization/qcborstreamwriter/tst_qcborstreamwriter.cpp
index 5651cc3987..dca6cbe02b 100644
--- a/tests/auto/corelib/serialization/qcborstreamwriter/tst_qcborstreamwriter.cpp
+++ b/tests/auto/corelib/serialization/qcborstreamwriter/tst_qcborstreamwriter.cpp
@@ -83,7 +83,7 @@ void encodeVariant(QCborStreamWriter &writer, const QVariant &v)
} else {
writer.startArray(list.length());
}
- for (const QVariant &v2 : qAsConst(list))
+ for (const QVariant &v2 : std::as_const(list))
encodeVariant(writer, v2);
QVERIFY(writer.endArray());
return;
@@ -96,7 +96,7 @@ void encodeVariant(QCborStreamWriter &writer, const QVariant &v)
} else {
writer.startMap(map.length());
}
- for (auto pair : qAsConst(map)) {
+ for (auto pair : std::as_const(map)) {
encodeVariant(writer, pair.first);
encodeVariant(writer, pair.second);
}
diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
index d8dfc5e99a..82e2309680 100644
--- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
+++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
@@ -785,7 +785,7 @@ void tst_QCborValue::arrayInitializerList()
// range for
int i = 0;
- for (const QCborValue v : qAsConst(a)) {
+ for (const QCborValue v : std::as_const(a)) {
QVERIFY(!v.isInvalid());
QCOMPARE(v.isUndefined(), i == 5); // 6th element is Undefined
++i;
@@ -885,7 +885,7 @@ void tst_QCborValue::mapSimpleInitializerList()
// range for
int i = 0;
- for (auto pair : qAsConst(m)) {
+ for (auto pair : std::as_const(m)) {
QVERIFY(!pair.first.isUndefined());
QVERIFY(!pair.second.isUndefined());
++i;
@@ -1294,16 +1294,16 @@ void tst_QCborValue::arrayValueRefLargeKey()
a[LargeKey + 1] = 123;
QCborValue v(a);
- QCOMPARE(qAsConst(v)[LargeKey], QCborValue());
- QCOMPARE(qAsConst(v)[LargeKey + 1], 123);
+ QCOMPARE(std::as_const(v)[LargeKey], QCborValue());
+ QCOMPARE(std::as_const(v)[LargeKey + 1], 123);
QCOMPARE(v[LargeKey], QCborValue());
QCOMPARE(v[LargeKey + 1], 123);
QCOMPARE(v.type(), QCborValue::Array);
QCborArray outer = { QCborValue(a) };
QCborValueRef ref = outer[0];
- QCOMPARE(qAsConst(ref)[LargeKey], QCborValue());
- QCOMPARE(qAsConst(ref)[LargeKey + 1], 123);
+ QCOMPARE(std::as_const(ref)[LargeKey], QCborValue());
+ QCOMPARE(std::as_const(ref)[LargeKey + 1], 123);
QCOMPARE(ref[LargeKey], QCborValue());
QCOMPARE(ref[LargeKey + 1], 123);
QCOMPARE(ref.type(), QCborValue::Array);
@@ -1714,7 +1714,7 @@ void tst_QCborValue::arrayNested()
QCborArray a1 = { 42, 47 };
QCborArray a2 = { QCborValue(a1) };
QCOMPARE(a2.size(), 1);
- const QCborValue &first = qAsConst(a2).first();
+ const QCborValue &first = std::as_const(a2).first();
QVERIFY(first.isArray());
QCOMPARE(first.toArray(wrongArray).size(), 2);
QCOMPARE(first.toArray(wrongArray).first(), 42);
@@ -1735,7 +1735,7 @@ void tst_QCborValue::arrayNested()
QCborArray a1;
a1 = { QCborValue(a1) }; // insert it into itself
QCOMPARE(a1.size(), 1);
- const QCborValue &first = qAsConst(a1).first();
+ const QCborValue &first = std::as_const(a1).first();
QVERIFY(first.isArray());
QCOMPARE(first, QCborArray());
QCOMPARE(first.toArray(wrongArray), QCborArray());
@@ -1752,7 +1752,7 @@ void tst_QCborValue::arrayNested()
QCborArray a1;
a1.append(a1); // insert into itself
QCOMPARE(a1.size(), 1);
- const QCborValue &first = qAsConst(a1).first();
+ const QCborValue &first = std::as_const(a1).first();
QVERIFY(first.isArray());
QCOMPARE(first, QCborArray());
QCOMPARE(first.toArray(), QCborArray());
@@ -2694,9 +2694,9 @@ template <typename ValueRef> static void cborValueRef_template()
QCOMPARE(ref.toArray().isEmpty(), v.toArray().isEmpty());
QCOMPARE(ref.toMap().isEmpty(), v.toMap().isEmpty());
- QCOMPARE(ref[0], qAsConst(v)[0]);
- QCOMPARE(ref[QLatin1String("other")], qAsConst(v)[QLatin1String("other")]);
- QCOMPARE(ref[QString("other")], qAsConst(v)[QString("other")]);
+ QCOMPARE(ref[0], std::as_const(v)[0]);
+ QCOMPARE(ref[QLatin1String("other")], std::as_const(v)[QLatin1String("other")]);
+ QCOMPARE(ref[QString("other")], std::as_const(v)[QString("other")]);
if (qIsNaN(v.toDouble()))
QCOMPARE(qIsNaN(ref.toVariant().toDouble()), qIsNaN(v.toVariant().toDouble()));
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 242ab53011..26bd61c248 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -67,11 +67,11 @@ public:
template <typename MemFun>
void apply0(QString &s, MemFun mf) const
- { for (QChar ch : qAsConst(this->pinned)) (s.*mf)(ch); }
+ { for (QChar ch : std::as_const(this->pinned)) (s.*mf)(ch); }
template <typename MemFun, typename A1>
void apply1(QString &s, MemFun mf, A1 a1) const
- { for (QChar ch : qAsConst(this->pinned)) (s.*mf)(a1, ch); }
+ { for (QChar ch : std::as_const(this->pinned)) (s.*mf)(a1, ch); }
};
template <>
diff --git a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
index ccb12488a7..9eab2f6966 100644
--- a/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
+++ b/tests/auto/corelib/text/qstringview/tst_qstringview.cpp
@@ -854,7 +854,7 @@ void tst_QStringView::overloadResolution()
{
std::u16string string;
QStringViewOverloadResolution::test(string);
- QStringViewOverloadResolution::test(qAsConst(string));
+ QStringViewOverloadResolution::test(std::as_const(string));
QStringViewOverloadResolution::test(std::move(string));
}
}
diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
index 81120c6f67..6664bb4776 100644
--- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
+++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
@@ -1076,13 +1076,13 @@ void tst_QFuture::multipleResults()
QList<int> fasit = QList<int>() << 1 << 2 << 3 << 4;
{
QList<int> results;
- for (int result : qAsConst(f))
+ for (int result : std::as_const(f))
results.append(result);
QCOMPARE(results, fasit);
}
{
QList<int> results;
- for (int result : qAsConst(copy))
+ for (int result : std::as_const(copy))
results.append(result);
QCOMPARE(results, fasit);
}
diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
index 60023e1bf2..722a174a32 100644
--- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
+++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
@@ -746,14 +746,14 @@ void tst_ContainerApiSymmetry::front_back_impl() const
auto c1 = make<Container>(1);
QCOMPARE(clean(c1.front()), V(1));
QCOMPARE(clean(c1.back()), V(1));
- QCOMPARE(clean(qAsConst(c1).front()), V(1));
- QCOMPARE(clean(qAsConst(c1).back()), V(1));
+ QCOMPARE(clean(std::as_const(c1).front()), V(1));
+ QCOMPARE(clean(std::as_const(c1).back()), V(1));
auto c2 = make<Container>(2);
QCOMPARE(clean(c2.front()), V(1));
QCOMPARE(clean(c2.back()), V(2));
- QCOMPARE(clean(qAsConst(c2).front()), V(1));
- QCOMPARE(clean(qAsConst(c2).back()), V(2));
+ QCOMPARE(clean(std::as_const(c2).front()), V(1));
+ QCOMPARE(clean(std::as_const(c2).back()), V(2));
}
namespace {
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index c21dfbfafb..81edb36916 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -1108,7 +1108,7 @@ void tst_QVarLengthArray::operators()
// +=: not provided, emulate
//myvla += myvlatwo;
- for (const QString &s : qAsConst(myvlatwo))
+ for (const QString &s : std::as_const(myvlatwo))
myvla.push_back(s);
QCOMPARE(myvla, combined);