Mark the module as free of Q_FOREACH, except where it isn't

The density of Q_FOREACH uses is high here, too high for this author,
unfamiliar with this code, to tackle in a short amount of time. But
they're concentrated in just a few TUs, so pick a different strategy:

Mark the whole module with QT_NO_FOREACH, to prevent new uses from
creeping in, and whitelist the affected TUs by #undef'ing
QT_NO_FOREACH locally, at the top of each file. For TUs that are part
of a larger executable, this requires these files to be compiled
separately, so add them to NO_PCH_SOURCES (which implies
NO_UNITY_BUILD_SOURCES, too). Created QTBUG-115808 to keep track of
this.

Task-number: QTBUG-115808
Change-Id: I29c377f939e3d747e3ce72c224c4ee722df7a95d
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Marc Mutz 2023-08-06 17:03:37 +02:00
parent 2ed0abd553
commit 8edbcdbeb4
52 changed files with 118 additions and 1 deletions

View File

@ -3,3 +3,4 @@ set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1")
set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_LEAN_HEADERS=1")
list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_AS_CONST=1")
list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_FOREACH=1")

View File

@ -56,7 +56,6 @@ qt_internal_add_qml_module(QuickParticlesPrivate
qquickturbulence.cpp
# end undef QT_NO_FOREACH
DEFINES
QT_NO_FOREACH
QT_NO_INTEGER_EVENT_COORDINATES
QT_NO_URL_CAST_FROM_STRING
PUBLIC_LIBRARIES

View File

@ -20,6 +20,8 @@ qt_internal_add_plugin(QQmlDebuggerServiceFactoryPlugin
qv4debuggeragent.cpp qv4debuggeragent.h
qv4debugjob.cpp qv4debugjob.h
qv4debugservice.cpp qv4debugservice.h
NO_PCH_SOURCES
qv4debuggeragent.cpp # undef QT_NO_FOREACH
LIBRARIES
Qt::CorePrivate
Qt::PacketProtocolPrivate

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "qv4debuggeragent.h"
#include "qv4debugservice.h"
#include "qv4datacollector.h"

View File

@ -34,6 +34,8 @@ qt_internal_add_module(QmlDebugPrivate
qqmlprofilertypedevent.cpp qqmlprofilertypedevent_p.h
qv4debugclient.cpp qv4debugclient_p.h
qv4debugclient_p_p.h
NO_PCH_SOURCES
qv4debugclient.cpp # undef QT_NO_FOREACH
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Network

View File

@ -1,6 +1,8 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "qv4debugclient_p.h"
#include "qv4debugclient_p_p.h"
#include "qqmldebugconnection_p.h"

View File

@ -41,6 +41,8 @@ qt_internal_add_module(QmlDomPrivate
qqmldomtop.cpp qqmldomtop_p.h
qqmldomtypesreader.cpp qqmldomtypesreader_p.h
qqmldomscriptelements_p.h qqmldomscriptelements.cpp
NO_PCH_SOURCES
qqmldomcodeformatter.cpp # undef QT_NO_FOREACH
DEFINES
QMLDOM_LIBRARY
PUBLIC_LIBRARIES

View File

@ -1,6 +1,8 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "qqmldomcodeformatter_p.h"
#include <QLoggingCategory>

View File

@ -19,6 +19,8 @@ qt_internal_add_test(tst_qqmldebugclient
../shared/qqmldebugprocess.cpp ../shared/qqmldebugprocess_p.h
../shared/qqmldebugtestservice.cpp ../shared/qqmldebugtestservice.h
tst_qqmldebugclient.cpp
NO_PCH_SOURCES
tst_qqmldebugclient.cpp # undef QT_NO_FOREACH
DEFINES
QT_QML_DEBUG
QT_QML_DEBUG_NO_WARNING

View File

@ -1,6 +1,8 @@
// 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 "debugutil_p.h"
#include "qqmldebugtestservice.h"

View File

@ -18,6 +18,8 @@ qt_internal_add_test(tst_qqmldebuggingenabler
../../shared/debugutil.cpp ../../shared/debugutil_p.h
../../shared/qqmldebugprocess.cpp ../../shared/qqmldebugprocess_p.h
tst_qqmldebuggingenabler.cpp
NO_PCH_SOURCES
tst_qqmldebuggingenabler.cpp # undef QT_NO_FOREACH
INCLUDE_DIRECTORIES
../../shared
LIBRARIES

View File

@ -1,6 +1,8 @@
// 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 "debugutil_p.h"
#include "qqmldebugprocess_p.h"
#include <QtQuickTestUtils/private/qmlutils_p.h>

View File

@ -25,6 +25,8 @@ qt_internal_add_test(tst_qqmldebugservice
../shared/qqmldebugprocess.cpp ../shared/qqmldebugprocess_p.h
../shared/qqmldebugtestservice.cpp ../shared/qqmldebugtestservice.h
tst_qqmldebugservice.cpp
NO_PCH_SOURCES
tst_qqmldebugservice.cpp # undef QT_NO_FOREACH
DEFINES
QT_QML_DEBUG_NO_WARNING
INCLUDE_DIRECTORIES

View File

@ -1,6 +1,7 @@
// 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 "qqmldebugtestservice.h"
#include "debugutil_p.h"

View File

@ -24,6 +24,8 @@ qt_internal_add_test(tst_qqmlenginedebuginspectorintegration
../shared/debugutil.cpp ../shared/debugutil_p.h
../shared/qqmldebugprocess.cpp ../shared/qqmldebugprocess_p.h
tst_qqmlenginedebuginspectorintegration.cpp
NO_PCH_SOURCES
tst_qqmlenginedebuginspectorintegration.cpp # undef QT_NO_FOREACH
INCLUDE_DIRECTORIES
../shared
LIBRARIES

View File

@ -1,6 +1,8 @@
// 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 "../shared/debugutil_p.h"
#include <QtQuickTestUtils/private/qmlutils_p.h>

View File

@ -24,6 +24,8 @@ qt_internal_add_test(tst_qqmlprofilerservice
../shared/debugutil.cpp ../shared/debugutil_p.h
../shared/qqmldebugprocess.cpp ../shared/qqmldebugprocess_p.h
tst_qqmlprofilerservice.cpp
NO_PCH_SOURCES
tst_qqmlprofilerservice.cpp # undef QT_NO_FOREACH
INCLUDE_DIRECTORIES
../shared
LIBRARIES

View File

@ -1,6 +1,8 @@
// 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 "debugutil_p.h"
#include "qqmldebugprocess_p.h"
#include <QtQuickTestUtils/private/qmlutils_p.h>

View File

@ -39,6 +39,8 @@ qt_internal_add_test(tst_qv4debugger
../../../../../src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp ../../../../../src/plugins/qmltooling/qmldbg_debugger/qv4debugger.h
../../../../../src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp ../../../../../src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h
tst_qv4debugger.cpp
NO_PCH_SOURCES
tst_qv4debugger.cpp
INCLUDE_DIRECTORIES
../../../../../src/plugins/qmltooling/qmldbg_debugger
LIBRARIES

View File

@ -1,5 +1,8 @@
// 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 <QtQuickTestUtils/private/qmlutils_p.h>
#include <QtTest/QtTest>

View File

@ -1,5 +1,8 @@
// Copyright (C) 2021 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 <qtest.h>
#include <qrandom.h>
#include <private/qqmlchangeset_p.h>

View File

@ -1,6 +1,8 @@
// 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 <qtest.h>
#include <QObject>
#include <QQmlEngine>

View File

@ -23,6 +23,8 @@ qt_internal_add_test(tst_qqmlecmascript
SOURCES
testtypes.cpp testtypes.h
tst_qqmlecmascript.cpp
NO_PCH_SOURCES
testtypes.cpp # undef QT_NO_FOREACH
LIBRARIES
Qt::CorePrivate
Qt::Gui

View File

@ -1,5 +1,8 @@
// 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 "testtypes.h"
#ifndef QT_NO_WIDGETS
# include <QWidget>

View File

@ -1,6 +1,8 @@
// 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 <QQmlEngine>
#include <QQmlContext>
#include <QNetworkAccessManager>

View File

@ -1,6 +1,8 @@
// Copyright (C) 2017 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 <QtCore>
#include <QtTest>
#include <QtQml>

View File

@ -23,6 +23,9 @@ qt_internal_add_test(tst_qqmllanguage
SOURCES
testtypes.cpp testtypes.h
tst_qqmllanguage.cpp
NO_PCH_SOURCES
testtypes.cpp # undef QT_NO_FOREACH
tst_qqmllanguage.cpp # undef QT_NO_FOREACH
LIBRARIES
Qt::CorePrivate
Qt::Gui

View File

@ -1,5 +1,8 @@
// 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 "testtypes.h"
#include <private/qv4qmlcontext_p.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <private/qqmllistcompositor_p.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquicktext_p.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <qdir.h>
#include <QtQml/qqmlengine.h>

View File

@ -1,6 +1,8 @@
// 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 <private/qqmljsengine_p.h>
#include <private/qqmljsparser_p.h>
#include <private/qqmljslexer_p.h>

View File

@ -1,6 +1,8 @@
// 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 <private/qqmlengine_p.h>
#include <qtest.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>

View File

@ -23,6 +23,8 @@ qt_internal_add_test(tst_qqmlvaluetypes
SOURCES
testtypes.cpp testtypes.h
tst_qqmlvaluetypes.cpp
NO_PCH_SOURCES
tst_qqmlvaluetypes.cpp # undef QT_NO_FOREACH
LIBRARIES
Qt::CorePrivate
Qt::Gui

View File

@ -1,6 +1,8 @@
// 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 <qtest.h>
#include <QQmlEngine>
#include <QQmlComponent>

View File

@ -1,6 +1,8 @@
// Copyright (C) 2018 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 <QtTest/QtTest>
#include <QQmlEngine>
#include <QtQml>

View File

@ -1,6 +1,8 @@
// Copyright (C) 2021 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 <qtest.h>
#include <QLibraryInfo>
#include <QDir>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QSignalSpy>
#include <private/qquickitem_p.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>

View File

@ -1,6 +1,8 @@
// 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 <QtTest/QtTest>
#include <QtCore/qstringlistmodel.h>
#include <QtQuick/qquickview.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QtTest/QtTest>
#include <QtQml/qqmlengine.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QtTest/QSignalSpy>
#include <QtQml/qqmlengine.h>

View File

@ -26,6 +26,8 @@ qt_internal_add_test(tst_qquicklistview
randomsortmodel.cpp randomsortmodel.h
reusemodel.h
tst_qquicklistview.cpp
NO_PCH_SOURCES
tst_qquicklistview.cpp # undef QT_NO_FOREACH
LIBRARIES
Qt::CorePrivate
Qt::Gui

View File

@ -1,6 +1,8 @@
// Copyright (C) 2020 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 <QtTest/QtTest>
#include <QtCore/QStringListModel>
#include <QtCore/QSortFilterProxyModel>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QSignalSpy>

View File

@ -1,6 +1,8 @@
// 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 <QtTest/QtTest>
#include <QtQuick/qquickview.h>
#include <QtQml/qqmlengine.h>

View File

@ -1,5 +1,8 @@
// 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 <QtTest/QtTest>
#include <QtQuick/qquickview.h>
#include <qqmlengine.h>

View File

@ -1,5 +1,8 @@
// 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 <qtest.h>
#include <QtTest/QSignalSpy>
#include <QtQuickTestUtils/private/qmlutils_p.h>

View File

@ -1,5 +1,8 @@
// Copyright (C) 2018 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 <QtQuickTestUtils/private/qmlutils_p.h>
#include <QtQuickTestUtils/private/visualtestutils_p.h>
#include <QtQuickTestUtils/private/viewtestutils_p.h>

View File

@ -1,6 +1,8 @@
// 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 <qtest.h>
#if QT_CONFIG(opengl)