Browse Source

Merge topic 'clang-tidy'

77f674be Fix some occurrences of readability-braces-around-statements
f0bab294 Convert some leftover loops to C++11 range-based loop
b5d7f5b0 Fix occurrences of readability-non-const-parameter
9a2da339 Fix some occurrences of readability-avoid-const-params-in-decls
870dd06d Fix left-over occurrences of else-after-return
2033abff Fix minor clang-tidy findings
79b8c380 Improve several occurrences of vector::push_back in loops
a45928cd Fix some occurrences of missing override keywords
...

Acked-by: Kitware Robot <[email protected]>
Merge-request: !1292
Brad King 8 years ago
parent
commit
e24e0ff6fa

+ 2 - 0
.clang-tidy

@@ -10,11 +10,13 @@ modernize-*,\
 -modernize-deprecated-headers,\
 -modernize-pass-by-value,\
 -modernize-raw-string-literal,\
+-modernize-return-braced-init-list,\
 -modernize-use-auto,\
 -modernize-use-default-member-init,\
 -modernize-use-emplace,\
 -modernize-use-equals-default,\
 -modernize-use-equals-delete,\
+-modernize-use-noexcept,\
 -modernize-use-transparent-functors,\
 -modernize-use-using,\
 performance-*,\

+ 6 - 0
CMakeLists.txt

@@ -250,6 +250,12 @@ if(CMake_RUN_CLANG_TIDY)
     message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
   endif()
   set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
+
+  # provide definitions for targets that require a rebuild once .clang-tidy changes
+  file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
+  set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
+  unset(clang_tidy_sha1)
+
 endif()
 configure_file(.clang-tidy .clang-tidy COPYONLY)
 

+ 2 - 0
Source/CMakeLists.txt

@@ -779,6 +779,8 @@ if(WIN32 AND NOT UNIX)
   target_link_libraries(CMakeLib rpcrt4 crypt32)
 endif()
 
+target_compile_definitions(CMakeLib PUBLIC ${CLANG_TIDY_DEFINITIONS})
+
 #
 # CTestLib
 #

+ 3 - 4
Source/CPack/cmCPackBundleGenerator.cxx

@@ -213,8 +213,7 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir)
     cmSystemTools::ExpandListArgument(sign_files, relFiles);
 
     // sign the files supplied by the user, ie. frameworks.
-    for (std::vector<std::string>::iterator it = relFiles.begin();
-         it != relFiles.end(); ++it) {
+    for (auto const& file : relFiles) {
       std::ostringstream temp_sign_file_cmd;
       temp_sign_file_cmd << this->GetOption("CPACK_COMMAND_CODESIGN");
       temp_sign_file_cmd << " " << sign_parameter << " -s \""
@@ -223,11 +222,11 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir)
       temp_sign_file_cmd << this->GetOption("CPACK_APPLE_BUNDLE_ID");
       temp_sign_file_cmd << " \"";
       temp_sign_file_cmd << bundle_path;
-      temp_sign_file_cmd << *it << "\"";
+      temp_sign_file_cmd << file << "\"";
 
       if (!this->RunCommand(temp_sign_file_cmd, &output)) {
         cmCPackLogger(cmCPackLog::LOG_ERROR,
-                      "Error signing file:" << bundle_path << *it << std::endl
+                      "Error signing file:" << bundle_path << file << std::endl
                                             << output << std::endl);
 
         return 0;

+ 22 - 20
Source/CPack/cmCPackDragNDropGenerator.cxx

@@ -136,17 +136,17 @@ int cmCPackDragNDropGenerator::InitializeInternal()
                     "CPACK_DMG_SLA_LANGUAGES set but empty" << std::endl);
       return 0;
     }
-    for (size_t i = 0; i < languages.size(); ++i) {
-      std::string license = slaDirectory + "/" + languages[i] + ".license.txt";
+    for (auto const& language : languages) {
+      std::string license = slaDirectory + "/" + language + ".license.txt";
       if (!singleLicense && !cmSystemTools::FileExists(license)) {
         cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing license file "
-                        << languages[i] << ".license.txt" << std::endl);
+                        << language << ".license.txt" << std::endl);
         return 0;
       }
-      std::string menu = slaDirectory + "/" + languages[i] + ".menu.txt";
+      std::string menu = slaDirectory + "/" + language + ".menu.txt";
       if (!cmSystemTools::FileExists(menu)) {
         cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing menu file "
-                        << languages[i] << ".menu.txt" << std::endl);
+                        << language << ".menu.txt" << std::endl);
         return 0;
       }
     }
@@ -185,19 +185,19 @@ int cmCPackDragNDropGenerator::PackageFiles()
 
   // loop to create dmg files
   packageFileNames.clear();
-  for (size_t i = 0; i < package_files.size(); i++) {
+  for (auto const& package_file : package_files) {
     std::string full_package_name = std::string(toplevel) + std::string("/");
-    if (package_files[i] == "ALL_IN_ONE") {
+    if (package_file == "ALL_IN_ONE") {
       full_package_name += this->GetOption("CPACK_PACKAGE_FILE_NAME");
     } else {
-      full_package_name += package_files[i];
+      full_package_name += package_file;
     }
     full_package_name += std::string(GetOutputExtension());
     packageFileNames.push_back(full_package_name);
 
     std::string src_dir = toplevel;
     src_dir += "/";
-    src_dir += package_files[i];
+    src_dir += package_file;
 
     if (0 == this->CreateDMG(src_dir, full_package_name)) {
       return 0;
@@ -226,14 +226,14 @@ bool cmCPackDragNDropGenerator::CreateEmptyFile(std::ostringstream& target,
   cmsys::ofstream fout(target.str().c_str(), std::ios::out | std::ios::binary);
   if (!fout) {
     return false;
-  } else {
-    // Seek to desired size - 1 byte
-    fout.seekp(size - 1, std::ios::beg);
-    char byte = 0;
-    // Write one byte to ensure file grows
-    fout.write(&byte, 1);
   }
 
+  // Seek to desired size - 1 byte
+  fout.seekp(size - 1, std::ios::beg);
+  char byte = 0;
+  // Write one byte to ensure file grows
+  fout.write(&byte, 1);
+
   return true;
 }
 
@@ -561,7 +561,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
           cmCPackLogger(cmCPackLog::LOG_ERROR, languages[i]
                           << " is not a recognized language" << std::endl);
         }
-        char* iso_language_cstr = (char*)malloc(65);
+        char* iso_language_cstr = static_cast<char*>(malloc(65));
         CFStringGetCString(iso_language, iso_language_cstr, 64,
                            kCFStringEncodingMacRoman);
         LangCode lang = 0;
@@ -769,7 +769,8 @@ std::string cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix(
 
 bool cmCPackDragNDropGenerator::WriteLicense(
   cmGeneratedFileStream& outputStream, int licenseNumber,
-  std::string licenseLanguage, std::string licenseFile, std::string* error)
+  std::string licenseLanguage, const std::string& licenseFile,
+  std::string* error)
 {
   if (!licenseFile.empty() && !singleLicense) {
     licenseNumber = 5002;
@@ -795,8 +796,8 @@ bool cmCPackDragNDropGenerator::WriteLicense(
         if (!this->BreakLongLine(line, lines, error)) {
           return false;
         }
-        for (size_t i = 0; i < lines.size(); ++i) {
-          outputStream << "        \"" << lines[i] << "\"\n";
+        for (auto const& l : lines) {
+          outputStream << "        \"" << l << "\"\n";
         }
       }
       outputStream << "        \"\\n\"\n";
@@ -865,10 +866,11 @@ bool cmCPackDragNDropGenerator::BreakLongLine(const std::string& line,
     size_t line_length = max_line_length;
     if (i + line_length > line.size()) {
       line_length = line.size() - i;
-    } else
+    } else {
       while (line_length > 0 && line[i + line_length - 1] != ' ') {
         line_length = line_length - 1;
       }
+    }
 
     if (line_length == 0) {
       *error = "Please make sure there are no words "

+ 2 - 2
Source/CPack/cmCPackDragNDropGenerator.h

@@ -45,8 +45,8 @@ private:
   bool singleLicense;
 
   bool WriteLicense(cmGeneratedFileStream& outputStream, int licenseNumber,
-                    std::string licenseLanguage, std::string licenseFile,
-                    std::string* error);
+                    std::string licenseLanguage,
+                    const std::string& licenseFile, std::string* error);
   bool BreakLongLine(const std::string& line, std::vector<std::string>& lines,
                      std::string* error);
   void EscapeQuotesAndBackslashes(std::string& line);

+ 2 - 2
Source/CPack/cmCPackPKGGenerator.cxx

@@ -42,9 +42,9 @@ std::string cmCPackPKGGenerator::GetPackageName(
     out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) << "-"
         << component.Name << ".pkg";
     return out.str();
-  } else {
-    return component.ArchiveFile + ".pkg";
   }
+
+  return component.ArchiveFile + ".pkg";
 }
 
 void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile)

+ 2 - 1
Source/CPack/cmCPackPackageMakerGenerator.cxx

@@ -275,8 +275,9 @@ int cmCPackPackageMakerGenerator::PackageFiles()
     if (this->PackageMakerVersion > 2.0) {
       pkgCmd << " -v";
     }
-    if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str()))
+    if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str())) {
       return 0;
+    }
   } else {
     // We have built the package in place. Generate the
     // distribution.dist file to describe it for the installer.

+ 1 - 1
Source/CPack/cmCPackProductBuildGenerator.cxx

@@ -190,7 +190,7 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage(
     cmCPackLogger(cmCPackLog::LOG_ERROR,
                   "Problem creating installer directory: " << scriptDir
                                                            << std::endl);
-    return 0;
+    return false;
   }
 
   // if preflight, postflight, or postupgrade are set

+ 1 - 0
Source/CTest/cmCTestBuildHandler.cxx

@@ -769,6 +769,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
   }
 
   std::vector<const char*> argv;
