From: Kevin Ottens Date: Thu, 13 Aug 2020 10:23:02 +0000 (+0200) Subject: Enable the modernize-loop-convert check on clang-tidy X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~22^2~230^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=866ffc2a6b0b73c62504902574d13c35eb7f0f9c;p=nextcloud-desktop.git Enable the modernize-loop-convert check on clang-tidy Signed-off-by: Kevin Ottens --- diff --git a/.clang-tidy b/.clang-tidy index 59e5956ea..b255f3def 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,6 +4,7 @@ Checks: '-*, modernize-concat-nested-namespaces, modernize-deprecated-headers, modernize-deprecated-ios-base-aliases, + modernize-loop-convert, modernize-make-*, modernize-raw-string-literal, modernize-redundant-void-arg, diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index f146fffc7..af0a3b998 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -730,8 +730,8 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list) endInsertRows(); } - for (auto it = undecidedIndexes.begin(); it != undecidedIndexes.end(); ++it) { - suggestExpand(index(*it, 0, idx)); + for (int undecidedIndex : qAsConst(undecidedIndexes)) { + suggestExpand(index(undecidedIndex, 0, idx)); } /* We need lambda function for the following code. diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index 386c7f762..9d2c3469c 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -605,8 +605,8 @@ Q_INVOKABLE QString UserModel::currentUserServer() void UserModel::addUser(AccountStatePtr &user, const bool &isCurrent) { bool containsUser = false; - for (int i = 0; i < _users.size(); i++) { - if (_users[i]->account() == user->account()) { + for (const auto &u : qAsConst(_users)) { + if (u->account() == user->account()) { containsUser = true; continue; } diff --git a/src/libsync/cookiejar.cpp b/src/libsync/cookiejar.cpp index 5e28c1b62..ded4eaeed 100644 --- a/src/libsync/cookiejar.cpp +++ b/src/libsync/cookiejar.cpp @@ -34,8 +34,8 @@ QDataStream &operator<<(QDataStream &stream, const QList &list) { stream << JAR_VERSION; stream << quint32(list.size()); - for (int i = 0; i < list.size(); ++i) - stream << list.at(i).toRawForm(); + for (const auto &cookie : list) + stream << cookie.toRawForm(); return stream; } diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index 7a1274bd7..88f32f6e8 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -796,16 +796,16 @@ bool PropagatorCompositeJob::scheduleSelfOrChild() } // Ask all the running composite jobs if they have something new to schedule. - for (int i = 0; i < _runningJobs.size(); ++i) { - ASSERT(_runningJobs.at(i)->_state == Running); + for (auto runningJob : qAsConst(_runningJobs)) { + ASSERT(runningJob->_state == Running); - if (possiblyRunNextJob(_runningJobs.at(i))) { + if (possiblyRunNextJob(runningJob)) { return true; } // If any of the running sub jobs is not parallel, we have to cancel the scheduling // of the rest of the list and wait for the blocking job to finish and schedule the next one. - auto paral = _runningJobs.at(i)->parallelism(); + auto paral = runningJob->parallelism(); if (paral == WaitForFinished) { return false; } diff --git a/src/libsync/propagateremotemove.cpp b/src/libsync/propagateremotemove.cpp index 0e106d851..39fb1a032 100644 --- a/src/libsync/propagateremotemove.cpp +++ b/src/libsync/propagateremotemove.cpp @@ -193,9 +193,9 @@ bool PropagateRemoteMove::adjustSelectiveSync(SyncJournalDb *journal, const QStr QString from = from_ + QLatin1String("/"); QString to = to_ + QLatin1String("/"); - for (auto it = list.begin(); it != list.end(); ++it) { - if (it->startsWith(from)) { - *it = it->replace(0, from.size(), to); + for (auto &s : list) { + if (s.startsWith(from)) { + s = s.replace(0, from.size(), to); changed = true; } } diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index 78ce82089..862ad7d74 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -157,8 +157,8 @@ void PropagateUploadFileNG::slotPropfindFinished() // Make sure that if there is a "hole" and then a few more chunks, on the server // we should remove the later chunks. Otherwise when we do dynamic chunk sizing, we may end up // with corruptions if there are too many chunks, or if we abort and there are still stale chunks. - for (auto it = _serverChunks.begin(); it != _serverChunks.end(); ++it) { - auto job = new DeleteJob(propagator()->account(), Utility::concatUrlPath(chunkUrl(), it->originalName), this); + for (const auto &serverChunk : qAsConst(_serverChunks)) { + auto job = new DeleteJob(propagator()->account(), Utility::concatUrlPath(chunkUrl(), serverChunk.originalName), this); QObject::connect(job, &DeleteJob::finishedSignal, this, &PropagateUploadFileNG::slotDeleteJobFinished); _jobs.append(job); job->start(); diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 7c79272b8..152d66b29 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -1086,9 +1086,8 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult) _syncItemMap.clear(); // free memory // Adjust the paths for the renames. - for (SyncFileItemVector::iterator it = syncItems.begin(); - it != syncItems.end(); ++it) { - (*it)->_file = adjustRenamedPath((*it)->_file); + for (const auto &syncItem : qAsConst(syncItems)) { + syncItem->_file = adjustRenamedPath(syncItem->_file); } // Check for invalid character in old server version @@ -1104,12 +1103,12 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult) } if (!invalidFilenamePattern.isEmpty()) { const QRegExp invalidFilenameRx(invalidFilenamePattern); - for (auto it = syncItems.begin(); it != syncItems.end(); ++it) { - if ((*it)->_direction == SyncFileItem::Up - && isFileModifyingInstruction((*it)->_instruction) - && (*it)->destination().contains(invalidFilenameRx)) { - (*it)->_errorString = tr("File name contains at least one invalid character"); - (*it)->_instruction = CSYNC_INSTRUCTION_IGNORE; + for (const auto &syncItem : qAsConst(syncItems)) { + if (syncItem->_direction == SyncFileItem::Up + && isFileModifyingInstruction(syncItem->_instruction) + && syncItem->destination().contains(invalidFilenameRx)) { + syncItem->_errorString = tr("File name contains at least one invalid character"); + syncItem->_instruction = CSYNC_INSTRUCTION_IGNORE; } } } @@ -1677,19 +1676,19 @@ void SyncEngine::restoreOldFiles(SyncFileItemVector &syncItems) upload the client file. But we still downloaded the old file in a conflict file just in case */ - for (auto it = syncItems.begin(); it != syncItems.end(); ++it) { - if ((*it)->_direction != SyncFileItem::Down) + for (const auto &syncItem : qAsConst(syncItems)) { + if (syncItem->_direction != SyncFileItem::Down) continue; - switch ((*it)->_instruction) { + switch (syncItem->_instruction) { case CSYNC_INSTRUCTION_SYNC: - qCWarning(lcEngine) << "restoreOldFiles: RESTORING" << (*it)->_file; - (*it)->_instruction = CSYNC_INSTRUCTION_CONFLICT; + qCWarning(lcEngine) << "restoreOldFiles: RESTORING" << syncItem->_file; + syncItem->_instruction = CSYNC_INSTRUCTION_CONFLICT; break; case CSYNC_INSTRUCTION_REMOVE: - qCWarning(lcEngine) << "restoreOldFiles: RESTORING" << (*it)->_file; - (*it)->_instruction = CSYNC_INSTRUCTION_NEW; - (*it)->_direction = SyncFileItem::Up; + qCWarning(lcEngine) << "restoreOldFiles: RESTORING" << syncItem->_file; + syncItem->_instruction = CSYNC_INSTRUCTION_NEW; + syncItem->_direction = SyncFileItem::Up; break; case CSYNC_INSTRUCTION_RENAME: case CSYNC_INSTRUCTION_NEW: diff --git a/src/libsync/syncfilestatustracker.cpp b/src/libsync/syncfilestatustracker.cpp index 03233e1de..1c69da171 100644 --- a/src/libsync/syncfilestatustracker.cpp +++ b/src/libsync/syncfilestatustracker.cpp @@ -244,16 +244,16 @@ void SyncFileStatusTracker::slotAboutToPropagate(SyncFileItemVector &items) // Swap into a copy since fileStatus() reads _dirtyPaths to determine the status QSet oldDirtyPaths; std::swap(_dirtyPaths, oldDirtyPaths); - for (auto it = oldDirtyPaths.constBegin(); it != oldDirtyPaths.constEnd(); ++it) - emit fileStatusChanged(getSystemDestination(*it), fileStatus(*it)); + for (const auto &oldDirtyPath : qAsConst(oldDirtyPaths)) + emit fileStatusChanged(getSystemDestination(oldDirtyPath), fileStatus(oldDirtyPath)); // Make sure to push any status that might have been resolved indirectly since the last sync // (like an error file being deleted from disk) - for (auto it = _syncProblems.begin(); it != _syncProblems.end(); ++it) - oldProblems.erase(it->first); - for (auto it = oldProblems.begin(); it != oldProblems.end(); ++it) { - const QString &path = it->first; - SyncFileStatus::SyncFileStatusTag severity = it->second; + for (const auto &syncProblem : _syncProblems) + oldProblems.erase(syncProblem.first); + for (const auto &oldProblem : oldProblems) { + const QString &path = oldProblem.first; + SyncFileStatus::SyncFileStatusTag severity = oldProblem.second; if (severity == SyncFileStatus::StatusError) invalidateParentPaths(path); emit fileStatusChanged(getSystemDestination(path), fileStatus(path)); diff --git a/src/libsync/wordlist.cpp b/src/libsync/wordlist.cpp index 69134ac3e..01b7b5328 100644 --- a/src/libsync/wordlist.cpp +++ b/src/libsync/wordlist.cpp @@ -13,9 +13,9 @@ int getRandomNumber(int max) { unsigned int num = 0; - for (int i = 0; i < 8; i++) { + for (unsigned char c : d) { num = num << 8; - num += d[i]; + num += c; } return num % max; diff --git a/test/testallfilesdeleted.cpp b/test/testallfilesdeleted.cpp index 513fdb65d..026aa7a60 100644 --- a/test/testallfilesdeleted.cpp +++ b/test/testallfilesdeleted.cpp @@ -18,8 +18,8 @@ static void changeAllFileId(FileInfo &info) { if (!info.isDir) return; info.etag = generateEtag(); - for (auto it = info.children.begin(); it != info.children.end(); ++it) { - changeAllFileId(*it); + for (auto &child : info.children) { + changeAllFileId(child); } }