diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2021-01-22 15:39:02 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2021-01-27 13:54:18 (GMT) |
commit | ef935b17ab47739b1e81e9c6baf6112b7a20f9cb (patch) | |
tree | 7f31fc4bcf6efb450e67b29ba6713937515ca956 | |
parent | 9ac8dbbb941194e79fd59acfc4affa018a222745 (diff) | |
download | CMake-ef935b17ab47739b1e81e9c6baf6112b7a20f9cb.zip CMake-ef935b17ab47739b1e81e9c6baf6112b7a20f9cb.tar.gz CMake-ef935b17ab47739b1e81e9c6baf6112b7a20f9cb.tar.bz2 |
clang-tidy: fix `readability-use-anyofallof` warnings
-rw-r--r-- | .clang-tidy | 1 | ||||
-rw-r--r-- | Source/cmCMakePresetsFile.cxx | 20 | ||||
-rw-r--r-- | Source/cmFileLockPool.cxx | 8 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 29 | ||||
-rw-r--r-- | Source/cmFindProgramCommand.cxx | 65 | ||||
-rw-r--r-- | Source/cmGhsMultiTargetGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 48 | ||||
-rw-r--r-- | Source/cmInstallCommandArguments.cxx | 13 | ||||
-rw-r--r-- | Source/cmLinkLineDeviceComputer.cxx | 19 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 44 | ||||
-rw-r--r-- | Source/cmQtAutoMocUic.cxx | 62 | ||||
-rw-r--r-- | Source/cmRuntimeDependencyArchive.cxx | 11 | ||||
-rw-r--r-- | Source/cmScriptGenerator.cxx | 11 | ||||
-rw-r--r-- | Source/cmState.cxx | 9 |
14 files changed, 161 insertions, 189 deletions
diff --git a/.clang-tidy b/.clang-tidy index 068a34e..5e513fb 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -27,7 +27,6 @@ readability-*,\ -readability-named-parameter,\ -readability-redundant-declaration,\ -readability-uppercase-literal-suffix,\ --readability-use-anyofallof,\ " HeaderFilterRegex: 'Source/cm[^/]*\.(h|hxx|cxx)$' CheckOptions: diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx index cf5db6e..8762158 100644 --- a/Source/cmCMakePresetsFile.cxx +++ b/Source/cmCMakePresetsFile.cxx @@ -2,8 +2,10 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCMakePresetsFile.h" +#include <algorithm> #include <cstdlib> #include <functional> +#include <iterator> #include <utility> #include <cmext/string_view> @@ -461,22 +463,16 @@ constexpr const char* ValidPrefixes[] = { bool PrefixesValidMacroNamespace(const std::string& str) { - for (auto const& prefix : ValidPrefixes) { - if (cmHasPrefix(prefix, str)) { - return true; - } - } - return false; + return std::any_of( + std::begin(ValidPrefixes), std::end(ValidPrefixes), + [&str](const char* prefix) -> bool { return cmHasPrefix(prefix, str); }); } bool IsValidMacroNamespace(const std::string& str) { - for (auto const& prefix : ValidPrefixes) { - if (str == prefix) { - return true; - } - } - return false; + return std::any_of( + std::begin(ValidPrefixes), std::end(ValidPrefixes), + [&str](const char* prefix) -> bool { return str == prefix; }); } enum class ExpandMacroResult diff --git a/Source/cmFileLockPool.cxx b/Source/cmFileLockPool.cxx index 4ca924b..99f6885 100644 --- a/Source/cmFileLockPool.cxx +++ b/Source/cmFileLockPool.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmFileLockPool.h" +#include <algorithm> #include <cassert> #include <utility> @@ -145,7 +146,8 @@ cmFileLockResult cmFileLockPool::ScopePool::Release( bool cmFileLockPool::ScopePool::IsAlreadyLocked( const std::string& filename) const { - return std::any_of( - this->Locks.begin(), this->Locks.end(), - [&filename](auto const& lock) { return lock.IsLocked(filename); }); + return std::any_of(this->Locks.begin(), this->Locks.end(), + [&filename](cmFileLock const& lock) -> bool { + return lock.IsLocked(filename); + }); } diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 3b7cf4c..3719fe1 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1145,34 +1145,27 @@ bool cmFindPackageCommand::FindConfig() bool cmFindPackageCommand::FindPrefixedConfig() { std::vector<std::string> const& prefixes = this->SearchPaths; - for (std::string const& p : prefixes) { - if (this->SearchPrefix(p)) { - return true; - } - } - return false; + return std::any_of( + prefixes.begin(), prefixes.end(), + [this](std::string const& p) -> bool { return this->SearchPrefix(p); }); } bool cmFindPackageCommand::FindFrameworkConfig() { std::vector<std::string> const& prefixes = this->SearchPaths; - for (std::string const& p : prefixes) { - if (this->SearchFrameworkPrefix(p)) { - return true; - } - } - return false; + return std::any_of(prefixes.begin(), prefixes.end(), + [this](std::string const& p) -> bool { + return this->SearchFrameworkPrefix(p); + }); } bool cmFindPackageCommand::FindAppBundleConfig() { std::vector<std::string> const& prefixes = this->SearchPaths; - for (std::string const& p : prefixes) { - if (this->SearchAppBundlePrefix(p)) { - return true; - } - } - return false; + return std::any_of(prefixes.begin(), prefixes.end(), + [this](std::string const& p) -> bool { + return this->SearchAppBundlePrefix(p); + }); } bool cmFindPackageCommand::ReadListFile(const std::string& f, diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 5bb4234..c22462e 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -2,6 +2,9 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmFindProgramCommand.h" +#include <algorithm> +#include <string> + #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" @@ -60,44 +63,42 @@ struct cmFindProgramHelper } bool CheckCompoundNames() { - for (std::string const& n : this->Names) { - // Only perform search relative to current directory if the file name - // contains a directory separator. - if (n.find('/') != std::string::npos) { - if (this->CheckDirectoryForName("", n)) { - return true; - } - } - } - return false; + return std::any_of(this->Names.begin(), this->Names.end(), + [this](std::string const& n) -> bool { + // Only perform search relative to current directory + // if the file name contains a directory separator. + return n.find('/') != std::string::npos && + this->CheckDirectoryForName("", n); + }); } bool CheckDirectory(std::string const& path) { - for (std::string const& n : this->Names) { - if (this->CheckDirectoryForName(path, n)) { - return true; - } - } - return false; + return std::any_of(this->Names.begin(), this->Names.end(), + [this, &path](std::string const& n) -> bool { + // Only perform search relative to current directory + // if the file name contains a directory separator. + return this->CheckDirectoryForName(path, n); + }); } bool CheckDirectoryForName(std::string const& path, std::string const& name) { - for (std::string const& ext : this->Extensions) { - if (!ext.empty() && cmHasSuffix(name, ext)) { - continue; - } - this->TestNameExt = cmStrCat(name, ext); - this->TestPath = - cmSystemTools::CollapseFullPath(this->TestNameExt, path); - bool exists = this->FileIsExecutable(this->TestPath); - exists ? this->DebugSearches.FoundAt(this->TestPath) - : this->DebugSearches.FailedAt(this->TestPath); - if (exists) { - this->BestPath = this->TestPath; - return true; - } - } - return false; + return std::any_of(this->Extensions.begin(), this->Extensions.end(), + [this, &path, &name](std::string const& ext) -> bool { + if (!ext.empty() && cmHasSuffix(name, ext)) { + return false; + } + this->TestNameExt = cmStrCat(name, ext); + this->TestPath = cmSystemTools::CollapseFullPath( + this->TestNameExt, path); + bool exists = this->FileIsExecutable(this->TestPath); + exists ? this->DebugSearches.FoundAt(this->TestPath) + : this->DebugSearches.FailedAt(this->TestPath); + if (exists) { + this->BestPath = this->TestPath; + return true; + } + return false; + }); } bool FileIsExecutable(std::string const& file) const { diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 3c44a88..ed5bff5 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -726,12 +726,10 @@ bool cmGhsMultiTargetGenerator::DetermineIfIntegrityApp() } std::vector<cmSourceFile*> sources; this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName); - for (const cmSourceFile* sf : sources) { - if ("int" == sf->GetExtension()) { - return true; - } - } - return false; + return std::any_of(sources.begin(), sources.end(), + [](cmSourceFile const* sf) -> bool { + return "int" == sf->GetExtension(); + }); } bool cmGhsMultiTargetGenerator::ComputeCustomCommandOrder( diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 4f17408..7eac169 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -2675,33 +2675,35 @@ bool cmGlobalNinjaMultiGenerator::OpenBuildFileStreams() << "# This file contains build statements common to all " "configurations.\n\n"; - for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs( - cmMakefile::IncludeEmptyConfig)) { - // Open impl file. - if (!this->OpenFileStream(this->ImplFileStreams[config], - GetNinjaImplFilename(config))) { - return false; - } + auto const& configs = + this->Makefiles[0]->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + return std::all_of( + configs.begin(), configs.end(), [this](std::string const& config) -> bool { + // Open impl file. + if (!this->OpenFileStream(this->ImplFileStreams[config], + GetNinjaImplFilename(config))) { + return false; + } - // Write a comment about this file. - *this->ImplFileStreams[config] - << "# This file contains build statements specific to the \"" << config - << "\"\n# configuration.\n\n"; + // Write a comment about this file. + *this->ImplFileStreams[config] + << "# This file contains build statements specific to the \"" << config + << "\"\n# configuration.\n\n"; - // Open config file. - if (!this->OpenFileStream(this->ConfigFileStreams[config], - GetNinjaConfigFilename(config))) { - return false; - } + // Open config file. + if (!this->OpenFileStream(this->ConfigFileStreams[config], + GetNinjaConfigFilename(config))) { + return false; + } - // Write a comment about this file. - *this->ConfigFileStreams[config] - << "# This file contains aliases specific to the \"" << config - << "\"\n# configuration.\n\n" - << "include " << GetNinjaImplFilename(config) << "\n\n"; - } + // Write a comment about this file. + *this->ConfigFileStreams[config] + << "# This file contains aliases specific to the \"" << config + << "\"\n# configuration.\n\n" + << "include " << GetNinjaImplFilename(config) << "\n\n"; - return true; + return true; + }); } void cmGlobalNinjaMultiGenerator::CloseBuildFileStreams() diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx index a034689..cc3df2a 100644 --- a/Source/cmInstallCommandArguments.cxx +++ b/Source/cmInstallCommandArguments.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallCommandArguments.h" +#include <algorithm> #include <utility> #include <cmext/string_view> @@ -176,13 +177,11 @@ bool cmInstallCommandArguments::Finalize() bool cmInstallCommandArguments::CheckPermissions() { this->PermissionsString.clear(); - for (std::string const& perm : this->Permissions) { - if (!cmInstallCommandArguments::CheckPermissions( - perm, this->PermissionsString)) { - return false; - } - } - return true; + return std::all_of(this->Permissions.begin(), this->Permissions.end(), + [this](std::string const& perm) -> bool { + return cmInstallCommandArguments::CheckPermissions( + perm, this->PermissionsString); + }); } bool cmInstallCommandArguments::CheckPermissions( diff --git a/Source/cmLinkLineDeviceComputer.cxx b/Source/cmLinkLineDeviceComputer.cxx index 5739fec..9cae926 100644 --- a/Source/cmLinkLineDeviceComputer.cxx +++ b/Source/cmLinkLineDeviceComputer.cxx @@ -3,6 +3,7 @@ #include "cmLinkLineDeviceComputer.h" +#include <algorithm> #include <set> #include <utility> @@ -57,17 +58,15 @@ bool cmLinkLineDeviceComputer::ComputeRequiresDeviceLinking( using ItemVector = cmComputeLinkInformation::ItemVector; ItemVector const& items = cli.GetItems(); std::string config = cli.GetConfig(); - for (auto const& item : items) { - if (item.Target && - item.Target->GetType() == cmStateEnums::STATIC_LIBRARY) { - if ((!item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS")) && - item.Target->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) { + return std::any_of( + items.begin(), items.end(), + [](cmComputeLinkInformation::Item const& item) -> bool { + return item.Target && + item.Target->GetType() == cmStateEnums::STATIC_LIBRARY && // this dependency requires us to device link it - return true; - } - } - } - return false; + !item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS") && + item.Target->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION"); + }); } void cmLinkLineDeviceComputer::ComputeLinkLibraries( diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index bd38446..349b53b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1853,17 +1853,12 @@ bool cmLocalGenerator::AllAppleArchSysrootsAreTheSame( return false; } - for (std::string const& arch : archs) { - std::string const& archSysroot = this->AppleArchSysroots[arch]; - if (cmIsOff(archSysroot)) { - continue; - } - if (archSysroot != sysroot) { - return false; - } - } - - return true; + return std::all_of(archs.begin(), archs.end(), + [this, &sysroot](std::string const& arch) -> bool { + std::string const& archSysroot = + this->AppleArchSysroots[arch]; + return cmIsOff(archSysroot) || archSysroot == sysroot; + }); } void cmLocalGenerator::AddArchitectureFlags(std::string& flags, @@ -4039,26 +4034,23 @@ cmSourceFile* AddCustomCommand( bool AnyOutputMatches(const std::string& name, const std::vector<std::string>& outputs) { - for (std::string const& output : outputs) { - std::string::size_type pos = output.rfind(name); - // If the output matches exactly - if (pos != std::string::npos && pos == output.size() - name.size() && - (pos == 0 || output[pos - 1] == '/')) { - return true; - } - } - return false; + return std::any_of(outputs.begin(), outputs.end(), + [&name](std::string const& output) -> bool { + std::string::size_type pos = output.rfind(name); + // If the output matches exactly + return (pos != std::string::npos && + pos == output.size() - name.size() && + (pos == 0 || output[pos - 1] == '/')); + }); } bool AnyTargetCommandOutputMatches( const std::string& name, const std::vector<cmCustomCommand>& commands) { - for (cmCustomCommand const& command : commands) { - if (AnyOutputMatches(name, command.GetByproducts())) { - return true; - } - } - return false; + return std::any_of(commands.begin(), commands.end(), + [&name](cmCustomCommand const& command) -> bool { + return AnyOutputMatches(name, command.GetByproducts()); + }); } } diff --git a/Source/cmQtAutoMocUic.cxx b/Source/cmQtAutoMocUic.cxx index 48354bc..68d3c6c 100644 --- a/Source/cmQtAutoMocUic.cxx +++ b/Source/cmQtAutoMocUic.cxx @@ -1426,13 +1426,12 @@ bool cmQtAutoMocUicT::JobEvalCacheMocT::FindIncludedHeader( return true; } // Search in include directories - for (std::string const& path : this->MocConst().IncludePaths) { - if (findHeader(cmStrCat(path, '/', includeBase))) { - return true; - } - } - // Return without success - return false; + auto const& includePaths = this->MocConst().IncludePaths; + return std::any_of( + includePaths.begin(), includePaths.end(), + [&findHeader, &includeBase](std::string const& path) -> bool { + return findHeader(cmStrCat(path, '/', includeBase)); + }); } bool cmQtAutoMocUicT::JobEvalCacheMocT::RegisterIncluded( @@ -1538,31 +1537,30 @@ bool cmQtAutoMocUicT::JobEvalCacheUicT::EvalFile( } std::string const sourceDirPrefix = SubDirPrefix(sourceFile.FileName); - for (IncludeKeyT const& incKey : Include) { - // Find .ui file - this->UiName = cmStrCat(incKey.Base, ".ui"); - if (!this->FindIncludedUi(sourceDirPrefix, incKey.Dir)) { - this->LogError( - GenT::UIC, - cmStrCat(this->MessagePath(sourceFile.FileName), - "\nincludes the uic file ", this->MessagePath(incKey.Key), - ",\nbut the user interface file ", - this->MessagePath(this->UiName), - "\ncould not be found in the following directories\n", - this->MessageSearchLocations())); - return false; - } - // Check if the file is skipped - if (this->UicConst().skipped(this->UiFileHandle->FileName)) { - continue; - } - // Register mapping - if (!this->RegisterMapping(incKey.Key, sourceFileHandle)) { - return false; - } - } - - return true; + return std::all_of( + Include.begin(), Include.end(), + [this, &sourceDirPrefix, &sourceFile, + &sourceFileHandle](IncludeKeyT const& incKey) -> bool { + // Find .ui file + this->UiName = cmStrCat(incKey.Base, ".ui"); + if (!this->FindIncludedUi(sourceDirPrefix, incKey.Dir)) { + this->LogError( + GenT::UIC, + cmStrCat(this->MessagePath(sourceFile.FileName), + "\nincludes the uic file ", this->MessagePath(incKey.Key), + ",\nbut the user interface file ", + this->MessagePath(this->UiName), + "\ncould not be found in the following directories\n", + this->MessageSearchLocations())); + return false; + } + // Check if the file is skipped + if (this->UicConst().skipped(this->UiFileHandle->FileName)) { + return true; + } + // Register mapping + return this->RegisterMapping(incKey.Key, sourceFileHandle); + }); } bool cmQtAutoMocUicT::JobEvalCacheUicT::FindIncludedUi( diff --git a/Source/cmRuntimeDependencyArchive.cxx b/Source/cmRuntimeDependencyArchive.cxx index 0781d29..472f234 100644 --- a/Source/cmRuntimeDependencyArchive.cxx +++ b/Source/cmRuntimeDependencyArchive.cxx @@ -181,13 +181,10 @@ bool cmRuntimeDependencyArchive::GetRuntimeDependencies( return false; } } - for (auto const& mod : modules) { - if (!this->Linker->ScanDependencies(mod, cmStateEnums::MODULE_LIBRARY)) { - return false; - } - } - - return true; + return std::all_of( + modules.begin(), modules.end(), [this](std::string const& mod) -> bool { + return this->Linker->ScanDependencies(mod, cmStateEnums::MODULE_LIBRARY); + }); } void cmRuntimeDependencyArchive::SetError(const std::string& e) diff --git a/Source/cmScriptGenerator.cxx b/Source/cmScriptGenerator.cxx index 3f6b754..5ac7be9 100644 --- a/Source/cmScriptGenerator.cxx +++ b/Source/cmScriptGenerator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmScriptGenerator.h" +#include <algorithm> #include <utility> #include "cmStringAlgorithms.h" @@ -119,12 +120,10 @@ bool cmScriptGenerator::GeneratesForConfig(const std::string& config) // This is a configuration-specific rule. Check if the config // matches this rule. std::string config_upper = cmSystemTools::UpperCase(config); - for (std::string const& cfg : this->Configurations) { - if (cmSystemTools::UpperCase(cfg) == config_upper) { - return true; - } - } - return false; + return std::any_of(this->Configurations.begin(), this->Configurations.end(), + [&config_upper](std::string const& cfg) -> bool { + return cmSystemTools::UpperCase(cfg) == config_upper; + }); } void cmScriptGenerator::GenerateScriptActionsOnce(std::ostream& os, diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 4252022..d97762b 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -110,12 +110,9 @@ bool cmState::StringToCacheEntryType(const std::string& s, bool cmState::IsCacheEntryType(std::string const& key) { - for (const std::string& i : cmCacheEntryTypes) { - if (key == i) { - return true; - } - } - return false; + return std::any_of( + cmCacheEntryTypes.begin(), cmCacheEntryTypes.end(), + [&key](std::string const& i) -> bool { return key == i; }); } bool cmState::LoadCache(const std::string& path, bool internal, |