tst_moc: compile with QT_NO_FOREACH

specifyMetaTagsFromCmdline(): the loop was iterating over a temporary so
it couldn't have modified it; hold it with a const auto variable and use
ranged-for.

relatedMetaObjectsNameConflict_data(): make the container const and port
to ranged-for.

Task-number: QTBUG-115839
Change-Id: I6a5afdf0e5a3dd47818da0025fbbeacd05335b39
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ahmad Samir 2023-08-13 18:33:05 +03:00
parent 890a61fba0
commit 192e1ed649
2 changed files with 4 additions and 7 deletions

View File

@ -72,8 +72,6 @@ qt_internal_add_test(tst_moc
cxx-attributes.h cxx-attributes.h
tst_moc.cpp tst_moc.cpp
${comparison_relevant_moc_list} ${comparison_relevant_moc_list}
NO_PCH_SOURCES
tst_moc.cpp # undef QT_NO_FOREACH
INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES
testproject testproject
testproject/include testproject/include

View File

@ -2,8 +2,6 @@
// Copyright (C) 2020 Olivier Goffart <ogoffart@woboq.com> // Copyright (C) 2020 Olivier Goffart <ogoffart@woboq.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // 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 <QTest> #include <QTest>
#include <QSignalSpy> #include <QSignalSpy>
#include <stdio.h> #include <stdio.h>
@ -1573,7 +1571,8 @@ public:
static StaticPluginInstance staticInstance; static StaticPluginInstance staticInstance;
void tst_Moc::specifyMetaTagsFromCmdline() { void tst_Moc::specifyMetaTagsFromCmdline() {
foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) { const auto staticPlugins = QPluginLoader::staticPlugins();
for (const QStaticPlugin &plugin : staticPlugins) {
const QString iid = plugin.metaData().value(QLatin1String("IID")).toString(); const QString iid = plugin.metaData().value(QLatin1String("IID")).toString();
if (iid == QLatin1String("test.meta.tags")) { if (iid == QLatin1String("test.meta.tags")) {
const QJsonArray metaTagsUriList = plugin.metaData().value("uri").toArray(); const QJsonArray metaTagsUriList = plugin.metaData().value("uri").toArray();
@ -3910,7 +3909,7 @@ void tst_Moc::relatedMetaObjectsNameConflict()
{ {
typedef QList<const QMetaObject *> QMetaObjects; typedef QList<const QMetaObject *> QMetaObjects;
QFETCH(const QMetaObject*, dependingObject); QFETCH(const QMetaObject*, dependingObject);
QFETCH(QMetaObjects, relatedMetaObjects); QFETCH(const QMetaObjects, relatedMetaObjects);
// load all specified metaobjects int a set // load all specified metaobjects int a set
QSet<const QMetaObject*> dependency; QSet<const QMetaObject*> dependency;
@ -3921,7 +3920,7 @@ void tst_Moc::relatedMetaObjectsNameConflict()
} }
// check if all required metaobjects are specified // check if all required metaobjects are specified
foreach (const QMetaObject *mo, relatedMetaObjects) for (const QMetaObject *mo : relatedMetaObjects)
QVERIFY(dependency.contains(mo)); QVERIFY(dependency.contains(mo));
// check if no additional metaobjects ara specified // check if no additional metaobjects ara specified