+  argv.reserve(args.size() + 1);
   for (std::string const& arg : args) {
     argv.push_back(arg.c_str());
   }

+ 1 - 0
Source/CTest/cmCTestGIT.cxx

@@ -214,6 +214,7 @@ bool cmCTestGIT::UpdateByCustom(std::string const& custom)
   std::vector<std::string> git_custom_command;
   cmSystemTools::ExpandListArgument(custom, git_custom_command, true);
   std::vector<char const*> git_custom;
+  git_custom.reserve(git_custom_command.size() + 1);
   for (std::string const& i : git_custom_command) {
     git_custom.push_back(i.c_str());
   }

+ 1 - 0
Source/CTest/cmCTestP4.cxx

@@ -464,6 +464,7 @@ bool cmCTestP4::UpdateCustom(const std::string& custom)
   cmSystemTools::ExpandListArgument(custom, p4_custom_command, true);
 
   std::vector<char const*> p4_custom;
+  p4_custom.reserve(p4_custom_command.size() + 1);
   for (std::string const& i : p4_custom_command) {
     p4_custom.push_back(i.c_str());
   }

+ 1 - 0
Source/CTest/cmCTestVC.cxx

@@ -56,6 +56,7 @@ bool cmCTestVC::InitialCheckout(const char* command)
   // Construct the initial checkout command line.
   std::vector<std::string> args = cmSystemTools::ParseArguments(command);
   std::vector<char const*> vc_co;
+  vc_co.reserve(args.size() + 1);
   for (std::string const& arg : args) {
     vc_co.push_back(arg.c_str());
   }

+ 2 - 0
Source/cmCTest.cxx

@@ -969,6 +969,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output,
   }
 
   std::vector<const char*> argv;
+  argv.reserve(args.size() + 1);
   for (std::string const& a : args) {
     argv.push_back(a.c_str());
   }
@@ -2569,6 +2570,7 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args,
                          const char* dir, double timeout, Encoding encoding)
 {
   std::vector<const char*> argv;
+  argv.reserve(args.size() + 1);
   for (std::string const& a : args) {
     argv.push_back(a.c_str());
   }

+ 1 - 0
Source/cmCommonTargetGenerator.cxx

@@ -194,6 +194,7 @@ std::string cmCommonTargetGenerator::GetManifests()
   this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
 
   std::vector<std::string> manifests;
+  manifests.reserve(manifest_srcs.size());
   for (cmSourceFile const* manifest_src : manifest_srcs) {
     manifests.push_back(this->LocalCommonGenerator->ConvertToOutputFormat(
       this->LocalCommonGenerator->ConvertToRelativePath(

+ 2 - 3
Source/cmFileCommand.cxx

@@ -2294,10 +2294,9 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args)
   if (errorArg.GetString().empty()) {
     this->SetError(error);
     return false;
-  } else {
-    this->Makefile->AddDefinition(errorArg.GetString(), error.c_str());
-    return true;
   }
+  this->Makefile->AddDefinition(errorArg.GetString(), error.c_str());
+  return true;
 #endif
 }
 

+ 14 - 10
Source/cmFileTimeComparison.cxx

@@ -116,18 +116,22 @@ int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1,
   // Compare using nanosecond resolution.
   if (s1->st_mtimespec.tv_sec < s2->st_mtimespec.tv_sec) {
     return -1;
-  } else if (s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec) {
+  }
+  if (s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec) {
     return 1;
-  } else if (s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec) {
+  }
+  if (s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec) {
     return -1;
-  } else if (s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec) {
+  }
+  if (s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec) {
     return 1;
   }
 #else
   // Compare using 1 second resolution.
   if (s1->st_mtime < s2->st_mtime) {
     return -1;
-  } else if (s1->st_mtime > s2->st_mtime) {
+  }
+  if (s1->st_mtime > s2->st_mtime) {
     return 1;
   }
 #endif
@@ -162,20 +166,20 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
   long long t2 = s2->st_mtimespec.tv_sec * bil + s2->st_mtimespec.tv_nsec;
   if (t1 < t2) {
     return (t2 - t1) >= bil;
-  } else if (t2 < t1) {
+  }
+  if (t2 < t1) {
     return (t1 - t2) >= bil;
-  } else {
-    return false;
   }
+  return false;
 #else
   // Times are integers in units of 1s.
   if (s1->st_mtime < s2->st_mtime) {
     return (s2->st_mtime - s1->st_mtime) >= 1;
-  } else if (s1->st_mtime > s2->st_mtime) {
+  }
+  if (s1->st_mtime > s2->st_mtime) {
     return (s1->st_mtime - s2->st_mtime) >= 1;
-  } else {
-    return false;
   }
+  return false;
 #endif
 #else
   // Times are integers in units of 100ns.

+ 1 - 1
Source/cmFindLibraryCommand.cxx

@@ -260,7 +260,7 @@ void cmFindLibraryHelper::RegexFromLiteral(std::string& out,
       out += "\\";
     }
 #if defined(_WIN32) || defined(__APPLE__)
-    out += tolower(ch);
+    out += static_cast<char>(tolower(ch));
 #else
     out += ch;
 #endif

+ 173 - 220
Source/cmGlobalXCodeGenerator.cxx

@@ -47,8 +47,11 @@ public:
     : Version("1.5")
   {
   }
-  void StartElement(const std::string&, const char**) { this->Data = ""; }
-  void EndElement(const std::string& name)
+  void StartElement(const std::string&, const char**) override
+  {
+    this->Data = "";
+  }
+  void EndElement(const std::string& name) override
   {
     if (name == "key") {
       this->Key = this->Data;
@@ -58,7 +61,7 @@ public:
       }
     }
   }
-  void CharacterDataHandler(const char* data, int length)
+  void CharacterDataHandler(const char* data, int length) override
   {
     this->Data.append(data, length);
   }
@@ -108,9 +111,8 @@ public:
   {
     if (this->Group) {
       return this->Group;
-    } else {
-      return this->Generator->CreateString(this->String);
     }
+    return this->Generator->CreateString(this->String);
   }
 };
 
@@ -161,8 +163,9 @@ cmGlobalGeneratorFactory* cmGlobalXCodeGenerator::NewFactory()
 cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator(
   const std::string& name, cmake* cm) const
 {
-  if (name != GetActualName())
+  if (name != GetActualName()) {
     return nullptr;
+  }
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   cmXcodeVersionParser parser;
   std::string versionFile;
@@ -237,10 +240,9 @@ std::string cmGlobalXCodeGenerator::FindXcodeBuildCommand()
       makeProgram = "xcodebuild";
     }
     return makeProgram;
-  } else {
-    // Use cmakexbuild wrapper to suppress environment dump from output.
-    return cmSystemTools::GetCMakeCommand() + "xbuild";
   }
+  // Use cmakexbuild wrapper to suppress environment dump from output.
+  return cmSystemTools::GetCMakeCommand() + "xbuild";
 }
 
 bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts,
@@ -435,18 +437,13 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
 
   // now make the allbuild depend on all the non-utility targets
   // in the project
