Commit ef935b17 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

clang-tidy: fix `readability-use-anyofallof` warnings

parent 9ac8dbbb
......@@ -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:
......
......@@ -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
......
......@@ -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);
});
}
......@@ -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,
......
......@@ -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
{
......
......@@ -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(
......
......@@ -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()
......
......@@ -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(
......
......@@ -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(
......
......@@ -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());
});
}
}
......
......@@ -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(
......
......@@ -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)
......
......@@ -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,
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment