From c7a8e1e9928fc2b84e6179adc69c858b17b25d48 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 11 Aug 2023 02:57:57 +0300 Subject: [PATCH] tst_QDirIterator: build with QT_NO_FOREACH cleanupTestCase: the loops don't change the member containers, so use std::as_const and ranged for. iterateRelativeDirectory(): the for loop doesn't change the container, so make it const to begin with, and use a ranged-for loop. Drive-by change: make the for-loop variables const&, no need to create unnecessary copies. Task-number: QTBUG-115839 Change-Id: Ic2776459f695c9f334f83916b1c9bbe5646a3b9d Reviewed-by: Volker Hilsheimer --- .../auto/corelib/io/qdiriterator/tst_qdiriterator.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp index 57bbff529d..bd36b937f1 100644 --- a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp +++ b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp @@ -1,8 +1,6 @@ // Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses - #include #include @@ -194,10 +192,10 @@ void tst_QDirIterator::initTestCase() void tst_QDirIterator::cleanupTestCase() { - Q_FOREACH(QString fileName, createdFiles) + for (const QString &fileName : std::as_const(createdFiles)) QFile::remove(fileName); - Q_FOREACH(QString dirName, createdDirectories) + for (const QString &dirName : std::as_const(createdDirectories)) currentDir.rmdir(dirName); } @@ -325,7 +323,7 @@ void tst_QDirIterator::iterateRelativeDirectory() QFETCH(QDirIterator::IteratorFlags, flags); QFETCH(QDir::Filters, filters); QFETCH(QStringList, nameFilters); - QFETCH(QStringList, entries); + QFETCH(const QStringList, entries); QDirIterator it(dirName, nameFilters, filters, flags); QStringList list; @@ -353,7 +351,7 @@ void tst_QDirIterator::iterateRelativeDirectory() list.sort(); QStringList sortedEntries; - foreach(QString item, entries) + for (const QString &item : entries) sortedEntries.append(QFileInfo(item).canonicalFilePath()); sortedEntries.sort();