From 645dcc27d3567a2a39baa11e37bd3e1dfb25e8f7 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 11 Aug 2023 02:47:10 +0300 Subject: [PATCH] tst_QAbstractFileEngine: compile with QT_NO_FOREACH cleanupTestCase(): the loop doesn't modify the member container, so use std::as_const and a ranged-for. mounting(): the loop was iterating over a temporary QList, store it in a local auto variable and use ranged-for. Drive-by change: add braces to a multi-lined for block. Task-number: QTBUG-115839 Change-Id: I0542cad4df3730d6a09b39e64a54a84fc0d57062 Reviewed-by: Fabian Kosmale Reviewed-by: Marc Mutz --- .../io/qabstractfileengine/tst_qabstractfileengine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/corelib/io/qabstractfileengine/tst_qabstractfileengine.cpp b/tests/auto/corelib/io/qabstractfileengine/tst_qabstractfileengine.cpp index 029ef373732..c62fa3571bf 100644 --- a/tests/auto/corelib/io/qabstractfileengine/tst_qabstractfileengine.cpp +++ b/tests/auto/corelib/io/qabstractfileengine/tst_qabstractfileengine.cpp @@ -1,8 +1,6 @@ // Copyright (C) 2016 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 @@ -514,12 +512,13 @@ void tst_QAbstractFileEngine::cleanupTestCase() bool failed = false; FileEngineHandler handler; - Q_FOREACH(QString file, filesForRemoval) + for (const QString &file : std::as_const(filesForRemoval)) { if (!QFile::remove(file) || QFile::exists(file)) { failed = true; qDebug() << "Couldn't remove file:" << file; } + } QVERIFY(!failed); @@ -825,7 +824,8 @@ void tst_QAbstractFileEngine::mounting() QCOMPARE(dir.entryList(), (QStringList() << "bar" << "foo")); QDir dir2(fs.path()); bool found = false; - foreach (QFileInfo info, dir2.entryInfoList()) { + const auto entries = dir2.entryInfoList(); + for (const QFileInfo &info : entries) { if (info.fileName() == QLatin1String("test.tar")) { QVERIFY(!found); found = true;