From dba42c925db368aa958c38c6a3481f18a57bd71f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 4 Sep 2016 19:35:21 +0200 Subject: Eradicate Q_FOREACH loops and mark the module as Q_FOREACH-free In network-settings.h, replaced a few QList of static size with C arrays. Change-Id: Iac32e68f76e3c53fa03b6a2943e1dfb5adbe6fad Reviewed-by: Friedemann Kleint --- .qmake.conf | 1 + .../xmlpatterns/shared/xmlsyntaxhighlighter.cpp | 2 +- tests/auto/network-settings.h | 52 ++++++++++++---------- .../patternistexamples/tst_patternistexamples.cpp | 4 +- tests/auto/qabstractxmlnodemodel/LoadingModel.cpp | 2 +- tests/auto/qxmlquery/tst_qxmlquery.cpp | 4 +- tests/auto/xmlpatterns/tst_xmlpatterns.cpp | 5 +-- 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/.qmake.conf b/.qmake.conf index 556f554..ae17d7b 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,4 +1,5 @@ load(qt_build_config) CONFIG += warning_clean +DEFINES += QT_NO_FOREACH MODULE_VERSION = 5.8.0 diff --git a/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp index 85c8020..385fd11 100644 --- a/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp +++ b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp @@ -73,7 +73,7 @@ XmlSyntaxHighlighter::XmlSyntaxHighlighter(QTextDocument *parent) void XmlSyntaxHighlighter::highlightBlock(const QString &text) { - foreach (const HighlightingRule &rule, highlightingRules) { + for (const HighlightingRule &rule : qAsConst(highlightingRules)) { QRegExp expression(rule.pattern); int index = text.indexOf(expression); while (index >= 0) { diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index f02ed86..569069a 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -65,21 +65,22 @@ public: static bool compareReplyIMAP(QByteArray const& actual) { - QList expected; + const QByteArray expected[] = { - // Mandriva; old test server - expected << QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] " ) + // Mandriva; old test server + QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] " ) .append(QtNetworkSettings::serverName().toLatin1()) - .append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"); + .append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"), - // Ubuntu 10.04; new test server - expected << QByteArray( "* OK " ) + // Ubuntu 10.04; new test server + QByteArray( "* OK " ) .append(QtNetworkSettings::serverLocalName().toLatin1()) - .append(" Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n"); + .append(" Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n"), - // Feel free to add more as needed + // Feel free to add more as needed + }; - Q_FOREACH (QByteArray const& ba, expected) { + for (const QByteArray &ba : expected) { if (ba == actual) { return true; } @@ -90,21 +91,22 @@ public: static bool compareReplyIMAPSSL(QByteArray const& actual) { - QList expected; + const QByteArray expected[] = { - // Mandriva; old test server - expected << QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " ) + // Mandriva; old test server + QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " ) .append(QtNetworkSettings::serverName().toLatin1()) - .append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"); + .append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"), - // Ubuntu 10.04; new test server - expected << QByteArray( "* OK " ) + // Ubuntu 10.04; new test server + QByteArray( "* OK " ) .append(QtNetworkSettings::serverLocalName().toLatin1()) - .append(" Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n"); + .append(" Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n"), - // Feel free to add more as needed + // Feel free to add more as needed + }; - Q_FOREACH (QByteArray const& ba, expected) { + for (const QByteArray &ba : expected) { if (ba == actual) { return true; } @@ -115,14 +117,16 @@ public: static bool compareReplyFtp(QByteArray const& actual) { - QList expected; + const QByteArray expected[] = { - // A few different vsFTPd versions. - // Feel free to add more as needed - expected << QByteArray( "220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n" ); - expected << QByteArray( "220 (vsFTPd 2.2.2)\r\n221 Goodbye.\r\n" ); + // A few different vsFTPd versions. + // Feel free to add more as needed + QByteArray( "220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n" ), + QByteArray( "220 (vsFTPd 2.2.2)\r\n221 Goodbye.\r\n" ), - Q_FOREACH (QByteArray const& ba, expected) { + }; + + for (const QByteArray &ba : expected) { if (ba == actual) { return true; } diff --git a/tests/auto/patternistexamples/tst_patternistexamples.cpp b/tests/auto/patternistexamples/tst_patternistexamples.cpp index 3aed232..6abeb04 100644 --- a/tests/auto/patternistexamples/tst_patternistexamples.cpp +++ b/tests/auto/patternistexamples/tst_patternistexamples.cpp @@ -142,7 +142,7 @@ void tst_PatternistExamples::checkQueries_data() const QCOMPARE(queryExamples.count(), int(XQueryFileCount)); - foreach(QString q, queryExamples) + for (const QString &q : queryExamples) QTest::newRow(q.toLocal8Bit().constData()) << q; } @@ -183,7 +183,7 @@ void tst_PatternistExamples::checkXMLFiles_data() const QCOMPARE(xmlFiles.count(), int(XMLFileCount)); - foreach(QString q, xmlFiles) + for (const QString &q : xmlFiles) QTest::newRow(q.toLocal8Bit().constData()) << q; } diff --git a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp index 76608f4..07a702b 100644 --- a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp +++ b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp @@ -169,7 +169,7 @@ QXmlNodeModelIndex LoadingModel::nextFromSimpleAxis(QAbstractXmlNodeModel::Simpl QVector LoadingModel::attributes(const QXmlNodeModelIndex &ni) const { QVector retval; - foreach(const Node *n, toInternal(ni)->attributes) + for (const Node *n : toInternal(ni)->attributes) retval.append(createIndex(n)); return retval; diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index 1754d7d..a7f3e8b 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -977,8 +977,8 @@ void tst_QXmlQuery::evaluateToReceiver_data() const { QTest::addColumn("inputQuery"); - foreach (QString const& query, queries()) - { + const auto queries_ = queries(); + for (QString const& query : queries_) { /* This outputs a URI specific to the environment, so we can't use it for this * particular test. */ if (query != QLatin1String("staticBaseURI.xq")) diff --git a/tests/auto/xmlpatterns/tst_xmlpatterns.cpp b/tests/auto/xmlpatterns/tst_xmlpatterns.cpp index 1a08a66..294e5fc 100644 --- a/tests/auto/xmlpatterns/tst_xmlpatterns.cpp +++ b/tests/auto/xmlpatterns/tst_xmlpatterns.cpp @@ -1028,7 +1028,7 @@ void tst_XmlPatterns::xsltSupport_data() const */ QString tst_XmlPatterns::filterStderr(const QString &in) { - static QList irrelevant = QList() + static const QList irrelevant = QList() // specific filenames << QRegExp(QLatin1String("file:\\/\\/.*(\\.xq|\\.gccxml|\\.xml|\\.xsl|-)(,|:)")) @@ -1040,9 +1040,8 @@ QString tst_XmlPatterns::filterStderr(const QString &in) ; QString out = in; - foreach (const QRegExp& rx, irrelevant) { + for (const QRegExp& rx : irrelevant) out = out.remove(rx); - } return out; } -- cgit v1.2.1