From 6864576577baa4b1fa512d5cc4ed4c54eda784e7 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sun, 13 Aug 2023 18:40:00 +0300 Subject: [PATCH] tst_qmakelib: compile with QT_NO_FOREACH proEval(), proParser(): the loop was iterating over a temporary so it couldn't have changed it. Hold the container in a const auto variable and use ranged-for. formatValue(): iterating over a const QList& parameter, and the container isn't changed at the call sites during iterating, so Q_FOREACH wasn't needed to beging with. Use ranged-for instead. Task-number: QTBUG-115839 Change-Id: Idabe0bbd84b5bcc86cef275f80497651353a4d9e Reviewed-by: Joerg Bornemann --- tests/auto/tools/qmakelib/CMakeLists.txt | 3 --- tests/auto/tools/qmakelib/evaltest.cpp | 8 +++----- tests/auto/tools/qmakelib/parsertest.cpp | 6 ++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/auto/tools/qmakelib/CMakeLists.txt b/tests/auto/tools/qmakelib/CMakeLists.txt index 271c369cf0..4c6a1e2a72 100644 --- a/tests/auto/tools/qmakelib/CMakeLists.txt +++ b/tests/auto/tools/qmakelib/CMakeLists.txt @@ -24,9 +24,6 @@ qt_internal_add_test(tst_qmakelib evaltest.cpp parsertest.cpp tst_qmakelib.cpp tst_qmakelib.h - NO_PCH_SOURCES - evaltest.cpp # undef QT_NO_FOREACH - parsertest.cpp # undef QT_NO_FOREACH DEFINES PROEVALUATOR_FULL PROEVALUATOR_SETENV diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp index 94355efdd8..e4174ccfb2 100644 --- a/tests/auto/tools/qmakelib/evaltest.cpp +++ b/tests/auto/tools/qmakelib/evaltest.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 "tst_qmakelib.h" #include @@ -2748,7 +2746,7 @@ static QString formatValue(const ProStringList &vals) { QString ret; - foreach (const ProString &str, vals) { + for (const ProString &str : vals) { ret += QLatin1Char(' '); ret += QMakeEvaluator::quoteValue(str); } @@ -2866,9 +2864,9 @@ void tst_qmakelib::proEval() qWarning("Got unexpected message(s)"); verified = false; } - QStringList missingMsgs = handler.expectedMessages(); + const QStringList missingMsgs = handler.expectedMessages(); if (!missingMsgs.isEmpty()) { - foreach (const QString &msg, missingMsgs) + for (const QString &msg : missingMsgs) qWarning("Missing message: %s", qPrintable(msg)); verified = false; } diff --git a/tests/auto/tools/qmakelib/parsertest.cpp b/tests/auto/tools/qmakelib/parsertest.cpp index ec1ec5ccbb..1d9c7e38d0 100644 --- a/tests/auto/tools/qmakelib/parsertest.cpp +++ b/tests/auto/tools/qmakelib/parsertest.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 "tst_qmakelib.h" #include @@ -2013,9 +2011,9 @@ void tst_qmakelib::proParser() qWarning("Got unexpected message(s)"); verified = false; } - QStringList missingMsgs = handler.expectedMessages(); + const QStringList missingMsgs = handler.expectedMessages(); if (!missingMsgs.isEmpty()) { - foreach (const QString &msg, missingMsgs) + for (const QString &msg : missingMsgs) qWarning("Missing message: %s", qPrintable(msg)); verified = false; }