1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 20:46:37 +08:00

source: Pass small and trivially copyable types by value

This commit is contained in:
Daniel Pfeifer
2025-07-15 17:59:23 +02:00
committed by Brad King
parent 7829ea76ad
commit b1fdab3cc1
27 changed files with 50 additions and 54 deletions

View File

@@ -10,7 +10,6 @@ export CLAZY_CHECKS="level2\
,no-copyable-polymorphic\ ,no-copyable-polymorphic\
,no-ctor-missing-parent-argument\ ,no-ctor-missing-parent-argument\
,no-function-args-by-ref\ ,no-function-args-by-ref\
,no-function-args-by-value\
,no-missing-qobject-macro\ ,no-missing-qobject-macro\
,no-non-pod-global-static\ ,no-non-pod-global-static\
,no-old-style-connect\ ,no-old-style-connect\

View File

@@ -530,7 +530,7 @@ bool cmCTestTestHandler::ProcessOptions()
void cmCTestTestHandler::LogTestSummary(std::vector<std::string> const& passed, void cmCTestTestHandler::LogTestSummary(std::vector<std::string> const& passed,
std::vector<std::string> const& failed, std::vector<std::string> const& failed,
cmDuration const& durationInSecs) cmDuration durationInSecs)
{ {
std::size_t total = passed.size() + failed.size(); std::size_t total = passed.size() + failed.size();

View File

@@ -242,7 +242,7 @@ protected:
bool ProcessOptions(); bool ProcessOptions();
void LogTestSummary(std::vector<std::string> const& passed, void LogTestSummary(std::vector<std::string> const& passed,
std::vector<std::string> const& failed, std::vector<std::string> const& failed,
cmDuration const& durationInSecs); cmDuration durationInSecs);
void LogDisabledTests(std::vector<cmCTestTestResult> const& disabledTests); void LogDisabledTests(std::vector<cmCTestTestResult> const& disabledTests);
void LogFailedTests(std::vector<std::string> const& failed, void LogFailedTests(std::vector<std::string> const& failed,
SetOfTests const& resultsSet); SetOfTests const& resultsSet);

View File

@@ -779,7 +779,7 @@ cmComputeLinkDepends::AllocateLinkEntry(cmLinkItem const& item)
} }
std::pair<size_t, bool> cmComputeLinkDepends::AddLinkEntry( std::pair<size_t, bool> cmComputeLinkDepends::AddLinkEntry(
cmLinkItem const& item, cm::optional<size_t> const& groupIndex) cmLinkItem const& item, cm::optional<size_t> groupIndex)
{ {
// Allocate a spot for the item entry. // Allocate a spot for the item entry.
auto lei = this->AllocateLinkEntry(item); auto lei = this->AllocateLinkEntry(item);
@@ -950,7 +950,7 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
} }
void cmComputeLinkDepends::AddVarLinkEntries( void cmComputeLinkDepends::AddVarLinkEntries(
cm::optional<size_t> const& depender_index, char const* value) cm::optional<size_t> depender_index, char const* value)
{ {
// This is called to add the dependencies named by // This is called to add the dependencies named by
// <item>_LIB_DEPENDS. The variable contains a semicolon-separated // <item>_LIB_DEPENDS. The variable contains a semicolon-separated
@@ -1020,8 +1020,8 @@ void cmComputeLinkDepends::AddDirectLinkEntries()
} }
template <typename T> template <typename T>
void cmComputeLinkDepends::AddLinkEntries( void cmComputeLinkDepends::AddLinkEntries(cm::optional<size_t> depender_index,
cm::optional<size_t> const& depender_index, std::vector<T> const& libs) std::vector<T> const& libs)
{ {
// Track inferred dependency sets implied by this list. // Track inferred dependency sets implied by this list.
std::map<size_t, DependSet> dependSets; std::map<size_t, DependSet> dependSets;
@@ -1305,7 +1305,7 @@ void cmComputeLinkDepends::AddLinkObjects(std::vector<cmLinkItem> const& objs)
} }
cmLinkItem cmComputeLinkDepends::ResolveLinkItem( cmLinkItem cmComputeLinkDepends::ResolveLinkItem(
cm::optional<size_t> const& depender_index, std::string const& name) cm::optional<size_t> depender_index, std::string const& name)
{ {
// Look for a target in the scope of the depender. // Look for a target in the scope of the depender.
cmGeneratorTarget const* from = this->Target; cmGeneratorTarget const* from = this->Target;

View File

@@ -106,16 +106,16 @@ private:
std::pair<std::map<cmLinkItem, size_t>::iterator, bool> AllocateLinkEntry( std::pair<std::map<cmLinkItem, size_t>::iterator, bool> AllocateLinkEntry(
cmLinkItem const& item); cmLinkItem const& item);
std::pair<size_t, bool> AddLinkEntry(cmLinkItem const& item, std::pair<size_t, bool> AddLinkEntry(cmLinkItem const& item,
cm::optional<size_t> const& groupIndex); cm::optional<size_t> groupIndex);
void AddLinkObject(cmLinkItem const& item); void AddLinkObject(cmLinkItem const& item);
void AddVarLinkEntries(cm::optional<size_t> const& depender_index, void AddVarLinkEntries(cm::optional<size_t> depender_index,
char const* value); char const* value);
void AddDirectLinkEntries(); void AddDirectLinkEntries();
template <typename T> template <typename T>
void AddLinkEntries(cm::optional<size_t> const& depender_index, void AddLinkEntries(cm::optional<size_t> depender_index,
std::vector<T> const& libs); std::vector<T> const& libs);
void AddLinkObjects(std::vector<cmLinkItem> const& objs); void AddLinkObjects(std::vector<cmLinkItem> const& objs);
cmLinkItem ResolveLinkItem(cm::optional<size_t> const& depender_index, cmLinkItem ResolveLinkItem(cm::optional<size_t> depender_index,
std::string const& name); std::string const& name);
// One entry for each unique item. // One entry for each unique item.

View File

@@ -394,7 +394,7 @@ void cmDebuggerAdapter::OnBeginFunctionCall(cmMakefile* mf,
dap::array<dap::integer> hitBreakpoints; dap::array<dap::integer> hitBreakpoints;
hitBreakpoints.resize(hits.size()); hitBreakpoints.resize(hits.size());
std::transform(hits.begin(), hits.end(), hitBreakpoints.begin(), std::transform(hits.begin(), hits.end(), hitBreakpoints.begin(),
[&](int64_t const& id) { return dap::integer(id); }); [&](int64_t id) { return dap::integer(id); });
stoppedEvent.reason = "breakpoint"; stoppedEvent.reason = "breakpoint";
stoppedEvent.hitBreakpointIds = hitBreakpoints; stoppedEvent.hitBreakpointIds = hitBreakpoints;
} }

View File

@@ -33,7 +33,7 @@ int64_t cmDebuggerBreakpointManager::FindFunctionStartLine(
auto location = auto location =
find_if(ListFileFunctionLines[sourcePath].begin(), find_if(ListFileFunctionLines[sourcePath].begin(),
ListFileFunctionLines[sourcePath].end(), ListFileFunctionLines[sourcePath].end(),
[=](cmDebuggerFunctionLocation const& loc) { [=](cmDebuggerFunctionLocation loc) {
return loc.StartLine <= line && loc.EndLine >= line; return loc.StartLine <= line && loc.EndLine >= line;
}); });
@@ -47,11 +47,10 @@ int64_t cmDebuggerBreakpointManager::FindFunctionStartLine(
int64_t cmDebuggerBreakpointManager::CalibrateBreakpointLine( int64_t cmDebuggerBreakpointManager::CalibrateBreakpointLine(
std::string const& sourcePath, int64_t line) std::string const& sourcePath, int64_t line)
{ {
auto location = find_if(ListFileFunctionLines[sourcePath].begin(), auto location = find_if(
ListFileFunctionLines[sourcePath].end(), ListFileFunctionLines[sourcePath].begin(),
[=](cmDebuggerFunctionLocation const& loc) { ListFileFunctionLines[sourcePath].end(),
return loc.StartLine >= line; [=](cmDebuggerFunctionLocation loc) { return loc.StartLine >= line; });
});
if (location != ListFileFunctionLines[sourcePath].end()) { if (location != ListFileFunctionLines[sourcePath].end()) {
return location->StartLine; return location->StartLine;

View File

@@ -4,7 +4,7 @@
#include "cmDuration.h" #include "cmDuration.h"
template <typename T> template <typename T>
T cmDurationTo(cmDuration const& duration) T cmDurationTo(cmDuration duration)
{ {
/* This works because the comparison operators for duration rely on /* This works because the comparison operators for duration rely on
* std::common_type. * std::common_type.
@@ -23,5 +23,5 @@ T cmDurationTo(cmDuration const& duration)
.count(); .count();
} }
template int cmDurationTo<int>(cmDuration const&); template int cmDurationTo<int>(cmDuration);
template unsigned int cmDurationTo<unsigned int>(cmDuration const&); template unsigned int cmDurationTo<unsigned int>(cmDuration);

View File

@@ -16,9 +16,9 @@ using cmDuration = std::chrono::duration<double, std::ratio<1>>;
* the permissible valid values for T. * the permissible valid values for T.
*/ */
template <typename T> template <typename T>
T cmDurationTo(cmDuration const& duration); T cmDurationTo(cmDuration duration);
#ifndef CMDURATION_CPP #ifndef CMDURATION_CPP
extern template int cmDurationTo<int>(cmDuration const&); extern template int cmDurationTo<int>(cmDuration);
extern template unsigned int cmDurationTo<unsigned int>(cmDuration const&); extern template unsigned int cmDurationTo<unsigned int>(cmDuration);
#endif #endif

View File

@@ -3848,7 +3848,7 @@ bool ValidateAndConvertPermissions(
return true; return true;
} }
bool SetPermissions(std::string const& filename, mode_t const& perms, bool SetPermissions(std::string const& filename, mode_t perms,
cmExecutionStatus& status) cmExecutionStatus& status)
{ {
if (!cmSystemTools::SetPermissions(filename, perms)) { if (!cmSystemTools::SetPermissions(filename, perms)) {
@@ -3953,8 +3953,7 @@ bool HandleChmodCommandImpl(std::vector<std::string> const& args, bool recurse,
if (cmSystemTools::FileExists(i, true)) { if (cmSystemTools::FileExists(i, true)) {
bool success = true; bool success = true;
mode_t const& filePermissions = mode_t filePermissions = parsedArgs.FilePermissions ? fperms : perms;
parsedArgs.FilePermissions ? fperms : perms;
if (filePermissions) { if (filePermissions) {
success = SetPermissions(i, filePermissions, status); success = SetPermissions(i, filePermissions, status);
} }
@@ -3965,7 +3964,7 @@ bool HandleChmodCommandImpl(std::vector<std::string> const& args, bool recurse,
else if (cmSystemTools::FileIsDirectory(i)) { else if (cmSystemTools::FileIsDirectory(i)) {
bool success = true; bool success = true;
mode_t const& directoryPermissions = mode_t directoryPermissions =
parsedArgs.DirectoryPermissions ? dperms : perms; parsedArgs.DirectoryPermissions ? dperms : perms;
if (directoryPermissions) { if (directoryPermissions) {
success = SetPermissions(i, directoryPermissions, status); success = SetPermissions(i, directoryPermissions, status);

View File

@@ -702,7 +702,7 @@ bool CheckPathParametersEx(cmGeneratorExpressionContext* ctx,
} }
bool CheckPathParameters(cmGeneratorExpressionContext* ctx, bool CheckPathParameters(cmGeneratorExpressionContext* ctx,
GeneratorExpressionContent const* cnt, GeneratorExpressionContent const* cnt,
cm::string_view option, Arguments const& args, cm::string_view option, Arguments args,
int required = 1) int required = 1)
{ {
return CheckPathParametersEx(ctx, cnt, option, args.size(), required); return CheckPathParametersEx(ctx, cnt, option, args.size(), required);
@@ -1190,7 +1190,7 @@ inline bool CheckListParametersEx(cmGeneratorExpressionContext* ctx,
} }
inline bool CheckListParameters(cmGeneratorExpressionContext* ctx, inline bool CheckListParameters(cmGeneratorExpressionContext* ctx,
GeneratorExpressionContent const* cnt, GeneratorExpressionContent const* cnt,
cm::string_view option, Arguments const& args, cm::string_view option, Arguments args,
int required = 1) int required = 1)
{ {
return CheckListParametersEx(ctx, cnt, option, args.size(), required); return CheckListParametersEx(ctx, cnt, option, args.size(), required);
@@ -1225,7 +1225,7 @@ bool GetNumericArgument(std::string const& arg, cmList::index_type& value)
bool GetNumericArguments( bool GetNumericArguments(
cmGeneratorExpressionContext* ctx, GeneratorExpressionContent const* cnt, cmGeneratorExpressionContext* ctx, GeneratorExpressionContent const* cnt,
Arguments const& args, std::vector<cmList::index_type>& indexes, Arguments args, std::vector<cmList::index_type>& indexes,
cmList::ExpandElements expandElements = cmList::ExpandElements::No) cmList::ExpandElements expandElements = cmList::ExpandElements::No)
{ {
using IndexRange = cmRange<Arguments::const_iterator>; using IndexRange = cmRange<Arguments::const_iterator>;

View File

@@ -134,7 +134,7 @@ protected:
} }
public: public:
StringSorter(cmList::SortConfiguration const& config) StringSorter(cmList::SortConfiguration config)
: Filters{ this->GetCompareFilter(config.Compare), : Filters{ this->GetCompareFilter(config.Compare),
this->GetCaseFilter(config.Case) } this->GetCaseFilter(config.Case) }
, SortMethod(this->GetComparisonFunction(config.Compare)) , SortMethod(this->GetComparisonFunction(config.Compare))
@@ -175,7 +175,7 @@ private:
cmList::SortConfiguration::SortConfiguration() = default; cmList::SortConfiguration::SortConfiguration() = default;
cmList& cmList::sort(SortConfiguration const& cfg) cmList& cmList::sort(SortConfiguration cfg)
{ {
SortConfiguration config{ cfg }; SortConfiguration config{ cfg };
@@ -910,7 +910,7 @@ cmList& cmList::RemoveItems(std::vector<index_type>&& indexes)
// compute all indexes // compute all indexes
std::vector<size_type> idx(indexes.size()); std::vector<size_type> idx(indexes.size());
std::transform(indexes.cbegin(), indexes.cend(), idx.begin(), std::transform(indexes.cbegin(), indexes.cend(), idx.begin(),
[this](index_type const& index) -> size_type { [this](index_type index) -> size_type {
return this->ComputeIndex(index); return this->ComputeIndex(index);
}); });

View File

@@ -863,7 +863,7 @@ public:
{ {
} }
}; };
cmList& sort(SortConfiguration const& config = SortConfiguration{}); cmList& sort(SortConfiguration config = SortConfiguration{});
// exception raised on error during transform operations // exception raised on error during transform operations
class transform_error : public std::runtime_error class transform_error : public std::runtime_error

View File

@@ -58,7 +58,7 @@ void cmOSXBundleGenerator::CreateAppBundle(std::string const& targetName,
void cmOSXBundleGenerator::CreateFramework( void cmOSXBundleGenerator::CreateFramework(
std::string const& targetName, std::string const& outpath, std::string const& targetName, std::string const& outpath,
std::string const& config, cmOSXBundleGenerator::SkipParts const& skipParts) std::string const& config, cmOSXBundleGenerator::SkipParts skipParts)
{ {
if (this->MustSkip()) { if (this->MustSkip()) {
return; return;

View File

@@ -34,7 +34,7 @@ public:
// create a framework at a given root // create a framework at a given root
void CreateFramework(std::string const& targetName, std::string const& root, void CreateFramework(std::string const& targetName, std::string const& root,
std::string const& config, std::string const& config,
SkipParts const& skipParts = SkipParts{}); SkipParts skipParts = SkipParts{});
// create a cf bundle at a given root // create a cf bundle at a given root
void CreateCFBundle(std::string const& targetName, std::string const& root, void CreateCFBundle(std::string const& targetName, std::string const& root,

View File

@@ -180,7 +180,7 @@ std::string DeterminePrefix(std::string const& filepath,
} }
// Extract key name from value iterator as string_view. // Extract key name from value iterator as string_view.
cm::string_view IterKey(Json::Value::const_iterator const& iter) cm::string_view IterKey(Json::Value::const_iterator iter)
{ {
char const* end; char const* end;
char const* const start = iter.memberName(&end); char const* const start = iter.memberName(&end);

View File

@@ -325,8 +325,8 @@ cmQtAutoGen::ConfigStrings<std::vector<std::string>> generateListOptions(
cmQtAutoGenInitializer::cmQtAutoGenInitializer( cmQtAutoGenInitializer::cmQtAutoGenInitializer(
cmQtAutoGenGlobalInitializer* globalInitializer, cmQtAutoGenGlobalInitializer* globalInitializer,
cmGeneratorTarget* genTarget, IntegerVersion const& qtVersion, cmGeneratorTarget* genTarget, IntegerVersion qtVersion, bool mocEnabled,
bool mocEnabled, bool uicEnabled, bool rccEnabled, bool globalAutogenTarget, bool uicEnabled, bool rccEnabled, bool globalAutogenTarget,
bool globalAutoRccTarget) bool globalAutoRccTarget)
: GlobalInitializer(globalInitializer) : GlobalInitializer(globalInitializer)
, GenTarget(genTarget) , GenTarget(genTarget)

View File

@@ -93,7 +93,7 @@ public:
cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer, cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
cmGeneratorTarget* genTarget, cmGeneratorTarget* genTarget,
IntegerVersion const& qtVersion, bool mocEnabled, IntegerVersion qtVersion, bool mocEnabled,
bool uicEnabled, bool rccEnabled, bool uicEnabled, bool rccEnabled,
bool globalAutogenTarget, bool globalAutoRccTarget); bool globalAutogenTarget, bool globalAutoRccTarget);

View File

@@ -37,7 +37,7 @@ bool cmSetSourceFilesPropertiesCommand(std::vector<std::string> const& args,
}; };
auto isAPropertyKeyword = auto isAPropertyKeyword =
[](std::vector<std::string>::const_iterator const& arg_it) { [](std::vector<std::string>::const_iterator arg_it) {
return std::any_of( return std::any_of(
std::begin(prop_names), std::end(prop_names), std::begin(prop_names), std::end(prop_names),
[&arg_it](cm::string_view prop_name) { return *arg_it == prop_name; }); [&arg_it](cm::string_view prop_name) { return *arg_it == prop_name; });

View File

@@ -14,7 +14,7 @@ public:
{ {
} }
size_t Index() const { return index_; } size_t Index() const { return index_; }
friend bool operator<(cmStandardLevel const& l, cmStandardLevel const& r) friend bool operator<(cmStandardLevel l, cmStandardLevel r)
{ {
return l.index_ < r.index_; return l.index_ < r.index_;
} }

View File

@@ -542,7 +542,7 @@ std::string cmStandardLevelResolver::GetEffectiveStandard(
} }
std::string cmStandardLevelResolver::GetLevelString( std::string cmStandardLevelResolver::GetLevelString(
std::string const& lang, cmStandardLevel const& level) const std::string const& lang, cmStandardLevel level) const
{ {
auto mapping = StandardComputerMapping.find(lang); auto mapping = StandardComputerMapping.find(lang);
if (mapping == StandardComputerMapping.end()) { if (mapping == StandardComputerMapping.end()) {

View File

@@ -30,7 +30,7 @@ public:
std::string const& config) const; std::string const& config) const;
std::string GetLevelString(std::string const& lang, std::string GetLevelString(std::string const& lang,
cmStandardLevel const& level) const; cmStandardLevel level) const;
bool AddRequiredTargetFeature(cmTarget* target, std::string const& feature, bool AddRequiredTargetFeature(cmTarget* target, std::string const& feature,
std::string* error = nullptr) const; std::string* error = nullptr) const;

View File

@@ -524,7 +524,7 @@ namespace std {
template <> template <>
struct hash<cmWindowsRegistry::View> struct hash<cmWindowsRegistry::View>
{ {
size_t operator()(cmWindowsRegistry::View const& v) const noexcept size_t operator()(cmWindowsRegistry::View v) const noexcept
{ {
return static_cast< return static_cast<
typename underlying_type<cmWindowsRegistry::View>::type>(v); typename underlying_type<cmWindowsRegistry::View>::type>(v);

View File

@@ -108,8 +108,7 @@ private:
* Therefore we must assume it is an arbitrary point in time. Instead of this * Therefore we must assume it is an arbitrary point in time. Instead of this
* method, it is recommended to convert it by means of the to_time_t method. * method, it is recommended to convert it by means of the to_time_t method.
*/ */
static std::time_t SafeContent( static std::time_t SafeContent(std::chrono::system_clock::time_point value)
std::chrono::system_clock::time_point const& value)
{ {
return std::chrono::system_clock::to_time_t(value); return std::chrono::system_clock::to_time_t(value);
} }

View File

@@ -455,8 +455,8 @@ void cmake::CleanupCommandsAndMacros()
#ifndef CMAKE_BOOTSTRAP #ifndef CMAKE_BOOTSTRAP
void cmake::SetWarningFromPreset(std::string const& name, void cmake::SetWarningFromPreset(std::string const& name,
cm::optional<bool> const& warning, cm::optional<bool> warning,
cm::optional<bool> const& error) cm::optional<bool> error)
{ {
if (warning) { if (warning) {
if (*warning) { if (*warning) {

View File

@@ -388,8 +388,8 @@ public:
#ifndef CMAKE_BOOTSTRAP #ifndef CMAKE_BOOTSTRAP
void SetWarningFromPreset(std::string const& name, void SetWarningFromPreset(std::string const& name,
cm::optional<bool> const& warning, cm::optional<bool> warning,
cm::optional<bool> const& error); cm::optional<bool> error);
void ProcessPresetVariables(); void ProcessPresetVariables();
void PrintPresetVariables(); void PrintPresetVariables();
void ProcessPresetEnvironment(); void ProcessPresetEnvironment();

View File

@@ -29,7 +29,7 @@
namespace { namespace {
inline int runTests(std::initializer_list<std::function<bool()>> const& tests, inline int runTests(std::initializer_list<std::function<bool()>> tests,
bool const fail_fast = true) bool const fail_fast = true)
{ {
int result = 0; int result = 0;