-  for (std::vector<cmLocalGenerator*>::iterator i = gens.begin();
-       i != gens.end(); ++i) {
-    cmLocalGenerator* lg = *i;
-    if (this->IsExcluded(root, *i)) {
+  for (auto& gen : gens) {
+    if (this->IsExcluded(root, gen)) {
       continue;
     }
 
-    const std::vector<cmGeneratorTarget*>& tgts = lg->GetGeneratorTargets();
-    for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
-         l != tgts.end(); l++) {
-      cmGeneratorTarget* target = *l;
-
+    const std::vector<cmGeneratorTarget*>& tgts = gen->GetGeneratorTargets();
+    for (auto target : tgts) {
       if (target->GetType() == cmStateEnums::GLOBAL_TARGET) {
         continue;
       }
@@ -472,7 +469,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
         cmCustomCommandLines commandLines;
         commandLines.push_back(makeHelper);
         std::vector<std::string> no_byproducts;
-        lg->GetMakefile()->AddCustomCommandToTarget(
+        gen->GetMakefile()->AddCustomCommandToTarget(
           target->GetName(), no_byproducts, no_depends, commandLines,
           cmTarget::POST_BUILD, "Depend check for xcode", dir.c_str(), true,
           false, "", false, cmMakefile::AcceptObjectLibraryCommands);
@@ -484,7 +481,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
       }
 
       // Refer to the build configuration file for easy editing.
-      listfile = lg->GetCurrentSourceDirectory();
+      listfile = gen->GetCurrentSourceDirectory();
       listfile += "/";
       listfile += "CMakeLists.txt";
       target->AddSource(listfile);
@@ -496,9 +493,8 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
   cmLocalGenerator* root, std::vector<cmLocalGenerator*> const& gens)
 {
   std::vector<std::string> lfiles;
-  for (std::vector<cmLocalGenerator*>::const_iterator gi = gens.begin();
-       gi != gens.end(); ++gi) {
-    std::vector<std::string> const& lf = (*gi)->GetMakefile()->GetListFiles();
+  for (auto gen : gens) {
+    std::vector<std::string> const& lf = gen->GetMakefile()->GetListFiles();
     lfiles.insert(lfiles.end(), lf.begin(), lf.end());
   }
 
@@ -558,8 +554,8 @@ void cmGlobalXCodeGenerator::SortXCodeObjects()
 void cmGlobalXCodeGenerator::ClearXCodeObjects()
 {
   this->TargetDoneSet.clear();
-  for (unsigned int i = 0; i < this->XCodeObjects.size(); ++i) {
-    delete this->XCodeObjects[i];
+  for (auto& obj : this->XCodeObjects) {
+    delete obj;
   }
   this->XCodeObjects.clear();
   this->XCodeObjectIDs.clear();
@@ -573,7 +569,7 @@ void cmGlobalXCodeGenerator::ClearXCodeObjects()
 void cmGlobalXCodeGenerator::addObject(cmXCodeObject* obj)
 {
   if (obj->GetType() == cmXCodeObject::OBJECT) {
-    std::string id = obj->GetId();
+    const std::string& id = obj->GetId();
 
     // If this is a duplicate id, it's an error:
     //
@@ -933,13 +929,11 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets(
   typedef std::map<std::string, cmGeneratorTarget*, cmCompareTargets>
     cmSortedTargets;
   cmSortedTargets sortedTargets;
-  for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
-       l != tgts.end(); l++) {
-    sortedTargets[(*l)->GetName()] = *l;
+  for (auto tgt : tgts) {
+    sortedTargets[tgt->GetName()] = tgt;
   }
-  for (cmSortedTargets::iterator l = sortedTargets.begin();
-       l != sortedTargets.end(); l++) {
-    cmGeneratorTarget* gtgt = l->second;
+  for (auto& sortedTarget : sortedTargets) {
+    cmGeneratorTarget* gtgt = sortedTarget.second;
 
     std::string targetName = gtgt->GetName();
 
@@ -1042,9 +1036,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets(
       sourceBuildPhase->AddAttribute("buildActionMask",
                                      this->CreateString("2147483647"));
       buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
-      for (std::vector<cmXCodeObject*>::iterator i = sourceFiles.begin();
-           i != sourceFiles.end(); ++i) {
-        buildFiles->AddObject(*i);
+      for (auto& sourceFile : sourceFiles) {
+        buildFiles->AddObject(sourceFile);
       }
       sourceBuildPhase->AddAttribute("files", buildFiles);
       sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
@@ -1060,9 +1053,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets(
       headerBuildPhase->AddAttribute("buildActionMask",
                                      this->CreateString("2147483647"));
       buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
-      for (std::vector<cmXCodeObject*>::iterator i = headerFiles.begin();
-           i != headerFiles.end(); ++i) {
-        buildFiles->AddObject(*i);
+      for (auto& headerFile : headerFiles) {
+        buildFiles->AddObject(headerFile);
       }
       headerBuildPhase->AddAttribute("files", buildFiles);
       headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
@@ -1079,9 +1071,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets(
       resourceBuildPhase->AddAttribute("buildActionMask",
                                        this->CreateString("2147483647"));
       buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
-      for (std::vector<cmXCodeObject*>::iterator i = resourceFiles.begin();
-           i != resourceFiles.end(); ++i) {
-        buildFiles->AddObject(*i);
+      for (auto& resourceFile : resourceFiles) {
+        buildFiles->AddObject(resourceFile);
       }
       resourceBuildPhase->AddAttribute("files", buildFiles);
       resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
@@ -1189,9 +1180,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets(
                                         this->CreateString("2147483647"));
       buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
       frameworkBuildPhase->AddAttribute("files", buildFiles);
-      for (std::vector<cmXCodeObject*>::iterator i = externalObjFiles.begin();
-           i != externalObjFiles.end(); ++i) {
-        buildFiles->AddObject(*i);
+      for (auto& externalObjFile : externalObjFiles) {
+        buildFiles->AddObject(externalObjFile);
       }
       frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
                                         this->CreateString("0"));
@@ -1212,14 +1202,13 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets(
 
 void cmGlobalXCodeGenerator::ForceLinkerLanguages()
 {
-  for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
+  for (auto& localGenerator : this->LocalGenerators) {
     const std::vector<cmGeneratorTarget*>& tgts =
-      this->LocalGenerators[i]->GetGeneratorTargets();
+      localGenerator->GetGeneratorTargets();
     // All targets depend on the build-system check target.
-    for (std::vector<cmGeneratorTarget*>::const_iterator ti = tgts.begin();
-         ti != tgts.end(); ++ti) {
+    for (auto tgt : tgts) {
       // This makes sure all targets link using the proper language.
-      this->ForceLinkerLanguage(*ti);
+      this->ForceLinkerLanguage(tgt);
     }
   }
 }
@@ -1240,9 +1229,8 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt)
 
   // If the language is compiled as a source trust Xcode to link with it.
   cmLinkImplementation const* impl = gtgt->GetLinkImplementation("NOCONFIG");
-  for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
-       li != impl->Languages.end(); ++li) {
-    if (*li == llang) {
+  for (auto const& Language : impl->Languages) {
+    if (Language == llang) {
       return;
     }
   }
@@ -1280,7 +1268,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateBuildPhase(
   const char* name, const char* name2, cmGeneratorTarget* target,
   const std::vector<cmCustomCommand>& commands)
 {
-  if (commands.size() == 0 && strcmp(name, "CMake ReRun") != 0) {
+  if (commands.empty() && strcmp(name, "CMake ReRun") != 0) {
     return nullptr;
   }
   cmXCodeObject* buildPhase =
@@ -1468,7 +1456,7 @@ void cmGlobalXCodeGenerator::FilterConfigurationAttribute(
     return;
   }
 
-  std::string::size_type endVariant = attribute.find("]", beginVariant + 9);
+  std::string::size_type endVariant = attribute.find(']', beginVariant + 9);
   if (endVariant == std::string::npos) {
     // There is no terminating bracket.
     return;
@@ -1544,16 +1532,15 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
   makefileStream << "all: ";
   std::map<const cmCustomCommand*, std::string> tname;
   int count = 0;
-  for (std::vector<cmCustomCommand>::const_iterator i = commands.begin();
-       i != commands.end(); ++i) {
-    cmCustomCommandGenerator ccg(*i, configName, this->CurrentLocalGenerator);
+  for (auto const& command : commands) {
+    cmCustomCommandGenerator ccg(command, configName,
+                                 this->CurrentLocalGenerator);
     if (ccg.GetNumberOfCommands() > 0) {
       const std::vector<std::string>& outputs = ccg.GetOutputs();
       if (!outputs.empty()) {
-        for (std::vector<std::string>::const_iterator o = outputs.begin();
-             o != outputs.end(); ++o) {
+        for (auto const& output : outputs) {
           makefileStream << "\\\n\t"
-                         << this->ConvertToRelativeForMake(o->c_str());
+                         << this->ConvertToRelativeForMake(output.c_str());
         }
       } else {
         std::ostringstream str;
@@ -1564,18 +1551,18 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
     }
   }
   makefileStream << "\n\n";
-  for (std::vector<cmCustomCommand>::const_iterator i = commands.begin();
-       i != commands.end(); ++i) {
-    cmCustomCommandGenerator ccg(*i, configName, this->CurrentLocalGenerator);
+  for (auto const& command : commands) {
+    cmCustomCommandGenerator ccg(command, configName,
+                                 this->CurrentLocalGenerator);
     if (ccg.GetNumberOfCommands() > 0) {
       makefileStream << "\n";
       const std::vector<std::string>& outputs = ccg.GetOutputs();
       if (!outputs.empty()) {
         // There is at least one output, start the rule for it
         const char* sep = "";
-        for (std::vector<std::string>::const_iterator oi = outputs.begin();
-             oi != outputs.end(); ++oi) {
-          makefileStream << sep << this->ConvertToRelativeForMake(oi->c_str());
+        for (auto const& output : outputs) {
+          makefileStream << sep
+                         << this->ConvertToRelativeForMake(output.c_str());
           sep = " ";
         }
         makefileStream << ": ";
@@ -1583,11 +1570,9 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
         // There are no outputs.  Use the generated force rule name.
         makefileStream << tname[&ccg.GetCC()] << ": ";
       }
-      for (std::vector<std::string>::const_iterator d =
-             ccg.GetDepends().begin();
-           d != ccg.GetDepends().end(); ++d) {
+      for (auto const& d : ccg.GetDepends()) {
         std::string dep;
-        if (this->CurrentLocalGenerator->GetRealDependency(*d, configName,
+        if (this->CurrentLocalGenerator->GetRealDependency(d, configName,
                                                            dep)) {
           makefileStream << "\\\n"
                          << this->ConvertToRelativeForMake(dep.c_str());
@@ -1642,9 +1627,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
   std::set<std::string> languages;
   gtgt->GetLanguages(languages, configName);
   std::map<std::string, std::string> cflags;
-  for (std::set<std::string>::iterator li = languages.begin();
-       li != languages.end(); ++li) {
-    std::string const& lang = *li;
+  for (auto const& lang : languages) {
     std::string& flags = cflags[lang];
 
     // Add language-specific flags.
@@ -1740,9 +1723,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
     } else {
       cmXCodeObject* archObjects =
         this->CreateObject(cmXCodeObject::OBJECT_LIST);
-      for (std::vector<std::string>::iterator i = archs.begin();
-           i != archs.end(); i++) {
-        archObjects->AddObject(this->CreateString(*i));
+      for (auto& arch : archs) {
+        archObjects->AddObject(this->CreateString(arch));
       }
       buildSettings->AddAttribute("ARCHS", archObjects);
     }
@@ -1967,10 +1949,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
   std::set<std::string> emitted;
   emitted.insert("/System/Library/Frameworks");
 
-  for (std::vector<std::string>::iterator i = includes.begin();
-       i != includes.end(); ++i) {
-    if (this->NameResolvesToFramework(*i)) {
-      std::string frameworkDir = *i;
+  for (auto& include : includes) {
+    if (this->NameResolvesToFramework(include)) {
+      std::string frameworkDir = include;
       frameworkDir += "/../";
       frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
       if (emitted.insert(frameworkDir).second) {
@@ -1983,9 +1964,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
         }
       }
     } else {
-      std::string incpath = this->XCodeEscapePath(*i);
+      std::string incpath = this->XCodeEscapePath(include);
       if (emitSystemIncludes &&
-          gtgt->IsSystemIncludeDirectory(*i, configName)) {
+          gtgt->IsSystemIncludeDirectory(include, configName)) {
         sysdirs.Add(incpath);
       } else {
         dirs.Add(incpath);
@@ -1995,12 +1976,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
   // Add framework search paths needed for linking.
   if (cmComputeLinkInformation* cli = gtgt->GetLinkInformation(configName)) {
     std::vector<std::string> const& fwDirs = cli->GetFrameworkPaths();
-    for (std::vector<std::string>::const_iterator fdi = fwDirs.begin();
-         fdi != fwDirs.end(); ++fdi) {
-      if (emitted.insert(*fdi).second) {
-        std::string incpath = this->XCodeEscapePath(*fdi);
+    for (auto const& fwDir : fwDirs) {
+      if (emitted.insert(fwDir).second) {
+        std::string incpath = this->XCodeEscapePath(fwDir);
         if (emitSystemIncludes &&
-            gtgt->IsSystemIncludeDirectory(*fdi, configName)) {
+            gtgt->IsSystemIncludeDirectory(fwDir, configName)) {
           sysfdirs.Add(incpath);
         } else {
           fdirs.Add(incpath);
@@ -2028,13 +2008,12 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
     // system include directory awareness. We need to also keep on setting
     // HEADER_SEARCH_PATHS to work around a missing compile options flag for
     // GNU assembly files (#16449)
-    for (std::set<std::string>::iterator li = languages.begin();
-         li != languages.end(); ++li) {
+    for (auto const& language : languages) {
       std::string includeFlags = this->CurrentLocalGenerator->GetIncludeFlags(
-        includes, gtgt, *li, true, false, configName);
+        includes, gtgt, language, true, false, configName);
 
       if (!includeFlags.empty()) {
-        cflags[*li] += " " + includeFlags;
+        cflags[language] += " " + includeFlags;
       }
     }
   }
@@ -2045,10 +2024,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
   std::string optLevel = "0";
 
   // Minimal map of flags to build settings.
-  for (std::set<std::string>::iterator li = languages.begin();
-       li != languages.end(); ++li) {
-    std::string& flags = cflags[*li];
-    std::string& gflag = gflags[*li];
+  for (auto const& language : languages) {
+    std::string& flags = cflags[language];
+    std::string& gflag = gflags[language];
     std::string oflag =
       this->ExtractFlagRegex("(^| )(-Ofast|-Os|-O[0-9]*)( |$)", 2, flags);
     if (oflag.size() == 2) {
@@ -2073,10 +2051,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
   if (!same_gflags) {
     // We can't set the Xcode flag differently depending on the language,
     // so put them back in this case.
-    for (std::set<std::string>::iterator li = languages.begin();
-         li != languages.end(); ++li) {
-      cflags[*li] += " ";
-      cflags[*li] += gflags[*li];
+    for (auto const& language : languages) {
+      cflags[language] += " ";
+      cflags[language] += gflags[language];
     }
     debugStr = "NO";
   } else if (last_gflag && (last_gflag->empty() || *last_gflag == "-g0")) {
@@ -2093,18 +2070,17 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
                               this->CreateString("NO"));
   buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
                               this->CreateString("NO"));
-  for (std::set<std::string>::iterator li = languages.begin();
-       li != languages.end(); ++li) {
-    std::string flags = cflags[*li] + " " + defFlags;
-    if (*li == "CXX") {
+  for (auto const& language : languages) {
+    std::string flags = cflags[language] + " " + defFlags;
+    if (language == "CXX") {
       buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
                                   this->CreateString(flags));
-    } else if (*li == "Fortran") {
+    } else if (language == "Fortran") {
       buildSettings->AddAttribute("IFORT_OTHER_FLAGS",
                                   this->CreateString(flags));
-    } else if (*li == "C") {
+    } else if (language == "C") {
       buildSettings->AddAttribute("OTHER_CFLAGS", this->CreateString(flags));
-    } else if (*li == "Swift") {
+    } else if (language == "Swift") {
       buildSettings->AddAttribute("OTHER_SWIFT_FLAGS",
                                   this->CreateString(flags));
     }
@@ -2228,15 +2204,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
   // Convert "XCODE_ATTRIBUTE_*" properties directly.
   {
     std::vector<std::string> const& props = gtgt->GetPropertyKeys();
-    for (std::vector<std::string>::const_iterator i = props.begin();
-         i != props.end(); ++i) {
-      if (i->find("XCODE_ATTRIBUTE_") == 0) {
-        std::string attribute = i->substr(16);
+    for (auto const& prop : props) {
+      if (prop.find("XCODE_ATTRIBUTE_") == 0) {
+        std::string attribute = prop.substr(16);
         this->FilterConfigurationAttribute(configName, attribute);
         if (!attribute.empty()) {
           cmGeneratorExpression ge;
           std::string processed =
-            ge.Parse(gtgt->GetProperty(*i))
+            ge.Parse(gtgt->GetProperty(prop))
               ->Evaluate(this->CurrentLocalGenerator, configName);
           buildSettings->AddAttribute(attribute,
                                       this->CreateString(processed));
@@ -2324,15 +2299,15 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
   configlist->SetComment(comment);
   target->AddAttribute("buildConfigurationList",
                        this->CreateObjectReference(configlist));
-  for (unsigned int i = 0; i < configVector.size(); ++i) {
+  for (auto const& i : configVector) {
     cmXCodeObject* config =
       this->CreateObject(cmXCodeObject::XCBuildConfiguration);
     buildConfigurations->AddObject(config);
     cmXCodeObject* buildSettings =
       this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
-    this->CreateBuildSettings(gtgt, buildSettings, configVector[i]);
-    config->AddAttribute("name", this->CreateString(configVector[i]));
-    config->SetComment(configVector[i]);
+    this->CreateBuildSettings(gtgt, buildSettings, i);
+    config->AddAttribute("name", this->CreateString(i));
+    config->SetComment(i);
     config->AddAttribute("buildSettings", buildSettings);
   }
   if (!configVector.empty()) {
@@ -2352,9 +2327,8 @@ const char* cmGlobalXCodeGenerator::GetTargetLinkFlagsVar(
       (target->GetType() == cmStateEnums::STATIC_LIBRARY ||
        target->GetType() == cmStateEnums::OBJECT_LIBRARY)) {
     return "OTHER_LIBTOOLFLAGS";
-  } else {
-    return "OTHER_LDFLAGS";
   }
+  return "OTHER_LDFLAGS";
 }
 
 const char* cmGlobalXCodeGenerator::GetTargetFileType(
@@ -2371,12 +2345,13 @@ const char* cmGlobalXCodeGenerator::GetTargetFileType(
       return (target->GetPropertyAsBool("FRAMEWORK") ? "wrapper.framework"
                                                      : "archive.ar");
     case cmStateEnums::MODULE_LIBRARY:
-      if (target->IsXCTestOnApple())
+      if (target->IsXCTestOnApple()) {
         return "wrapper.cfbundle";
-      else if (target->IsCFBundleOnApple())
+      }
+      if (target->IsCFBundleOnApple()) {
         return "wrapper.plug-in";
-      else
-        return "compiled.mach-o.executable";
+      }
+      return "compiled.mach-o.executable";
     case cmStateEnums::SHARED_LIBRARY:
       return (target->GetPropertyAsBool("FRAMEWORK")
                 ? "wrapper.framework"
@@ -2404,12 +2379,13 @@ const char* cmGlobalXCodeGenerator::GetTargetProductType(
                 ? "com.apple.product-type.framework"
                 : "com.apple.product-type.library.static");
     case cmStateEnums::MODULE_LIBRARY:
-      if (target->IsXCTestOnApple())
+      if (target->IsXCTestOnApple()) {
         return "com.apple.product-type.bundle.unit-test";
-      else if (target->IsCFBundleOnApple())
+      } else if (target->IsCFBundleOnApple()) {
         return "com.apple.product-type.bundle";
-      else
+      } else {
         return "com.apple.product-type.tool";
+      }
     case cmStateEnums::SHARED_LIBRARY:
       return (target->GetPropertyAsBool("FRAMEWORK")
                 ? "com.apple.product-type.framework"
@@ -2563,15 +2539,14 @@ void cmGlobalXCodeGenerator::AppendBuildSettingAttribute(
   std::vector<cmXCodeObject*> list = buildConfigs->GetObjectList();
   // each configuration and the target itself has a buildSettings in it
   // list.push_back(target);
-  for (std::vector<cmXCodeObject*>::iterator i = list.begin(); i != list.end();
-       ++i) {
+  for (auto& i : list) {
     if (!configName.empty()) {
-      if ((*i)->GetObject("name")->GetString() == configName) {
-        cmXCodeObject* settings = (*i)->GetObject("buildSettings");
+      if (i->GetObject("name")->GetString() == configName) {
+        cmXCodeObject* settings = i->GetObject("buildSettings");
         this->AppendOrAddBuildSetting(settings, attribute, value);
       }
     } else {
-      cmXCodeObject* settings = (*i)->GetObject("buildSettings");
+      cmXCodeObject* settings = i->GetObject("buildSettings");
       this->AppendOrAddBuildSetting(settings, attribute, value);
     }
   }
@@ -2590,20 +2565,15 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
 
   // Add dependencies on other CMake targets.
   TargetDependSet const& deps = this->GetTargetDirectDepends(gt);
-  for (TargetDependSet::const_iterator i = deps.begin(); i != deps.end();
-       ++i) {
-    if (cmXCodeObject* dptarget = this->FindXCodeTarget(*i)) {
+  for (auto dep : deps) {
+    if (cmXCodeObject* dptarget = this->FindXCodeTarget(dep)) {
       this->AddDependTarget(target, dptarget);
     }
   }
 
   // Loop over configuration types and set per-configuration info.
-  for (std::vector<std::string>::iterator i =
-         this->CurrentConfigurationTypes.begin();
-       i != this->CurrentConfigurationTypes.end(); ++i) {
+  for (auto const& configName : this->CurrentConfigurationTypes) {
     // Get the current configuration name.
-    std::string configName = *i;
-
     if (this->XcodeVersion >= 50) {
       // Add object library contents as link flags.
       std::string linkObjs;
@@ -2639,9 +2609,8 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
     // Add dependencies directly on library files.
     {
       std::vector<std::string> const& libDeps = cli.GetDepends();
-      for (std::vector<std::string>::const_iterator j = libDeps.begin();
-           j != libDeps.end(); ++j) {
-        target->AddDependLibrary(configName, *j);
+      for (auto const& libDep : libDeps) {
+        target->AddDependLibrary(configName, libDep);
       }
     }
 
@@ -2649,16 +2618,15 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
     {
       std::vector<std::string> const& libDirs = cli.GetDirectories();
       std::string linkDirs;
-      for (std::vector<std::string>::const_iterator libDir = libDirs.begin();
-           libDir != libDirs.end(); ++libDir) {
-        if (libDir->size() && *libDir != "/usr/lib") {
+      for (auto const& libDir : libDirs) {
+        if (!libDir.empty() && libDir != "/usr/lib") {
           // Now add the same one but append
           // $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to it:
           linkDirs += " ";
           linkDirs += this->XCodeEscapePath(
-            *libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)");
+            libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)");
           linkDirs += " ";
-          linkDirs += this->XCodeEscapePath(*libDir);
+          linkDirs += this->XCodeEscapePath(libDir);
         }
       }
       this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
@@ -2671,18 +2639,18 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
       const char* sep = "";
       typedef cmComputeLinkInformation::ItemVector ItemVector;
       ItemVector const& libNames = cli.GetItems();
-      for (ItemVector::const_iterator li = libNames.begin();
-           li != libNames.end(); ++li) {
+      for (auto const& libName : libNames) {
         linkLibs += sep;
         sep = " ";
-        if (li->IsPath) {
-          linkLibs += this->XCodeEscapePath(li->Value);
-        } else if (!li->Target ||
-                   li->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
-          linkLibs += li->Value;
+        if (libName.IsPath) {
+          linkLibs += this->XCodeEscapePath(libName.Value);
+        } else if (!libName.Target ||
+                   libName.Target->GetType() !=
+                     cmStateEnums::INTERFACE_LIBRARY) {
+          linkLibs += libName.Value;
         }
-        if (li->Target && !li->Target->IsImported()) {
-          target->AddDependTarget(configName, li->Target->GetName());
+        if (libName.Target && !libName.Target->IsImported()) {
+          target->AddDependTarget(configName, libName.Target->GetName());
         }
       }
       this->AppendBuildSettingAttribute(
@@ -2694,15 +2662,12 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
 bool cmGlobalXCodeGenerator::CreateGroups(
   std::vector<cmLocalGenerator*>& generators)
 {
-  for (std::vector<cmLocalGenerator*>::iterator i = generators.begin();
-       i != generators.end(); ++i) {
-    cmMakefile* mf = (*i)->GetMakefile();
+  for (auto& generator : generators) {
+    cmMakefile* mf = generator->GetMakefile();
     std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
-    const std::vector<cmGeneratorTarget*>& tgts = (*i)->GetGeneratorTargets();
-    for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
-         l != tgts.end(); l++) {
-      cmGeneratorTarget* gtgt = *l;
-
+    const std::vector<cmGeneratorTarget*>& tgts =
+      generator->GetGeneratorTargets();
+    for (auto gtgt : tgts) {
       // Same skipping logic here as in CreateXCodeTargets so that we do not
       // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
       // groups:
@@ -2726,10 +2691,8 @@ bool cmGlobalXCodeGenerator::CreateGroups(
         gtgt->GetAllConfigSources();
 
       // Put cmSourceFile instances in proper groups:
-      for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si =
-             sources.begin();
-           si != sources.end(); ++si) {
-        cmSourceFile const* sf = si->Source;
+      for (auto const& si : sources) {
+        cmSourceFile const* sf = si.Source;
         if (this->XcodeVersion >= 50 && !sf->GetObjectLibrary().empty()) {
           // Object library files go on the link line instead.
           continue;
@@ -2748,19 +2711,21 @@ bool cmGlobalXCodeGenerator::CreateGroups(
 }
 
 cmXCodeObject* cmGlobalXCodeGenerator::CreatePBXGroup(cmXCodeObject* parent,
-                                                      std::string name)
+                                                      const std::string& name)
 {
   cmXCodeObject* parentChildren = nullptr;
-  if (parent)
+  if (parent) {
     parentChildren = parent->GetObject("children");
+  }
   cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
   cmXCodeObject* groupChildren =
     this->CreateObject(cmXCodeObject::OBJECT_LIST);
   group->AddAttribute("name", this->CreateString(name));
   group->AddAttribute("children", groupChildren);
   group->AddAttribute("sourceTree", this->CreateString("<group>"));
-  if (parentChildren)
+  if (parentChildren) {
     parentChildren->AddObject(group);
+  }
   return group;
 }
 
@@ -2814,7 +2779,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(
   // If it's the default source group (empty name) then put the source file
   // directly in the tgroup...
   //
-  if (std::string(sg->GetFullName()) == "") {
+  if (std::string(sg->GetFullName()).empty()) {
     this->GroupNameMap[s] = tgroup;
     return tgroup;
   }
@@ -2825,13 +2790,13 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(
       cmSystemTools::tokenize(sg->GetFullName(), "\\");
     std::string curr_folder = target;
     curr_folder += "/";
-    for (std::vector<std::string>::size_type i = 0; i < folders.size(); i++) {
-      curr_folder += folders[i];
+    for (auto const& folder : folders) {
+      curr_folder += folder;
       std::map<std::string, cmXCodeObject*>::iterator i_folder =
         this->GroupNameMap.find(curr_folder);
       // Create new folder
       if (i_folder == this->GroupNameMap.end()) {
-        cmXCodeObject* group = this->CreatePBXGroup(tgroup, folders[i]);
+        cmXCodeObject* group = this->CreatePBXGroup(tgroup, folder);
         this->GroupNameMap[curr_folder] = group;
         tgroup = group;
       } else {
@@ -2855,10 +2820,10 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
   cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
   group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
   cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
-  for (unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i) {
+  for (auto& CurrentConfigurationType : this->CurrentConfigurationTypes) {
     cmXCodeObject* buildStyle =
       this->CreateObject(cmXCodeObject::PBXBuildStyle);
-    const char* name = this->CurrentConfigurationTypes[i].c_str();
+    const char* name = CurrentConfigurationType.c_str();
     buildStyle->AddAttribute("name", this->CreateString(name));
     buildStyle->SetComment(name);
     cmXCodeObject* sgroup = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
@@ -2891,7 +2856,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
   std::string project_id = "PROJECT_";
   project_id += root->GetProjectName();
   this->RootObject->SetId(
-    this->GetOrCreateId(project_id.c_str(), this->RootObject->GetId()));
+    this->GetOrCreateId(project_id, this->RootObject->GetId()));
 
   group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
   this->RootObject->AddAttribute("mainGroup",
@@ -2907,15 +2872,16 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
   v << std::setfill('0') << std::setw(4) << XcodeVersion * 10;
   group->AddAttribute("LastUpgradeCheck", this->CreateString(v.str()));
   this->RootObject->AddAttribute("attributes", group);
-  if (this->XcodeVersion >= 32)
+  if (this->XcodeVersion >= 32) {
     this->RootObject->AddAttribute("compatibilityVersion",
                                    this->CreateString("Xcode 3.2"));
-  else if (this->XcodeVersion >= 31)
+  } else if (this->XcodeVersion >= 31) {
     this->RootObject->AddAttribute("compatibilityVersion",
                                    this->CreateString("Xcode 3.1"));
-  else
+  } else {
     this->RootObject->AddAttribute("compatibilityVersion",
                                    this->CreateString("Xcode 3.0"));
+  }
   // Point Xcode at the top of the source tree.
   {
     std::string pdir =
@@ -2940,8 +2906,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
     config->AddAttribute("name", this->CreateString(name));
     configs.push_back(std::make_pair(name, config));
   }
-  for (Configs::iterator c = configs.begin(); c != configs.end(); ++c) {
-    buildConfigurations->AddObject(c->second);
+  for (auto& config : configs) {
+    buildConfigurations->AddObject(config.second);
   }
   configlist->AddAttribute("buildConfigurations", buildConfigurations);
 
@@ -2999,7 +2965,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
   symroot += "/build";
   buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot));
 
-  for (Configs::iterator i = configs.begin(); i != configs.end(); ++i) {
+  for (auto& config : configs) {
     cmXCodeObject* buildSettingsForCfg = this->CreateFlatClone(buildSettings);
 
     // Put this last so it can override existing settings
@@ -3009,43 +2975,38 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
          d != vars.end(); ++d) {
       if (d->find("CMAKE_XCODE_ATTRIBUTE_") == 0) {
         std::string attribute = d->substr(22);
-        this->FilterConfigurationAttribute(i->first, attribute);
+        this->FilterConfigurationAttribute(config.first, attribute);
         if (!attribute.empty()) {
           cmGeneratorExpression ge;
           std::string processed =
             ge.Parse(this->CurrentMakefile->GetDefinition(*d))
-              ->Evaluate(this->CurrentLocalGenerator, i->first);
+              ->Evaluate(this->CurrentLocalGenerator, config.first);
           buildSettingsForCfg->AddAttribute(attribute,
                                             this->CreateString(processed));
         }
       }
     }
     // store per-config buildSettings into configuration object
-    i->second->AddAttribute("buildSettings", buildSettingsForCfg);
+    config.second->AddAttribute("buildSettings", buildSettingsForCfg);
   }
 
   this->RootObject->AddAttribute("buildConfigurationList",
                                  this->CreateObjectReference(configlist));
 
   std::vector<cmXCodeObject*> targets;
-  for (std::vector<cmLocalGenerator*>::iterator i = generators.begin();
-       i != generators.end(); ++i) {
-    if (!this->CreateXCodeTargets(*i, targets)) {
+  for (auto& generator : generators) {
+    if (!this->CreateXCodeTargets(generator, targets)) {
       return false;
     }
   }
   // loop over all targets and add link and depend info
-  for (std::vector<cmXCodeObject*>::iterator i = targets.begin();
-       i != targets.end(); ++i) {
-    cmXCodeObject* t = *i;
+  for (auto t : targets) {
     this->AddDependAndLinkInformation(t);
   }
   this->CreateXCodeDependHackTarget(targets);
   // now add all targets to the root object
   cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
-  for (std::vector<cmXCodeObject*>::iterator i = targets.begin();
-       i != targets.end(); ++i) {
-    cmXCodeObject* t = *i;
+  for (auto t : targets) {
     allTargets->AddObject(t);
     cmXCodeObject* productRef = t->GetObject("productReference");
     if (productRef) {
@@ -3138,9 +3099,7 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
          this->CurrentConfigurationTypes.begin();
        ct != this->CurrentConfigurationTypes.end(); ++ct) {
     std::string configName = *ct;
-    for (std::vector<cmXCodeObject*>::iterator i = targets.begin();
-         i != targets.end(); ++i) {
-      cmXCodeObject* target = *i;
+    for (auto target : targets) {
       cmGeneratorTarget* gt = target->GetTarget();
 
       if (gt->GetType() == cmStateEnums::EXECUTABLE ||
@@ -3165,9 +3124,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
           target->GetDependTargets().find(*ct);
         if (y != target->GetDependTargets().end()) {
           std::vector<std::string> const& deptgts = y->second;
-          for (std::vector<std::string>::const_iterator d = deptgts.begin();
-               d != deptgts.end(); ++d) {
-            makefileStream << this->PostBuildMakeTarget(*d, *ct) << ": "
+          for (auto const& deptgt : deptgts) {
+            makefileStream << this->PostBuildMakeTarget(deptgt, *ct) << ": "
                            << trel << "\n";
           }
         }
@@ -3189,9 +3147,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
           target->GetDependLibraries().find(*ct);
         if (x != target->GetDependLibraries().end()) {
           std::vector<std::string> const& deplibs = x->second;
-          for (std::vector<std::string>::const_iterator d = deplibs.begin();
-               d != deplibs.end(); ++d) {
-            std::string file = this->ConvertToRelativeForMake(d->c_str());
+          for (auto const& deplib : deplibs) {
+            std::string file = this->ConvertToRelativeForMake(deplib.c_str());
             makefileStream << "\\\n\t" << file;
             dummyRules.insert(file);
           }
@@ -3223,11 +3180,9 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
         if (this->Architectures.size() > 1) {
           std::string universal = this->GetObjectsNormalDirectory(
             this->CurrentProject, configName, gt);
-          for (std::vector<std::string>::iterator arch =
-                 this->Architectures.begin();
-               arch != this->Architectures.end(); ++arch) {
+          for (auto& architecture : this->Architectures) {
             std::string universalFile = universal;
-            universalFile += *arch;
+            universalFile += architecture;
             universalFile += "/";
             universalFile += gt->GetFullName(configName);
             makefileStream << "\t/bin/rm -f "
@@ -3244,22 +3199,20 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
   makefileStream << "\n\n"
                  << "# For each target create a dummy rule"
                  << "so the target does not have to exist\n";
-  for (std::set<std::string>::const_iterator it = dummyRules.begin();
-       it != dummyRules.end(); ++it) {
-    makefileStream << *it << ":\n";
+  for (auto const& dummyRule : dummyRules) {
+    makefileStream << dummyRule << ":\n";
   }
 }
 
 void cmGlobalXCodeGenerator::OutputXCodeProject(
   cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
 {
-  if (generators.size() == 0) {
+  if (generators.empty()) {
     return;
   }
   // Skip local generators that are excluded from this project.
-  for (std::vector<cmLocalGenerator*>::iterator g = generators.begin();
-       g != generators.end(); ++g) {
-    if (this->IsExcluded(root, *g)) {
+  for (auto& generator : generators) {
+    if (this->IsExcluded(root, generator)) {
       continue;
     }
   }
@@ -3387,12 +3340,13 @@ void cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
   cmXCodeObject::Indent(1, fout);
   fout << "};\n";
   cmXCodeObject::Indent(1, fout);
-  if (this->XcodeVersion >= 32)
+  if (this->XcodeVersion >= 32) {
     fout << "objectVersion = 46;\n";
-  else if (this->XcodeVersion >= 31)
+  } else if (this->XcodeVersion >= 31) {
     fout << "objectVersion = 45;\n";
-  else
+  } else {
     fout << "objectVersion = 44;\n";
+  }
   cmXCode21Object::PrintList(this->XCodeObjects, fout);
   cmXCodeObject::Indent(1, fout);
   fout << "rootObject = " << this->RootObject->GetId()
@@ -3512,11 +3466,10 @@ void cmGlobalXCodeGenerator::AppendDefines(
 {
   // GCC_PREPROCESSOR_DEFINITIONS is a space-separated list of definitions.
   std::string def;
-  for (std::vector<std::string>::const_iterator di = defines.begin();
-       di != defines.end(); ++di) {
+  for (auto const& define : defines) {
     // Start with -D if requested.
     def = dflag ? "-D" : "";
-    def += *di;
+    def += define;
 
     // Append the flag with needed escapes.
     std::string tmp;

+ 2 - 1
Source/cmGlobalXCodeGenerator.h

@@ -106,7 +106,8 @@ protected:
 private:
   cmXCodeObject* CreateOrGetPBXGroup(cmGeneratorTarget* gtgt,
                                      cmSourceGroup* sg);
-  cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent, std::string name);
+  cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent,
+                                const std::string& name);
   bool CreateGroups(std::vector<cmLocalGenerator*>& generators);
   std::string XCodeEscapePath(const std::string& p);
   std::string RelativeToSource(const char* p);

+ 1 - 3
Source/cmInstalledFile.cxx

@@ -16,9 +16,7 @@ cmInstalledFile::cmInstalledFile()
 
 cmInstalledFile::~cmInstalledFile()
 {
-  if (NameExpression) {
-    delete NameExpression;
-  }
+  delete NameExpression;
 }
 
 cmInstalledFile::Property::Property()

+ 7 - 11
Source/cmLocalXCodeGenerator.cxx

@@ -43,9 +43,8 @@ void cmLocalXCodeGenerator::Generate()
   cmLocalGenerator::Generate();
 
   const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
-  for (std::vector<cmGeneratorTarget*>::const_iterator iter = targets.begin();
-       iter != targets.end(); ++iter) {
-    (*iter)->HasMacOSXRpathInstallNameDir("");
+  for (auto target : targets) {
+    target->HasMacOSXRpathInstallNameDir("");
   }
 }
 
@@ -54,9 +53,8 @@ void cmLocalXCodeGenerator::GenerateInstallRules()
   cmLocalGenerator::GenerateInstallRules();
 
   const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
-  for (std::vector<cmGeneratorTarget*>::const_iterator iter = targets.begin();
-       iter != targets.end(); ++iter) {
-    (*iter)->HasMacOSXRpathInstallNameDir("");
+  for (auto target : targets) {
+    target->HasMacOSXRpathInstallNameDir("");
   }
 }
 
@@ -69,10 +67,8 @@ void cmLocalXCodeGenerator::ComputeObjectFilenames(
   // to avoid exact duplicate file names. Note that Mac file names are not
   // typically case sensitive, hence the LowerCase.
   std::map<std::string, int> counts;
-  for (std::map<cmSourceFile const*, std::string>::iterator si =
-         mapping.begin();
-       si != mapping.end(); ++si) {
-    cmSourceFile const* sf = si->first;
+  for (auto& si : mapping) {
+    cmSourceFile const* sf = si.first;
     std::string objectName =
       cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
     objectName += ".o";
@@ -82,6 +78,6 @@ void cmLocalXCodeGenerator::ComputeObjectFilenames(
     if (2 == counts[objectNameLower]) {
       // TODO: emit warning about duplicate name?
     }
-    si->second = objectName;
+    si.second = objectName;
   }
 }

+ 8 - 8
Source/cmLocalXCodeGenerator.h

@@ -27,16 +27,16 @@ public:
   ///! Set cache only and recurse to false by default.
   cmLocalXCodeGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
 
-  virtual ~cmLocalXCodeGenerator();
-  virtual std::string GetTargetDirectory(
-    cmGeneratorTarget const* target) const;
-  virtual void AppendFlagEscape(std::string& flags,
-                                const std::string& rawFlag);
-  virtual void Generate();
+  ~cmLocalXCodeGenerator() override;
+  std::string GetTargetDirectory(
+    cmGeneratorTarget const* target) const override;
+  void AppendFlagEscape(std::string& flags,
+                        const std::string& rawFlag) override;
+  void Generate() override;
   virtual void GenerateInstallRules();
-  virtual void ComputeObjectFilenames(
+  void ComputeObjectFilenames(
     std::map<cmSourceFile const*, std::string>& mapping,
-    cmGeneratorTarget const* gt = nullptr);
+    cmGeneratorTarget const* gt = nullptr) override;
 
 private:
 };

+ 4 - 5
Source/cmMachO.cxx

@@ -134,7 +134,7 @@ public:
     : cmMachOHeaderAndLoadCommands(_swap)
   {
   }
-  bool read_mach_o(cmsys::ifstream& fin)
+  bool read_mach_o(cmsys::ifstream& fin) override
   {
     if (!read(fin, this->Header)) {
       return false;
@@ -251,8 +251,7 @@ cmMachOInternal::cmMachOInternal(const char* fname)
     }
 
     // parse each Mach-O file
-    for (size_t i = 0; i < this->FatArchs.size(); i++) {
-      const fat_arch& arch = this->FatArchs[i];
+    for (const auto& arch : this->FatArchs) {
       if (!this->read_mach_o(OSSwapBigToHostInt32(arch.offset))) {
         return;
       }
@@ -265,8 +264,8 @@ cmMachOInternal::cmMachOInternal(const char* fname)
 
 cmMachOInternal::~cmMachOInternal()
 {
-  for (size_t i = 0; i < this->MachOList.size(); i++) {
-    delete this->MachOList[i];
+  for (auto& i : this->MachOList) {
+    delete i;
   }
 }
 

+ 2 - 1
Source/cmServerProtocol.cxx

@@ -602,11 +602,12 @@ bool LanguageData::operator==(const LanguageData& other) const
 void LanguageData::SetDefines(const std::set<std::string>& defines)
 {
   std::vector<std::string> result;
+  result.reserve(defines.size());
   for (std::string const& i : defines) {
     result.push_back(i);
   }
   std::sort(result.begin(), result.end());
-  Defines = result;
+  Defines = std::move(result);
 }
 
 namespace std {

+ 1 - 0
Source/cmStateDirectory.cxx

@@ -442,6 +442,7 @@ const char* cmStateDirectory::GetProperty(const std::string& prop,
     std::vector<std::string> child_dirs;
     std::vector<cmStateSnapshot> const& children =
       this->DirectoryState->Children;
+    child_dirs.reserve(children.size());
     for (cmStateSnapshot const& ci : children) {
       child_dirs.push_back(ci.GetDirectory().GetCurrentSource());
     }

+ 16 - 13
Source/cmSystemTools.cxx

@@ -700,6 +700,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
                                      double timeout, Encoding encoding)
 {
   std::vector<const char*> argv;
+  argv.reserve(command.size() + 1);
   for (std::string const& cmd : command) {
     argv.push_back(cmd.c_str());
   }
@@ -2065,7 +2066,7 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
 #undef CM_EXE_PATH_LOCAL_SIZE
   char* exe_path = exe_path_local;
   if (_NSGetExecutablePath(exe_path, &exe_path_size) < 0) {
-    exe_path = (char*)malloc(exe_path_size);
+    exe_path = static_cast<char*>(malloc(exe_path_size));
     _NSGetExecutablePath(exe_path, &exe_path_size);
   }
   exe_dir =
@@ -2325,12 +2326,12 @@ struct cmSystemToolsRPathInfo
 };
 #endif
 
+#if defined(CMAKE_USE_ELF_PARSER)
 bool cmSystemTools::ChangeRPath(std::string const& file,
                                 std::string const& oldRPath,
                                 std::string const& newRPath, std::string* emsg,
                                 bool* changed)
 {
-#if defined(CMAKE_USE_ELF_PARSER)
   if (changed) {
     *changed = false;
   }
@@ -2496,15 +2497,16 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
     *changed = true;
   }
   return true;
+}
 #else
-  (void)file;
-  (void)oldRPath;
-  (void)newRPath;
-  (void)emsg;
-  (void)changed;
+bool cmSystemTools::ChangeRPath(std::string const& /*file*/,
+                                std::string const& /*oldRPath*/,
+                                std::string const& /*newRPath*/,
+                                std::string* /*emsg*/, bool* /*changed*/)
+{
   return false;
-#endif
 }
+#endif
 
 bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op,
                                    const char* lhss, const char* rhss)
@@ -2638,10 +2640,10 @@ int cmSystemTools::strverscmp(std::string const& lhs, std::string const& rhs)
   return cm_strverscmp(lhs.c_str(), rhs.c_str());
 }
 
+#if defined(CMAKE_USE_ELF_PARSER)
 bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
                                 bool* removed)
 {
-#if defined(CMAKE_USE_ELF_PARSER)
   if (removed) {
     *removed = false;
   }
@@ -2779,13 +2781,14 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
     *removed = true;
   }
   return true;
+}
 #else
-  (void)file;
-  (void)emsg;
-  (void)removed;
+bool cmSystemTools::RemoveRPath(std::string const& /*file*/,
+                                std::string* /*emsg*/, bool* /*removed*/)
+{
   return false;
-#endif
 }
+#endif
 
 bool cmSystemTools::CheckRPath(std::string const& file,
                                std::string const& newRPath)

+ 2 - 6
Source/cmXCode21Object.cxx

@@ -34,9 +34,7 @@ void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v,
                                 std::ostream& out, PBXType t)
 {
   bool hasOne = false;
-  for (std::vector<cmXCodeObject*>::const_iterator i = v.begin(); i != v.end();
-       ++i) {
-    cmXCodeObject* obj = *i;
+  for (auto obj : v) {
     if (obj->GetType() == OBJECT && obj->GetIsA() == t) {
       hasOne = true;
       break;
@@ -46,9 +44,7 @@ void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v,
     return;
   }
   out << "\n/* Begin " << PBXTypeNames[t] << " section */\n";
-  for (std::vector<cmXCodeObject*>::const_iterator i = v.begin(); i != v.end();
-       ++i) {
-    cmXCodeObject* obj = *i;
+  for (auto obj : v) {
     if (obj->GetType() == OBJECT && obj->GetIsA() == t) {
       obj->Print(out);
     }

+ 1 - 1
Source/cmXCode21Object.h

@@ -14,7 +14,7 @@ class cmXCode21Object : public cmXCodeObject
 {
 public:
   cmXCode21Object(PBXType ptype, Type type);
-  virtual void PrintComment(std::ostream&);
+  void PrintComment(std::ostream&) override;
   static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out,
                         PBXType t);
   static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out);

+ 8 - 7
Source/cmXCodeObject.cxx

@@ -120,8 +120,9 @@ void cmXCodeObject::Print(std::ostream& out)
   out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
   for (i = this->ObjectAttributes.begin(); i != this->ObjectAttributes.end();
        ++i) {
-    if (i->first == "isa")
+    if (i->first == "isa") {
       continue;
+    }
 
     PrintAttribute(out, 3, separator, indentFactor, i->first, i->second, this);
   }
@@ -129,9 +130,9 @@ void cmXCodeObject::Print(std::ostream& out)
   out << "};\n";
 }
 
-void cmXCodeObject::PrintAttribute(std::ostream& out, const int level,
-                                   const std::string separator,
-                                   const int factor, const std::string& name,
+void cmXCodeObject::PrintAttribute(std::ostream& out, int level,
+                                   const std::string& separator, int factor,
+                                   const std::string& name,
                                    const cmXCodeObject* object,
                                    const cmXCodeObject* parent)
 {
@@ -203,9 +204,9 @@ void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
 {
   cmXCodeObject::Indent(1, out);
   out << "objects = {\n";
-  for (unsigned int i = 0; i < objs.size(); ++i) {
-    if (objs[i]->TypeValue == OBJECT) {
-      objs[i]->Print(out);
+  for (auto obj : objs) {
+    if (obj->TypeValue == OBJECT) {
+      obj->Print(out);
     }
   }
   cmXCodeObject::Indent(1, out);

+ 3 - 5
Source/cmXCodeObject.h

@@ -94,8 +94,8 @@ public:
   }
   static void Indent(int level, std::ostream& out);
   void Print(std::ostream& out);
-  void PrintAttribute(std::ostream& out, const int level,
-                      const std::string separator, const int factor,
+  void PrintAttribute(std::ostream& out, int level,
+                      const std::string& separator, int factor,
                       const std::string& name, const cmXCodeObject* object,
                       const cmXCodeObject* parent);
   virtual void PrintComment(std::ostream&) {}
@@ -119,9 +119,7 @@ public:
   // search the attribute list for an object of the specified type
   cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const
   {
-    for (std::vector<cmXCodeObject*>::const_iterator i = this->List.begin();
-         i != this->List.end(); ++i) {
-      cmXCodeObject* o = *i;
+    for (auto o : this->List) {
       if (o->IsA == t) {
         return o;
       }

+ 9 - 9
Source/cmXCodeScheme.cxx

@@ -91,7 +91,7 @@ void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
 }
 
 void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
-                                    std::string configuration,
+                                    const std::string& configuration,
                                     const std::string& container)
 {
   xout.StartElement("TestAction");
@@ -104,12 +104,11 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
   xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES");
 
   xout.StartElement("Testables");
-  for (TestObjects::const_iterator it = this->Tests.begin();
-       it != this->Tests.end(); ++it) {
+  for (auto test : this->Tests) {
     xout.StartElement("TestableReference");
     xout.BreakAttributes();
     xout.Attribute("skipped", "NO");
-    WriteBuildableReference(xout, *it, container);
+    WriteBuildableReference(xout, test, container);
     xout.EndElement(); // TestableReference
   }
   xout.EndElement();
@@ -127,7 +126,7 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
 }
 
 void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
-                                      std::string configuration,
+                                      const std::string& configuration,
                                       const std::string& container)
 {
   xout.StartElement("LaunchAction");
@@ -164,7 +163,7 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
 }
 
 void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout,
-                                       std::string configuration)
+                                       const std::string& configuration)
 {
   xout.StartElement("ProfileAction");
   xout.BreakAttributes();
@@ -177,7 +176,7 @@ void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout,
 }
 
 void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout,
-                                       std::string configuration)
+                                       const std::string& configuration)
 {
   xout.StartElement("AnalyzeAction");
   xout.BreakAttributes();
@@ -186,7 +185,7 @@ void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout,
 }
 
 void cmXCodeScheme::WriteArchiveAction(cmXMLWriter& xout,
-                                       std::string configuration)
+                                       const std::string& configuration)
 {
   xout.StartElement("ArchiveAction");
   xout.BreakAttributes();
@@ -223,8 +222,9 @@ std::string cmXCodeScheme::FindConfiguration(const std::string& name)
   //
   if (std::find(this->ConfigList.begin(), this->ConfigList.end(), name) ==
         this->ConfigList.end() &&
-      this->ConfigList.size() > 0)
+      !this->ConfigList.empty()) {
     return this->ConfigList[0];
+  }
 
   return name;
 }

+ 5 - 5
Source/cmXCodeScheme.h

@@ -37,13 +37,13 @@ private:
   void WriteXCodeXCScheme(std::ostream& fout, const std::string& container);
 
   void WriteBuildAction(cmXMLWriter& xout, const std::string& container);
-  void WriteTestAction(cmXMLWriter& xout, std::string configuration,
+  void WriteTestAction(cmXMLWriter& xout, const std::string& configuration,
                        const std::string& container);
-  void WriteLaunchAction(cmXMLWriter& xout, std::string configuration,
+  void WriteLaunchAction(cmXMLWriter& xout, const std::string& configuration,
                          const std::string& container);
-  void WriteProfileAction(cmXMLWriter& xout, std::string configuration);
-  void WriteAnalyzeAction(cmXMLWriter& xout, std::string configuration);
-  void WriteArchiveAction(cmXMLWriter& xout, std::string configuration);
+  void WriteProfileAction(cmXMLWriter& xout, const std::string& configuration);
+  void WriteAnalyzeAction(cmXMLWriter& xout, const std::string& configuration);
+  void WriteArchiveAction(cmXMLWriter& xout, const std::string& configuration);
 
   void WriteBuildableReference(cmXMLWriter& xout, const cmXCodeObject* xcObj,
                                const std::string& container);

+ 1 - 0
Source/cmcmd.cxx

@@ -348,6 +348,7 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string>& args)
     std::bind(&cmcmd::HandleCppCheck, a1, a2, a3);
   // copy the command options to a vector of strings
   std::vector<std::string> commandOptions;
+  commandOptions.reserve(coCompileTypes.size());
   for (const auto& i : coCompileTypes) {
     commandOptions.push_back(i.first);
   }

+ 1 - 0
Source/ctest.cxx

@@ -186,6 +186,7 @@ int main(int argc, char const* const* argv)
 
   // copy the args to a vector
   std::vector<std::string> args;
+  args.reserve(argc);
   for (int i = 0; i < argc; ++i) {
     args.push_back(argv[i]);
   }