diff --git a/samples/blackmisc/samplesperformance.cpp b/samples/blackmisc/samplesperformance.cpp index dbfedecef..28d43a23e 100644 --- a/samples/blackmisc/samplesperformance.cpp +++ b/samples/blackmisc/samplesperformance.cpp @@ -162,22 +162,22 @@ namespace BlackSample QString containsStr("aaa"); number = 0; timer.start(); - for (const auto &str : strList1) { if (newRegex.match(str).hasMatch()) number++; } + for (const auto &str : as_const(strList1)) { if (newRegex.match(str).hasMatch()) number++; } ms = timer.elapsed(); out << "new regex matched " << number << " of" << strList1.size() << " strings in " << ms << "ms" << endl; number = 0; timer.start(); - for (const auto &str : strList2) { if (fullRegex.exactMatch(str)) number++; } + for (const auto &str : as_const(strList2)) { if (fullRegex.exactMatch(str)) number++; } ms = timer.elapsed(); out << "full regex matched " << number << " of" << strList2.size() << " strings in " << ms << "ms" << endl; number = 0; timer.start(); - for (const auto &str : strList3) { if (wildcardRegex.exactMatch(str)) number++; } + for (const auto &str : as_const(strList3)) { if (wildcardRegex.exactMatch(str)) number++; } ms = timer.elapsed(); out << "wildcard matched " << number << " of " << strList3.size() << " strings in " << ms << "ms" << endl; number = 0; timer.start(); - for (const auto &str : strList4) { if (str.contains(containsStr)) number++; } + for (const auto &str : as_const(strList4)) { if (str.contains(containsStr)) number++; } ms = timer.elapsed(); out << "contains matched " << number << " of " << strList4.size() << " strings in " << ms << "ms" << endl; @@ -241,7 +241,7 @@ namespace BlackSample out << "Reads by times / callsigns: " << timer.elapsed() << "ms" << endl; timer.start(); - QHash splitList = situations.splitPerCallsign(); + const QHash splitList = situations.splitPerCallsign(); Q_ASSERT(splitList.size() == numberOfCallsigns); for (int t = 0; t < numberOfTimes; t++) { @@ -318,7 +318,7 @@ namespace BlackSample Q_UNUSED(b); timer.start(); - QHash csSituations = situations.splitPerCallsign(); + const QHash csSituations = situations.splitPerCallsign(); out << "Split by " << csSituations.size() << " callsigns, " << timer.elapsed() << "ms" << endl; timer.start(); @@ -422,7 +422,7 @@ namespace BlackSample upperRegex.optimize(); timer.start(); - for (const QString &s : strings) + for (const QString &s : as_const(strings)) { auto c = containsChar(s, [](QChar c) { return c.isUpper(); }); Q_UNUSED(c); @@ -430,7 +430,7 @@ namespace BlackSample out << "Check 100,000 strings for containing uppercase letter: (utility) " << timer.elapsed() << "ms" << endl; timer.start(); - for (const QString &s : strings) + for (const QString &s : as_const(strings)) { auto c = s.contains(upperRegex); Q_UNUSED(c); @@ -438,7 +438,7 @@ namespace BlackSample out << "Check 100,000 strings for containing uppercase letter: (regex) " << timer.elapsed() << "ms" << endl << endl; timer.start(); - for (const QString &s : strings) + for (const QString &s : as_const(strings)) { auto i = indexOfChar(s, [](QChar c) { return c.isUpper(); }); Q_UNUSED(i); @@ -446,7 +446,7 @@ namespace BlackSample out << "Check 100,000 strings for index of first uppercase letter: (utility) " << timer.elapsed() << "ms" << endl; timer.start(); - for (const QString &s : strings) + for (const QString &s : as_const(strings)) { auto i = s.indexOf(upperRegex); Q_UNUSED(i); diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index 3094ec220..fc90613da 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -102,13 +102,13 @@ namespace BlackSample CMetaMemberComparator cmp; QList> list = cmp(station1, station3); - for (const auto &member : list) { out << member.first << (member.second ? " equal" : " NOT equal") << endl; } + for (const auto &member : as_const(list)) { out << member.first << (member.second ? " equal" : " NOT equal") << endl; } out << endl; list = cmp(station1, station3, { "controller" }); - for (const auto &member : list) { out << member.first << (member.second ? " equal" : " NOT equal") << endl; } + for (const auto &member : as_const(list)) { out << member.first << (member.second ? " equal" : " NOT equal") << endl; } out << endl; list = cmp(station1, station3, { "controller", "homebase" }); - for (const auto &member : list) { out << member.first << (member.second ? " equal" : " NOT equal") << endl; } + for (const auto &member : as_const(list)) { out << member.first << (member.second ? " equal" : " NOT equal") << endl; } out << "-----------------------------------------------" << endl; return 0; diff --git a/samples/cliclient/client.cpp b/samples/cliclient/client.cpp index 7e5a9fa96..cec0a01dc 100644 --- a/samples/cliclient/client.cpp +++ b/samples/cliclient/client.cpp @@ -134,8 +134,8 @@ namespace BlackSample stream >> cmd; stream.skipWhiteSpace(); - auto found = m_commands.find(cmd); - if (found == m_commands.end()) + auto found = m_commands.constFind(cmd); + if (found == m_commands.constEnd()) { std::cout << "No such command" << std::endl; } diff --git a/src/blackcore/context/contextapplication.cpp b/src/blackcore/context/contextapplication.cpp index ad1ac45fe..42240fedc 100644 --- a/src/blackcore/context/contextapplication.cpp +++ b/src/blackcore/context/contextapplication.cpp @@ -163,6 +163,6 @@ const QDBusArgument &operator >>(const QDBusArgument &arg, BlackCore::Context::C { QList listOfPairs; arg >> listOfPairs; - for (const auto &pair : listOfPairs) { hash.insert(pair.first, pair.second); } + for (const auto &pair : as_const(listOfPairs)) { hash.insert(pair.first, pair.second); } return arg; } diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 2e16dba32..cb009f1c7 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -552,7 +552,7 @@ namespace BlackCore QSharedPointer CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) { QSharedPointer voiceChannel; - for (const auto &channel : m_voiceChannelMapping.values()) + for (const auto &channel : as_const(m_voiceChannelMapping)) { if (channel->getVoiceRoom().getVoiceRoomUrl() == voiceRoom.getVoiceRoomUrl()) voiceChannel = channel; } diff --git a/src/blackcore/inputmanager.cpp b/src/blackcore/inputmanager.cpp index 8666fb9c3..b98217743 100644 --- a/src/blackcore/inputmanager.cpp +++ b/src/blackcore/inputmanager.cpp @@ -16,6 +16,8 @@ #include #include +// clazy:excludeall=detaching-member + using namespace BlackInput; using namespace BlackMisc; using namespace BlackMisc::Input; @@ -107,7 +109,7 @@ namespace BlackCore if (action.isEmpty()) { return; } if (m_actionRelayingEnabled) emit remoteActionFromLocal(action, isKeyDown); - for (const auto &boundAction : m_boundActions) + for (const auto &boundAction : as_const(m_boundActions)) { if (boundAction.m_action == action) { diff --git a/src/blackcore/weathermanager.cpp b/src/blackcore/weathermanager.cpp index 3baaf986e..e2e3891a2 100644 --- a/src/blackcore/weathermanager.cpp +++ b/src/blackcore/weathermanager.cpp @@ -97,10 +97,10 @@ namespace BlackCore void CWeatherManager::fetchNextWeatherData() { - const WeatherRequest weatherRequest = m_pendingRequests.first(); + const WeatherRequest weatherRequest = m_pendingRequests.constFirst(); PhysicalQuantities::CLength maxDistance(100.0, CLengthUnit::km()); - for (IWeatherData *plugin : m_weatherDataPlugins) + for (IWeatherData *plugin : as_const(m_weatherDataPlugins)) { plugin->fetchWeatherData(weatherRequest.weatherGrid, maxDistance); } @@ -114,7 +114,7 @@ namespace BlackCore Q_ASSERT(weatherDataPlugin); auto fetchedWeatherGrid = weatherDataPlugin->getWeatherData(); - const WeatherRequest weatherRequest = m_pendingRequests.first(); + const WeatherRequest weatherRequest = m_pendingRequests.constFirst(); CWeatherGrid requestedWeatherGrid = weatherRequest.weatherGrid; // Interpolation. So far it just picks the closest point without interpolation. diff --git a/src/blackinput/win/joystickwindows.cpp b/src/blackinput/win/joystickwindows.cpp index 0b1e8168e..43804d8f9 100644 --- a/src/blackinput/win/joystickwindows.cpp +++ b/src/blackinput/win/joystickwindows.cpp @@ -105,7 +105,7 @@ namespace BlackInput // FIXME: Take the first device for the time being // For the future, the user should be able to choose which device // he wants to use. - CJoystickDeviceData deviceData = m_availableJoystickDevices.first(); + const CJoystickDeviceData &deviceData = m_availableJoystickDevices.constFirst(); // Create device if (FAILED(hr = m_directInput->CreateDevice(deviceData.guidDevice, &m_directInputDevice, nullptr))) diff --git a/src/blackmisc/connectionguard.cpp b/src/blackmisc/connectionguard.cpp index d7b2e4696..835a159fe 100644 --- a/src/blackmisc/connectionguard.cpp +++ b/src/blackmisc/connectionguard.cpp @@ -8,6 +8,7 @@ */ #include "blackmisc/connectionguard.h" +#include "blackmisc/range.h" namespace BlackMisc { @@ -35,7 +36,7 @@ namespace BlackMisc { if (this->m_connections.isEmpty()) { return 0; } int c = 0; - for (const QMetaObject::Connection &con : this->m_connections) + for (const QMetaObject::Connection &con : as_const(this->m_connections)) { if (QObject::disconnect(con)) { c++; } } diff --git a/src/blackmisc/datacache.cpp b/src/blackmisc/datacache.cpp index 06f9f43e9..99c10fc3b 100644 --- a/src/blackmisc/datacache.cpp +++ b/src/blackmisc/datacache.cpp @@ -226,7 +226,7 @@ namespace BlackMisc qSwap(m_queue, queue); lock.unlock(); - for (const auto &pair : queue) + for (const auto &pair : BlackMisc::as_const(queue)) { m_page->setValuesFromCache(pair.first, pair.second); } @@ -299,7 +299,7 @@ namespace BlackMisc auto msg = m_cache->loadFromFiles(persistentStore(), m_cache->m_revision.keysWithNewerTimestamps(), baseline.toVariantMap(), newValues, m_cache->m_revision.timestampsAsString()); newValues.setTimestamps(m_cache->m_revision.newerTimestamps()); - auto missingKeys = m_cache->m_revision.keysWithNewerTimestamps().subtract(newValues.keys()); + auto missingKeys = m_cache->m_revision.keysWithNewerTimestamps() - newValues.keys(); if (! missingKeys.isEmpty()) { m_cache->m_revision.writeNewRevision({}, missingKeys); } msg.setCategories(this); diff --git a/src/blackmisc/db/distribution.cpp b/src/blackmisc/db/distribution.cpp index 2396dce11..cb8626815 100644 --- a/src/blackmisc/db/distribution.cpp +++ b/src/blackmisc/db/distribution.cpp @@ -64,7 +64,7 @@ namespace BlackMisc { // further reduce by VATSIM flag QStringList furtherReduced; - for (const QString &p : reduced) + for (const QString &p : as_const(reduced)) { if (CBuildConfig::isVatsimVersion()) { @@ -203,7 +203,7 @@ namespace BlackMisc const QJsonObject platforms = json.value("platforms").toObject(); const QStringList platformsKeys = platforms.keys(); if (platformsKeys.isEmpty()) { return CDistribution(); } // no platforms, then the whole distribution is useless - for (const QString platformKey : platformsKeys) + for (const QString platformKey : as_const(platformsKeys)) { QStringList platformFileNames; QJsonArray platformFiles = platforms.value(platformKey).toArray(); diff --git a/src/blackmisc/dbusserver.cpp b/src/blackmisc/dbusserver.cpp index 3804f5f8f..bab5fb763 100644 --- a/src/blackmisc/dbusserver.cpp +++ b/src/blackmisc/dbusserver.cpp @@ -183,7 +183,7 @@ namespace BlackMisc m_connections.insert(connection.name(), connection); CLogMessage(this).debug() << "New Connection from:" << connection.name(); bool success = true; - for (auto i = m_objects.begin(); i != m_objects.end(); ++i) + for (auto i = m_objects.cbegin(); i != m_objects.cend(); ++i) { CLogMessage(this).debug() << "Adding" << i.key() << getDBusInterfaceFromClassInfo(i.value()) << "to the new connection."; bool ok = connection.registerObject(i.key(), i.value(), registerOptions()); @@ -228,7 +228,7 @@ namespace BlackMisc break; case SERVERMODE_P2P: { - for (QDBusConnection connection : m_connections) + for (QDBusConnection connection : as_const(m_connections)) { if (connection.registerObject(path, object, registerOptions())) { @@ -277,7 +277,7 @@ namespace BlackMisc break; case SERVERMODE_P2P: { - for (QDBusConnection connection : m_connections) + for (QDBusConnection connection : as_const(m_connections)) { connection.unregisterObject(path); } diff --git a/src/blackmisc/directoryutils.cpp b/src/blackmisc/directoryutils.cpp index d02983a60..bd383b54c 100644 --- a/src/blackmisc/directoryutils.cpp +++ b/src/blackmisc/directoryutils.cpp @@ -11,6 +11,7 @@ #include "blackmisc/directoryutils.h" #include "blackmisc/fileutils.h" +#include "blackmisc/range.h" #include #include #include @@ -176,8 +177,8 @@ namespace BlackMisc comp.sameNameInTarget = CDirectoryUtils::filesToCanonicalNames(sameNames, sTargetCanonicalFiles); Q_ASSERT_X(comp.sameNameInSource.size() == comp.sameNameInTarget.size(), Q_FUNC_INFO, "Same sets require same size"); - QSet::const_iterator targetIt = comp.sameNameInTarget.begin(); - for (const QString &sourceFile : comp.sameNameInSource) + QSet::const_iterator targetIt = comp.sameNameInTarget.cbegin(); + for (const QString &sourceFile : as_const(comp.sameNameInSource)) { const QFileInfo source(sourceFile); const QFileInfo target(*targetIt++); diff --git a/src/blackmisc/loghandler.cpp b/src/blackmisc/loghandler.cpp index 7b8e8eb2a..028588144 100644 --- a/src/blackmisc/loghandler.cpp +++ b/src/blackmisc/loghandler.cpp @@ -130,7 +130,7 @@ namespace BlackMisc void CLogHandler::logMessage(const CStatusMessage &statusMessage) { - auto handlers = handlersForMessage(statusMessage); + const auto handlers = handlersForMessage(statusMessage); if (isFallThroughEnabled(handlers)) { diff --git a/src/blackmisc/range.h b/src/blackmisc/range.h index 2d43d3881..e3716ea39 100644 --- a/src/blackmisc/range.h +++ b/src/blackmisc/range.h @@ -289,24 +289,54 @@ namespace BlackMisc /*! * Returns a CRange constructed from the begin and end iterators of the given container. - * - * The returned CRange may or may not be const, depending on the constness of the container. */ + //! @{ template - auto makeRange(T &&container) -> CRange + auto makeRange(T &container) -> CRange { return { container.begin(), container.end() }; } + template + auto makeRange(const T &container) -> CRange + { + return { container.begin(), container.end() }; + } + //! @} /*! * Returns a const CRange constructed from the cbegin and cend iterators of the given container. */ template - auto makeConstRange(T &&container) -> CRange + auto makeConstRange(const T &container) -> CRange { return { container.cbegin(), container.cend() }; } + /*! + * Returns a const CRange for iterating over the keys of an associative container. + * + * This is more efficient than the keys() method of the container, as it doesn't allocate memory. + */ + template + auto makeKeysRange(const T &container) + { + return makeRange(Iterators::makeKeyIterator(container.cbegin()), container.cend()); + } + + /*! + * Keys range for a non-const lvalue would be unsafe due to iterator invalidation on detach(). + * + * \see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem + */ + template + void makeKeysRange(T &container) = delete; + + /*! + * Keys range for a temporary would be unsafe. + */ + template + void makeKeysRange(const T &&container) = delete; + /* * Member functions of CRangeBase template defined out of line, because they depend on CRange etc. */ diff --git a/src/blackmisc/simplecommandparser.cpp b/src/blackmisc/simplecommandparser.cpp index 4961fbe72..b9d61eb80 100644 --- a/src/blackmisc/simplecommandparser.cpp +++ b/src/blackmisc/simplecommandparser.cpp @@ -38,11 +38,11 @@ namespace BlackMisc this->m_splitParts = m_cleanedLine.split(' '); if (!this->m_splitParts.isEmpty()) { - const QString first = this->m_splitParts.first(); + const QString &first = this->m_splitParts.constFirst(); const QString formatted = formatCommand(first); if (isCommand(first)) { - this->m_commandPart = formatCommand(first); + this->m_commandPart = formatted; this->m_knownCommand = this->m_knownCommands.contains(formatted); } } diff --git a/src/blackmisc/simulation/fscommon/vpilotmodelruleset.cpp b/src/blackmisc/simulation/fscommon/vpilotmodelruleset.cpp index 13c3a7a42..9c0277cd5 100644 --- a/src/blackmisc/simulation/fscommon/vpilotmodelruleset.cpp +++ b/src/blackmisc/simulation/fscommon/vpilotmodelruleset.cpp @@ -90,7 +90,7 @@ namespace BlackMisc QStringList remove(toUpper(modelsToBeRemoved)); remove.sort(); - QSet removeSet(knownModels.toSet().intersect(remove.toSet())); + QSet removeSet(knownModels.toSet() & remove.toSet()); int c = 0; for (const QString &model : removeSet) { diff --git a/src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp b/src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp index 2f4cc1707..a8cf9de89 100644 --- a/src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp +++ b/src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp @@ -132,10 +132,11 @@ namespace BlackMisc const QString &CVPilotRulesReader::standardMappingsDirectory() { + //! \fixme not threadsafe static QString directory; if (directory.isEmpty()) { - directory = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first(); + directory = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).constFirst(); if (!directory.endsWith('/')) { directory.append('/'); } directory.append("vPilot Files/Model Matching Rule Sets"); } diff --git a/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp b/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp index 3d63e347e..17c539636 100644 --- a/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp +++ b/src/blackmisc/simulation/xplane/aircraftmodelloaderxplane.cpp @@ -262,7 +262,7 @@ namespace BlackMisc file.close(); parseFullPackage(content, package); - for (const auto &plane : package.planes) + for (const auto &plane : as_const(package.planes)) { if (installedModels.containsModelString(plane.getModelName())) { @@ -295,7 +295,7 @@ namespace BlackMisc bool CAircraftModelLoaderXPlane::doPackageSub(QString &ioPath) { - for (auto i = m_cslPackages.begin(); i != m_cslPackages.end(); ++i) + for (auto i = m_cslPackages.cbegin(); i != m_cslPackages.cend(); ++i) { if (strncmp(qPrintable(i->name), qPrintable(ioPath), i->name.size()) == 0) { @@ -315,8 +315,8 @@ namespace BlackMisc return false; } - auto p = std::find_if(m_cslPackages.begin(), m_cslPackages.end(), [&tokens](CSLPackage p) { return p.name == tokens[1]; }); - if (p == m_cslPackages.end()) + auto p = std::find_if(m_cslPackages.cbegin(), m_cslPackages.cend(), [&tokens](const CSLPackage &p) { return p.name == tokens[1]; }); + if (p == m_cslPackages.cend()) { package.path = path; package.name = tokens[1]; @@ -338,7 +338,7 @@ namespace BlackMisc return false; } - if (std::count_if(m_cslPackages.begin(), m_cslPackages.end(), [&tokens](CSLPackage p) { return p.name == tokens[1]; }) == 0) + if (std::count_if(m_cslPackages.cbegin(), m_cslPackages.cend(), [&tokens](const CSLPackage &p) { return p.name == tokens[1]; }) == 0) { CLogMessage(this).warning("WARNING: required package %1 not found. Aborting processing of this package.") << tokens[1]; return false; diff --git a/src/blackmisc/valuecache.cpp b/src/blackmisc/valuecache.cpp index 281743fa5..acc49e855 100644 --- a/src/blackmisc/valuecache.cpp +++ b/src/blackmisc/valuecache.cpp @@ -182,14 +182,14 @@ namespace BlackMisc CValueCache::Element &CValueCache::getElement(const QString &key) { QMutexLocker lock(&m_mutex); - return getElement(key, m_elements.lowerBound(key)); + return getElement(key, as_const(m_elements).lowerBound(key)); } CValueCache::Element &CValueCache::getElement(const QString &key, QMap::const_iterator pos) { QMutexLocker lock(&m_mutex); - if (pos != m_elements.end() && pos.key() == key) { return **pos; } - Q_ASSERT(pos == m_elements.lowerBound(key)); + if (pos != m_elements.cend() && pos.key() == key) { return **pos; } + Q_ASSERT(pos == as_const(m_elements).lowerBound(key)); return **m_elements.insert(pos, key, ElementPtr(new Element(key))); } @@ -259,8 +259,9 @@ namespace BlackMisc { QMutexLocker lock(&m_mutex); if (values.empty()) { return; } - auto out = m_elements.lowerBound(values.cbegin().key()); - auto end = m_elements.upperBound((values.cend() - 1).key()); + m_elements.detach(); //! \fixme see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem + auto out = as_const(m_elements).lowerBound(values.cbegin().key()); + auto end = as_const(m_elements).upperBound((values.cend() - 1).key()); for (auto in = values.cbegin(); in != values.cend(); ++in) { while (out != end && out.key() < in.key()) { ++out; } @@ -295,8 +296,9 @@ namespace BlackMisc } CValueCachePacket ratifiedChanges(values.isSaved()); CValueCachePacket ackedChanges(values.isSaved()); - auto out = m_elements.lowerBound(values.cbegin().key()); - auto end = m_elements.upperBound((values.cend() - 1).key()); + m_elements.detach(); //! \fixme see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem + auto out = as_const(m_elements).lowerBound(values.cbegin().key()); + auto end = as_const(m_elements).upperBound((values.cend() - 1).key()); for (auto in = values.cbegin(); in != values.cend(); ++in) { while (out != end && out.key() < in.key()) { ++out; } diff --git a/src/blacksound/soundgenerator.cpp b/src/blacksound/soundgenerator.cpp index 04a266f46..e2a668418 100644 --- a/src/blacksound/soundgenerator.cpp +++ b/src/blacksound/soundgenerator.cpp @@ -134,10 +134,11 @@ namespace BlackSound while (chunks) { // periodSize-> Returns the period size in bytes. + //! \todo looks wrong: read() will memcpy from m_buffer.constData() to m_buffer.data() const qint64 len = this->read(m_buffer.data(), this->m_audioOutput->periodSize()); if (len >= 0) { - this->m_pushModeIODevice->write(m_buffer.data(), len); + this->m_pushModeIODevice->write(m_buffer.constData(), len); } if (len != this->m_audioOutput->periodSize()) { @@ -176,7 +177,7 @@ namespace BlackSound Q_UNUSED(bytesForAllChannels) // suppress warning in release builds m_buffer.resize(totalLength); - unsigned char *bufferPointer = reinterpret_cast(m_buffer.data()); + unsigned char *bufferPointer = reinterpret_cast(m_buffer.data()); // clazy:exclude=detaching-member foreach(Tone t, this->m_tones) { diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp index 14ef67ef3..e9e296c99 100644 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp +++ b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp @@ -257,7 +257,7 @@ namespace BlackWxPlugin } CLogMessage(this).debug() << "Parsed" << messageNo << "GRIB messages."; - for (const GfsGridPoint &gfsGridPoint : m_gfsWeatherGrid) + for (const GfsGridPoint &gfsGridPoint : as_const(m_gfsWeatherGrid)) { if(QThread::currentThread()->isInterruptionRequested()) { return; } diff --git a/src/xbus/traffic.cpp b/src/xbus/traffic.cpp index 58c2401d9..44a732f27 100644 --- a/src/xbus/traffic.cpp +++ b/src/xbus/traffic.cpp @@ -25,6 +25,8 @@ #include #include +// clazy:excludeall=reserve-candidates + namespace XBus { @@ -246,7 +248,7 @@ namespace XBus void CTraffic::removeAllPlanes() { - for (auto plane : m_planesByCallsign) + for (auto plane : BlackMisc::as_const(m_planesByCallsign)) { XPMPDestroyPlane(plane->id); delete plane; @@ -334,7 +336,10 @@ namespace XBus } else if (callsign.isEmpty()) { - for (const auto &callsign : m_planesByCallsign.keys()) { setInterpolatorMode(callsign, spline); } + for (const auto &callsign : BlackMisc::makeKeysRange(BlackMisc::as_const(m_planesByCallsign))) + { + setInterpolatorMode(callsign, spline); + } } } @@ -379,10 +384,10 @@ namespace XBus if (plane->hasSurfaces) { const auto currentTime = QDateTime::currentMSecsSinceEpoch(); - while (! plane->pendingSurfaces.isEmpty() && plane->pendingSurfaces.front().first <= currentTime) + while (! plane->pendingSurfaces.isEmpty() && plane->pendingSurfaces.constFirst().first <= currentTime) { //! \todo if gear is currently retracted, look ahead and pull gear position from pendingSurfaces up to 5 seconds in the future - plane->pendingSurfaces.front().second(plane); + plane->pendingSurfaces.constFirst().second(plane); plane->pendingSurfaces.pop_front(); } if (plane->surfaces.gearPosition != plane->targetGearPosition) diff --git a/tests/blackcore/expect.cpp b/tests/blackcore/expect.cpp index 6fa159db1..06f726254 100644 --- a/tests/blackcore/expect.cpp +++ b/tests/blackcore/expect.cpp @@ -15,6 +15,7 @@ */ #include "expect.h" +#include "blackmisc/range.h" #include #include @@ -81,7 +82,8 @@ void Expect::wait(const SourceLocation& srcloc, int timeout) { i->onDone([&](const ExpectUnit* u){ unitsCopy.remove(u); }); } - for (auto i : unitsCopy.toList()) // toList is an easy way to make a temporary copy, needed because init might invalidate iterators + // toList is an easy way to make a temporary copy, needed because init might invalidate iterators + for (auto i : unitsCopy.toList()) // clazy:exclude=container-anti-pattern,range-loop { i->init(); } @@ -90,7 +92,7 @@ void Expect::wait(const SourceLocation& srcloc, int timeout) timer.setSingleShot(true); QObject::connect(&timer, &QTimer::timeout, [=, &unitsCopy]{ reportTimeout(srcloc, unitsCopy); - for (auto i : unitsCopy) + for (auto i : BlackMisc::as_const(unitsCopy)) { i->onDone(nullptr); //paranoia } diff --git a/tests/blackcore/expect.h b/tests/blackcore/expect.h index 3c4583b24..a9f52c10d 100644 --- a/tests/blackcore/expect.h +++ b/tests/blackcore/expect.h @@ -61,7 +61,7 @@ namespace BlackCoreTest ConnectGuard &operator+= (const QMetaObject::Connection &conn) { m_conns += conn; return *this; } //! Disconnect and remove all stored connections. - void cleanup() { for (auto i = m_conns.begin(); i != m_conns.end(); ++i) QObject::disconnect(*i); m_conns.clear(); } + void cleanup() { for (auto i = m_conns.cbegin(); i != m_conns.cend(); ++i) QObject::disconnect(*i); m_conns.clear(); } //! Copying is only allowed when there are no connections stored. //! @{