From bb11f7a9fa576b679fc64b09abadebf90dfbe9a1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 8 Aug 2023 10:17:15 +0200 Subject: [PATCH] QStorageInfo manual test: port away from Q_FOREACH In main.cpp, the loop is over a local variable which would be const were it not for the multi-step initialization that I didn't want to change. The loop body clearly doesn't modify the container, so port to ranged for loop with std::as_const(). In printvolumes.cpp, the loop _does_ invoke unknown code (through the function pointer passed as the second argument), but, as could be expected, the two users of the function don't pass functions that know about `volumes`: - in the tst_QStorageInfo auto-test, an rvalue `volumes` is passed, so we don't need to analyze the qInfoPrinter function passed there, as it cannot possibly reference the temporary - and in main.cpp of the manual test, we just pass printf (which is technically UB (taking the address of a standard library function), but I don't care right now). Pick-to: 6.6 6.5 Task-number: QTBUG-115839 Change-Id: Ibcd10a0e0b3229d8f2a1d98545d8fa6d473a0f75 Reviewed-by: Thiago Macieira Reviewed-by: Ahmad Samir --- tests/manual/qstorageinfo/main.cpp | 2 +- tests/manual/qstorageinfo/printvolumes.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/manual/qstorageinfo/main.cpp b/tests/manual/qstorageinfo/main.cpp index a2fd95129c7..5c01a151133 100644 --- a/tests/manual/qstorageinfo/main.cpp +++ b/tests/manual/qstorageinfo/main.cpp @@ -15,7 +15,7 @@ int main(int argc, char *argv[]) QStringList args = a.arguments(); args.takeFirst(); // skip application name - foreach (const QString &path, args) { + for (const QString &path : std::as_const(args)) { QStorageInfo info(path); if (!info.isValid()) { // no error string... diff --git a/tests/manual/qstorageinfo/printvolumes.cpp b/tests/manual/qstorageinfo/printvolumes.cpp index 5e4fdd4863d..538f1ea603c 100644 --- a/tests/manual/qstorageinfo/printvolumes.cpp +++ b/tests/manual/qstorageinfo/printvolumes.cpp @@ -13,7 +13,7 @@ void printVolumes(const QList &volumes, int (*printer)(const char // /dev/disk1s2 (hfs) RW 488050672 419909696 4096 Macintosh HD2 /Volumes/Macintosh HD2 printer("Filesystem (Type) Size Available BSize Label Mounted on\n"); - foreach (const QStorageInfo &info, volumes) { + for (const QStorageInfo &info : volumes) { QByteArray fsAndType = info.device(); if (info.fileSystemType() != fsAndType) fsAndType += " (" + info.fileSystemType() + ')';