clang-tidy: fix readability-use-anyofallof warnings

This commit is contained in:
Ben Boeckel
2021-01-22 10:39:02 -05:00
parent 9ac8dbbb94
commit ef935b17ab
14 changed files with 161 additions and 189 deletions

View File

@@ -27,7 +27,6 @@ readability-*,\
-readability-named-parameter,\ -readability-named-parameter,\
-readability-redundant-declaration,\ -readability-redundant-declaration,\
-readability-uppercase-literal-suffix,\ -readability-uppercase-literal-suffix,\
-readability-use-anyofallof,\
" "
HeaderFilterRegex: 'Source/cm[^/]*\.(h|hxx|cxx)$' HeaderFilterRegex: 'Source/cm[^/]*\.(h|hxx|cxx)$'
CheckOptions: CheckOptions:

View File

@@ -2,8 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCMakePresetsFile.h" #include "cmCMakePresetsFile.h"
#include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <functional> #include <functional>
#include <iterator>
#include <utility> #include <utility>
#include <cmext/string_view> #include <cmext/string_view>
@@ -461,22 +463,16 @@ constexpr const char* ValidPrefixes[] = {
bool PrefixesValidMacroNamespace(const std::string& str) bool PrefixesValidMacroNamespace(const std::string& str)
{ {
for (auto const& prefix : ValidPrefixes) { return std::any_of(
if (cmHasPrefix(prefix, str)) { std::begin(ValidPrefixes), std::end(ValidPrefixes),
return true; [&str](const char* prefix) -> bool { return cmHasPrefix(prefix, str); });
}
}
return false;
} }
bool IsValidMacroNamespace(const std::string& str) bool IsValidMacroNamespace(const std::string& str)
{ {
for (auto const& prefix : ValidPrefixes) { return std::any_of(
if (str == prefix) { std::begin(ValidPrefixes), std::end(ValidPrefixes),
return true; [&str](const char* prefix) -> bool { return str == prefix; });
}
}
return false;
} }
enum class ExpandMacroResult enum class ExpandMacroResult

View File

@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmFileLockPool.h" #include "cmFileLockPool.h"
#include <algorithm>
#include <cassert> #include <cassert>
#include <utility> #include <utility>
@@ -145,7 +146,8 @@ cmFileLockResult cmFileLockPool::ScopePool::Release(
bool cmFileLockPool::ScopePool::IsAlreadyLocked( bool cmFileLockPool::ScopePool::IsAlreadyLocked(
const std::string& filename) const const std::string& filename) const
{ {
return std::any_of( return std::any_of(this->Locks.begin(), this->Locks.end(),
this->Locks.begin(), this->Locks.end(), [&filename](cmFileLock const& lock) -> bool {
[&filename](auto const& lock) { return lock.IsLocked(filename); }); return lock.IsLocked(filename);
});
} }

View File

@@ -1145,34 +1145,27 @@ bool cmFindPackageCommand::FindConfig()
bool cmFindPackageCommand::FindPrefixedConfig() bool cmFindPackageCommand::FindPrefixedConfig()
{ {
std::vector<std::string> const& prefixes = this->SearchPaths; std::vector<std::string> const& prefixes = this->SearchPaths;
for (std::string const& p : prefixes) { return std::any_of(
if (this->SearchPrefix(p)) { prefixes.begin(), prefixes.end(),
return true; [this](std::string const& p) -> bool { return this->SearchPrefix(p); });
}
}
return false;
} }
bool cmFindPackageCommand::FindFrameworkConfig() bool cmFindPackageCommand::FindFrameworkConfig()
{ {
std::vector<std::string> const& prefixes = this->SearchPaths; std::vector<std::string> const& prefixes = this->SearchPaths;
for (std::string const& p : prefixes) { return std::any_of(prefixes.begin(), prefixes.end(),
if (this->SearchFrameworkPrefix(p)) { [this](std::string const& p) -> bool {
return true; return this->SearchFrameworkPrefix(p);
} });
}
return false;
} }
bool cmFindPackageCommand::FindAppBundleConfig() bool cmFindPackageCommand::FindAppBundleConfig()
{ {
std::vector<std::string> const& prefixes = this->SearchPaths; std::vector<std::string> const& prefixes = this->SearchPaths;
for (std::string const& p : prefixes) { return std::any_of(prefixes.begin(), prefixes.end(),
if (this->SearchAppBundlePrefix(p)) { [this](std::string const& p) -> bool {
return true; return this->SearchAppBundlePrefix(p);
} });
}
return false;
} }
bool cmFindPackageCommand::ReadListFile(const std::string& f, bool cmFindPackageCommand::ReadListFile(const std::string& f,

View File

@@ -2,6 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmFindProgramCommand.h" #include "cmFindProgramCommand.h"
#include <algorithm>
#include <string>
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmPolicies.h" #include "cmPolicies.h"
@@ -60,44 +63,42 @@ struct cmFindProgramHelper
} }
bool CheckCompoundNames() bool CheckCompoundNames()
{ {
for (std::string const& n : this->Names) { return std::any_of(this->Names.begin(), this->Names.end(),
// Only perform search relative to current directory if the file name [this](std::string const& n) -> bool {
// contains a directory separator. // Only perform search relative to current directory
if (n.find('/') != std::string::npos) { // if the file name contains a directory separator.
if (this->CheckDirectoryForName("", n)) { return n.find('/') != std::string::npos &&
return true; this->CheckDirectoryForName("", n);
} });
}
}
return false;
} }
bool CheckDirectory(std::string const& path) bool CheckDirectory(std::string const& path)
{ {
for (std::string const& n : this->Names) { return std::any_of(this->Names.begin(), this->Names.end(),
if (this->CheckDirectoryForName(path, n)) { [this, &path](std::string const& n) -> bool {
return true; // Only perform search relative to current directory
} // if the file name contains a directory separator.
} return this->CheckDirectoryForName(path, n);
return false; });
} }
bool CheckDirectoryForName(std::string const& path, std::string const& name) bool CheckDirectoryForName(std::string const& path, std::string const& name)
{ {
for (std::string const& ext : this->Extensions) { return std::any_of(this->Extensions.begin(), this->Extensions.end(),
if (!ext.empty() && cmHasSuffix(name, ext)) { [this, &path, &name](std::string const& ext) -> bool {
continue; if (!ext.empty() && cmHasSuffix(name, ext)) {
} return false;
this->TestNameExt = cmStrCat(name, ext); }
this->TestPath = this->TestNameExt = cmStrCat(name, ext);
cmSystemTools::CollapseFullPath(this->TestNameExt, path); this->TestPath = cmSystemTools::CollapseFullPath(
bool exists = this->FileIsExecutable(this->TestPath); this->TestNameExt, path);
exists ? this->DebugSearches.FoundAt(this->TestPath) bool exists = this->FileIsExecutable(this->TestPath);
: this->DebugSearches.FailedAt(this->TestPath); exists ? this->DebugSearches.FoundAt(this->TestPath)
if (exists) { : this->DebugSearches.FailedAt(this->TestPath);
this->BestPath = this->TestPath; if (exists) {
return true; this->BestPath = this->TestPath;
} return true;
} }
return false; return false;
});
} }
bool FileIsExecutable(std::string const& file) const bool FileIsExecutable(std::string const& file) const
{ {

View File

@@ -726,12 +726,10 @@ bool cmGhsMultiTargetGenerator::DetermineIfIntegrityApp()
} }
std::vector<cmSourceFile*> sources; std::vector<cmSourceFile*> sources;
this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName); this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName);
for (const cmSourceFile* sf : sources) { return std::any_of(sources.begin(), sources.end(),
if ("int" == sf->GetExtension()) { [](cmSourceFile const* sf) -> bool {
return true; return "int" == sf->GetExtension();
} });
}
return false;
} }
bool cmGhsMultiTargetGenerator::ComputeCustomCommandOrder( bool cmGhsMultiTargetGenerator::ComputeCustomCommandOrder(

View File

@@ -2675,33 +2675,35 @@ bool cmGlobalNinjaMultiGenerator::OpenBuildFileStreams()
<< "# This file contains build statements common to all " << "# This file contains build statements common to all "
"configurations.\n\n"; "configurations.\n\n";
for (auto const& config : this->Makefiles[0]->GetGeneratorConfigs( auto const& configs =
cmMakefile::IncludeEmptyConfig)) { this->Makefiles[0]->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
// Open impl file. return std::all_of(
if (!this->OpenFileStream(this->ImplFileStreams[config], configs.begin(), configs.end(), [this](std::string const& config) -> bool {
GetNinjaImplFilename(config))) { // Open impl file.
return false; if (!this->OpenFileStream(this->ImplFileStreams[config],
} GetNinjaImplFilename(config))) {
return false;
}
// Write a comment about this file. // Write a comment about this file.
*this->ImplFileStreams[config] *this->ImplFileStreams[config]
<< "# This file contains build statements specific to the \"" << config << "# This file contains build statements specific to the \"" << config
<< "\"\n# configuration.\n\n"; << "\"\n# configuration.\n\n";
// Open config file. // Open config file.
if (!this->OpenFileStream(this->ConfigFileStreams[config], if (!this->OpenFileStream(this->ConfigFileStreams[config],
GetNinjaConfigFilename(config))) { GetNinjaConfigFilename(config))) {
return false; return false;
} }
// Write a comment about this file. // Write a comment about this file.
*this->ConfigFileStreams[config] *this->ConfigFileStreams[config]
<< "# This file contains aliases specific to the \"" << config << "# This file contains aliases specific to the \"" << config
<< "\"\n# configuration.\n\n" << "\"\n# configuration.\n\n"
<< "include " << GetNinjaImplFilename(config) << "\n\n"; << "include " << GetNinjaImplFilename(config) << "\n\n";
}
return true; return true;
});
} }
void cmGlobalNinjaMultiGenerator::CloseBuildFileStreams() void cmGlobalNinjaMultiGenerator::CloseBuildFileStreams()

