From 33f7eb44ff33e0f8f516a9e8076dfdb6098cfc6f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 7 Aug 2023 18:23:35 +0200 Subject: [PATCH] dbus test headers: port away from Q_FOREACH Headers must be free of Q_FOREACH uses if we want to white-list only those .cpp files that still use Q_FOREACH in order to enable QT_NO_FOREACH by default. In common.h, the situation is pretty clear: the loop bodies clearly don't modify the container being iterated over. In MyServer, the situation is not clear at all, and this author doesn't have the time to investigate, so take a copy and iterate over that (eactly what Q_FOREACH does), and leave a comment. As a drive-by, fix missing {} around multi-line loop bodies. Task-number: QTBUG-115839 Change-Id: I06311a641c83daeee25f45522c694ac355ee86b6 Reviewed-by: Ievgenii Meshcheriakov --- tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h | 6 ++++-- tests/auto/dbus/qdbusmarshall/common.h | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h index 46e53dad9b..02412066a8 100644 --- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h @@ -164,7 +164,8 @@ public: bool registerObject() { - Q_FOREACH (const QString &name, m_connections) { + const auto copy = m_connections; // needed? Loop doesn't modify, but handleConnection() does + for (const QString &name : copy) { if (!registerObject(QDBusConnection(name))) return false; } @@ -173,7 +174,8 @@ public: void unregisterObject() { - Q_FOREACH (const QString &name, m_connections) { + const auto copy = m_connections; // needed? Loop doesn't modify, but handleConnection() does + for (const QString &name : copy) { QDBusConnection c(name); c.unregisterObject(m_path); } diff --git a/tests/auto/dbus/qdbusmarshall/common.h b/tests/auto/dbus/qdbusmarshall/common.h index e972ca21a1..54056a3e72 100644 --- a/tests/auto/dbus/qdbusmarshall/common.h +++ b/tests/auto/dbus/qdbusmarshall/common.h @@ -206,12 +206,14 @@ inline const char* mapName(const PropertyMap&) QString printable(const QDBusIntrospection::Method& m) { QString result = "method " + m.name + "("; - foreach (QDBusIntrospection::Argument arg, m.inputArgs) + for (QDBusIntrospection::Argument arg : m.inputArgs) { result += QString("in %1 %2, ") .arg(arg.type, arg.name); - foreach (QDBusIntrospection::Argument arg, m.outputArgs) + } + for (QDBusIntrospection::Argument arg : m.outputArgs) { result += QString("out %1 %2, ") .arg(arg.type, arg.name); + } AnnotationsMap::const_iterator it = m.annotations.begin(); for ( ; it != m.annotations.end(); ++it) result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value().value); @@ -223,9 +225,10 @@ QString printable(const QDBusIntrospection::Method& m) QString printable(const QDBusIntrospection::Signal& s) { QString result = "signal " + s.name + "("; - foreach (QDBusIntrospection::Argument arg, s.outputArgs) + for (QDBusIntrospection::Argument arg : s.outputArgs) { result += QString("out %1 %2, ") .arg(arg.type, arg.name); + } AnnotationsMap::const_iterator it = s.annotations.begin(); for ( ; it != s.annotations.end(); ++it) result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value().value);