Pārlūkot izejas kodu

Enable clang-tidy modernize-loop-convert lint

Fix remaining diagnostics by this lint and remove it from our list of
disabled lints.
Brad King 8 gadi atpakaļ
vecāks
revīzija
706b37b7f5

+ 0 - 1
.clang-tidy

@@ -8,7 +8,6 @@ misc-*,\
 -misc-static-assert,\
 modernize-*,\
 -modernize-deprecated-headers,\
--modernize-loop-convert,\
 -modernize-pass-by-value,\
 -modernize-raw-string-literal,\
 -modernize-replace-auto-ptr,\

+ 2 - 3
Source/CursesDialog/cmCursesCacheEntryComposite.cxx

@@ -72,9 +72,8 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
         this->Entry = ow;
         std::vector<std::string> options;
         cmSystemTools::ExpandListArgument(stringsProp, options);
-        for (std::vector<std::string>::iterator si = options.begin();
-             si != options.end(); ++si) {
-          ow->AddOption(*si);
+        for (auto const& opt : options) {
+          ow->AddOption(opt);
         }
         ow->SetOption(value);
       } else {

+ 2 - 3
Source/CursesDialog/cmCursesOptionsWidget.cxx

@@ -75,9 +75,8 @@ void cmCursesOptionsWidget::SetOption(const std::string& value)
   this->CurrentOption = 0; // default to 0 index
   this->SetValue(value);
   int index = 0;
-  for (std::vector<std::string>::iterator i = this->Options.begin();
-       i != this->Options.end(); ++i) {
-    if (*i == value) {
+  for (auto const& opt : this->Options) {
+    if (opt == value) {
       this->CurrentOption = index;
     }
     index++;

+ 1 - 3
Source/CursesDialog/cmCursesStringWidget.cxx

@@ -188,9 +188,7 @@ bool cmCursesStringWidget::PrintKeys()
     char fmt_s[] = "%s";
     char firstLine[512];
     // Clean the toolbar
-    for (int i = 0; i < 512; i++) {
-      firstLine[i] = ' ';
-    }
+    memset(firstLine, ' ', sizeof(firstLine));
     firstLine[511] = '\0';
     curses_move(y - 4, 0);
     printw(fmt_s, firstLine);

+ 2 - 5
Source/cmcmd.cxx

@@ -282,8 +282,7 @@ int cmcmd::HandleCppCheck(const std::string& runCmd,
   std::vector<std::string> cppcheck_cmd;
   cmSystemTools::ExpandListArgument(runCmd, cppcheck_cmd, true);
   // extract all the -D, -U, and -I options from the compile line
-  for (size_t i = 0; i < orig_cmd.size(); i++) {
-    const std::string& opt = orig_cmd[i];
+  for (auto const& opt : orig_cmd) {
     if (opt.size() > 2) {
       if ((opt[0] == '-') &&
           ((opt[1] == 'D') || (opt[1] == 'I') || (opt[1] == 'U'))) {
@@ -367,9 +366,7 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string>& args)
     } else if (doing_options) {
       bool optionFound = false;
       // check arg against all the commandOptions
-      for (std::vector<std::string>::size_type i = 0;
-           i < commandOptions.size(); ++i) {
-        const std::string& command = commandOptions[i];
+      for (auto const& command : commandOptions) {
         if (arg.compare(0, command.size(), command) == 0) {
           optionFound = true;
           runCmd = arg.substr(command.size());

+ 3 - 6
Tests/CMakeLib/run_compile_commands.cxx

@@ -144,14 +144,11 @@ int main()
   cmsys::ifstream file("compile_commands.json");
   CompileCommandParser parser(file);
   parser.Parse();
-  for (CompileCommandParser::TranslationUnitsType::const_iterator
-         it = parser.GetTranslationUnits().begin(),
-         end = parser.GetTranslationUnits().end();
-       it != end; ++it) {
+  for (auto const& tu : parser.GetTranslationUnits()) {
     std::vector<std::string> command;
-    cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), command);
+    cmSystemTools::ParseUnixCommandLine(tu.at("command").c_str(), command);
     if (!cmSystemTools::RunSingleCommand(command, nullptr, nullptr, nullptr,
-                                         it->at("directory").c_str())) {
+                                         tu.at("directory").c_str())) {
       std::cout << "ERROR: Failed to run command \"" << command[0] << "\""
                 << std::endl;
       exit(1);