View File

@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallCommandArguments.h" #include "cmInstallCommandArguments.h"
#include <algorithm>
#include <utility> #include <utility>
#include <cmext/string_view> #include <cmext/string_view>
@@ -176,13 +177,11 @@ bool cmInstallCommandArguments::Finalize()
bool cmInstallCommandArguments::CheckPermissions() bool cmInstallCommandArguments::CheckPermissions()
{ {
this->PermissionsString.clear(); this->PermissionsString.clear();
for (std::string const& perm : this->Permissions) { return std::all_of(this->Permissions.begin(), this->Permissions.end(),
if (!cmInstallCommandArguments::CheckPermissions( [this](std::string const& perm) -> bool {
perm, this->PermissionsString)) { return cmInstallCommandArguments::CheckPermissions(
return false; perm, this->PermissionsString);
} });
}
return true;
} }
bool cmInstallCommandArguments::CheckPermissions( bool cmInstallCommandArguments::CheckPermissions(

View File

@@ -3,6 +3,7 @@
#include "cmLinkLineDeviceComputer.h" #include "cmLinkLineDeviceComputer.h"
#include <algorithm>
#include <set> #include <set>
#include <utility> #include <utility>
@@ -57,17 +58,15 @@ bool cmLinkLineDeviceComputer::ComputeRequiresDeviceLinking(
using ItemVector = cmComputeLinkInformation::ItemVector; using ItemVector = cmComputeLinkInformation::ItemVector;
ItemVector const& items = cli.GetItems(); ItemVector const& items = cli.GetItems();
std::string config = cli.GetConfig(); std::string config = cli.GetConfig();
for (auto const& item : items) { return std::any_of(
if (item.Target && items.begin(), items.end(),
item.Target->GetType() == cmStateEnums::STATIC_LIBRARY) { [](cmComputeLinkInformation::Item const& item) -> bool {
if ((!item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS")) && return item.Target &&
item.Target->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) { item.Target->GetType() == cmStateEnums::STATIC_LIBRARY &&
// this dependency requires us to device link it // this dependency requires us to device link it
return true; !item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS") &&
} item.Target->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION");
} });
}
return false;
} }
void cmLinkLineDeviceComputer::ComputeLinkLibraries( void cmLinkLineDeviceComputer::ComputeLinkLibraries(

View File

@@ -1853,17 +1853,12 @@ bool cmLocalGenerator::AllAppleArchSysrootsAreTheSame(
return false; return false;
} }
for (std::string const& arch : archs) { return std::all_of(archs.begin(), archs.end(),
std::string const& archSysroot = this->AppleArchSysroots[arch]; [this, &sysroot](std::string const& arch) -> bool {
if (cmIsOff(archSysroot)) { std::string const& archSysroot =
continue; this->AppleArchSysroots[arch];
} return cmIsOff(archSysroot) || archSysroot == sysroot;
if (archSysroot != sysroot) { });
return false;
}
}
return true;
} }
void cmLocalGenerator::AddArchitectureFlags(std::string& flags, void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
@@ -4039,26 +4034,23 @@ cmSourceFile* AddCustomCommand(
bool AnyOutputMatches(const std::string& name, bool AnyOutputMatches(const std::string& name,
const std::vector<std::string>& outputs) const std::vector<std::string>& outputs)
{ {
for (std::string const& output : outputs) { return std::any_of(outputs.begin(), outputs.end(),
std::string::size_type pos = output.rfind(name); [&name](std::string const& output) -> bool {
// If the output matches exactly std::string::size_type pos = output.rfind(name);
if (pos != std::string::npos && pos == output.size() - name.size() && // If the output matches exactly
(pos == 0 || output[pos - 1] == '/')) { return (pos != std::string::npos &&
return true; pos == output.size() - name.size() &&
} (pos == 0 || output[pos - 1] == '/'));
} });
return false;
} }
bool AnyTargetCommandOutputMatches( bool AnyTargetCommandOutputMatches(
const std::string& name, const std::vector<cmCustomCommand>& commands) const std::string& name, const std::vector<cmCustomCommand>& commands)
{ {
for (cmCustomCommand const& command : commands) { return std::any_of(commands.begin(), commands.end(),
if (AnyOutputMatches(name, command.GetByproducts())) { [&name](cmCustomCommand const& command) -> bool {
return true; return AnyOutputMatches(name, command.GetByproducts());
} });
}
return false;
} }
} }

View File

@@ -1426,13 +1426,12 @@ bool cmQtAutoMocUicT::JobEvalCacheMocT::FindIncludedHeader(
return true; return true;
} }
// Search in include directories // Search in include directories
for (std::string const& path : this->MocConst().IncludePaths) { auto const& includePaths = this->MocConst().IncludePaths;
if (findHeader(cmStrCat(path, '/', includeBase))) { return std::any_of(
return true; includePaths.begin(), includePaths.end(),
} [&findHeader, &includeBase](std::string const& path) -> bool {
} return findHeader(cmStrCat(path, '/', includeBase));
// Return without success });
return false;
} }
bool cmQtAutoMocUicT::JobEvalCacheMocT::RegisterIncluded( bool cmQtAutoMocUicT::JobEvalCacheMocT::RegisterIncluded(
@@ -1538,31 +1537,30 @@ bool cmQtAutoMocUicT::JobEvalCacheUicT::EvalFile(
} }
std::string const sourceDirPrefix = SubDirPrefix(sourceFile.FileName); std::string const sourceDirPrefix = SubDirPrefix(sourceFile.FileName);
for (IncludeKeyT const& incKey : Include) { return std::all_of(
// Find .ui file Include.begin(), Include.end(),
this->UiName = cmStrCat(incKey.Base, ".ui"); [this, &sourceDirPrefix, &sourceFile,
if (!this->FindIncludedUi(sourceDirPrefix, incKey.Dir)) { &sourceFileHandle](IncludeKeyT const& incKey) -> bool {
this->LogError( // Find .ui file
GenT::UIC, this->UiName = cmStrCat(incKey.Base, ".ui");
cmStrCat(this->MessagePath(sourceFile.FileName), if (!this->FindIncludedUi(sourceDirPrefix, incKey.Dir)) {
"\nincludes the uic file ", this->MessagePath(incKey.Key), this->LogError(
",\nbut the user interface file ", GenT::UIC,
this->MessagePath(this->UiName), cmStrCat(this->MessagePath(sourceFile.FileName),
"\ncould not be found in the following directories\n", "\nincludes the uic file ", this->MessagePath(incKey.Key),
this->MessageSearchLocations())); ",\nbut the user interface file ",
return false; this->MessagePath(this->UiName),
} "\ncould not be found in the following directories\n",
// Check if the file is skipped this->MessageSearchLocations()));
if (this->UicConst().skipped(this->UiFileHandle->FileName)) { return false;
continue; }
} // Check if the file is skipped
// Register mapping if (this->UicConst().skipped(this->UiFileHandle->FileName)) {
if (!this->RegisterMapping(incKey.Key, sourceFileHandle)) { return true;
return false; }
} // Register mapping
} return this->RegisterMapping(incKey.Key, sourceFileHandle);
});
return true;
} }
bool cmQtAutoMocUicT::JobEvalCacheUicT::FindIncludedUi( bool cmQtAutoMocUicT::JobEvalCacheUicT::FindIncludedUi(

View File

@@ -181,13 +181,10 @@ bool cmRuntimeDependencyArchive::GetRuntimeDependencies(
return false; return false;
} }
} }
for (auto const& mod : modules) { return std::all_of(
if (!this->Linker->ScanDependencies(mod, cmStateEnums::MODULE_LIBRARY)) { modules.begin(), modules.end(), [this](std::string const& mod) -> bool {
return false; return this->Linker->ScanDependencies(mod, cmStateEnums::MODULE_LIBRARY);
} });
}
return true;
} }
void cmRuntimeDependencyArchive::SetError(const std::string& e) void cmRuntimeDependencyArchive::SetError(const std::string& e)

View File

@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmScriptGenerator.h" #include "cmScriptGenerator.h"
#include <algorithm>
#include <utility> #include <utility>
#include "cmStringAlgorithms.h" #include "cmStringAlgorithms.h"
@@ -119,12 +120,10 @@ bool cmScriptGenerator::GeneratesForConfig(const std::string& config)
// This is a configuration-specific rule. Check if the config // This is a configuration-specific rule. Check if the config
// matches this rule. // matches this rule.
std::string config_upper = cmSystemTools::UpperCase(config); std::string config_upper = cmSystemTools::UpperCase(config);
for (std::string const& cfg : this->Configurations) { return std::any_of(this->Configurations.begin(), this->Configurations.end(),
if (cmSystemTools::UpperCase(cfg) == config_upper) { [&config_upper](std::string const& cfg) -> bool {
return true; return cmSystemTools::UpperCase(cfg) == config_upper;
} });
}
return false;
} }
void cmScriptGenerator::GenerateScriptActionsOnce(std::ostream& os, void cmScriptGenerator::GenerateScriptActionsOnce(std::ostream& os,

View File

@@ -110,12 +110,9 @@ bool cmState::StringToCacheEntryType(const std::string& s,
bool cmState::IsCacheEntryType(std::string const& key) bool cmState::IsCacheEntryType(std::string const& key)
{ {
for (const std::string& i : cmCacheEntryTypes) { return std::any_of(
if (key == i) { cmCacheEntryTypes.begin(), cmCacheEntryTypes.end(),
return true; [&key](std::string const& i) -> bool { return key == i; });
}
}
return false;
} }
bool cmState::LoadCache(const std::string& path, bool internal, bool cmState::LoadCache(const std::string& path, bool internal,