From b1fdab3cc18ced1a9eef7dbd4000b5ecbfa7d77a Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Tue, 15 Jul 2025 17:59:23 +0200 Subject: [PATCH] source: Pass small and trivially copyable types by value --- .gitlab/ci/env_fedora42_clazy.sh | 1 - Source/CTest/cmCTestTestHandler.cxx | 2 +- Source/CTest/cmCTestTestHandler.h | 2 +- Source/cmComputeLinkDepends.cxx | 10 +++++----- Source/cmComputeLinkDepends.h | 8 ++++---- Source/cmDebuggerAdapter.cxx | 2 +- Source/cmDebuggerBreakpointManager.cxx | 11 +++++------ Source/cmDuration.cxx | 6 +++--- Source/cmDuration.h | 6 +++--- Source/cmFileCommand.cxx | 7 +++---- Source/cmGeneratorExpressionNode.cxx | 6 +++--- Source/cmList.cxx | 6 +++--- Source/cmList.h | 2 +- Source/cmOSXBundleGenerator.cxx | 2 +- Source/cmOSXBundleGenerator.h | 2 +- Source/cmPackageInfoReader.cxx | 2 +- Source/cmQtAutoGenInitializer.cxx | 4 ++-- Source/cmQtAutoGenInitializer.h | 2 +- Source/cmSetSourceFilesPropertiesCommand.cxx | 2 +- Source/cmStandardLevel.h | 2 +- Source/cmStandardLevelResolver.cxx | 2 +- Source/cmStandardLevelResolver.h | 2 +- Source/cmWindowsRegistry.cxx | 2 +- Source/cmXMLWriter.h | 3 +-- Source/cmake.cxx | 4 ++-- Source/cmake.h | 4 ++-- Tests/CMakeLib/testCommon.h | 2 +- 27 files changed, 50 insertions(+), 54 deletions(-) diff --git a/.gitlab/ci/env_fedora42_clazy.sh b/.gitlab/ci/env_fedora42_clazy.sh index 8df878e220..007c52d47c 100644 --- a/.gitlab/ci/env_fedora42_clazy.sh +++ b/.gitlab/ci/env_fedora42_clazy.sh @@ -10,7 +10,6 @@ export CLAZY_CHECKS="level2\ ,no-copyable-polymorphic\ ,no-ctor-missing-parent-argument\ ,no-function-args-by-ref\ -,no-function-args-by-value\ ,no-missing-qobject-macro\ ,no-non-pod-global-static\ ,no-old-style-connect\ diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index a39cb7bcbc..0c64f3f82a 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -530,7 +530,7 @@ bool cmCTestTestHandler::ProcessOptions() void cmCTestTestHandler::LogTestSummary(std::vector const& passed, std::vector const& failed, - cmDuration const& durationInSecs) + cmDuration durationInSecs) { std::size_t total = passed.size() + failed.size(); diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 9388425db9..83aae981e1 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -242,7 +242,7 @@ protected: bool ProcessOptions(); void LogTestSummary(std::vector const& passed, std::vector const& failed, - cmDuration const& durationInSecs); + cmDuration durationInSecs); void LogDisabledTests(std::vector const& disabledTests); void LogFailedTests(std::vector const& failed, SetOfTests const& resultsSet); diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index ed23958f16..1d3f93340a 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -779,7 +779,7 @@ cmComputeLinkDepends::AllocateLinkEntry(cmLinkItem const& item) } std::pair cmComputeLinkDepends::AddLinkEntry( - cmLinkItem const& item, cm::optional const& groupIndex) + cmLinkItem const& item, cm::optional groupIndex) { // Allocate a spot for the item entry. auto lei = this->AllocateLinkEntry(item); @@ -950,7 +950,7 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep) } void cmComputeLinkDepends::AddVarLinkEntries( - cm::optional const& depender_index, char const* value) + cm::optional depender_index, char const* value) { // This is called to add the dependencies named by // _LIB_DEPENDS. The variable contains a semicolon-separated @@ -1020,8 +1020,8 @@ void cmComputeLinkDepends::AddDirectLinkEntries() } template -void cmComputeLinkDepends::AddLinkEntries( - cm::optional const& depender_index, std::vector const& libs) +void cmComputeLinkDepends::AddLinkEntries(cm::optional depender_index, + std::vector const& libs) { // Track inferred dependency sets implied by this list. std::map dependSets; @@ -1305,7 +1305,7 @@ void cmComputeLinkDepends::AddLinkObjects(std::vector const& objs) } cmLinkItem cmComputeLinkDepends::ResolveLinkItem( - cm::optional const& depender_index, std::string const& name) + cm::optional depender_index, std::string const& name) { // Look for a target in the scope of the depender. cmGeneratorTarget const* from = this->Target; diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index a82db2b693..0724561d70 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -106,16 +106,16 @@ private: std::pair::iterator, bool> AllocateLinkEntry( cmLinkItem const& item); std::pair AddLinkEntry(cmLinkItem const& item, - cm::optional const& groupIndex); + cm::optional groupIndex); void AddLinkObject(cmLinkItem const& item); - void AddVarLinkEntries(cm::optional const& depender_index, + void AddVarLinkEntries(cm::optional depender_index, char const* value); void AddDirectLinkEntries(); template - void AddLinkEntries(cm::optional const& depender_index, + void AddLinkEntries(cm::optional depender_index, std::vector const& libs); void AddLinkObjects(std::vector const& objs); - cmLinkItem ResolveLinkItem(cm::optional const& depender_index, + cmLinkItem ResolveLinkItem(cm::optional depender_index, std::string const& name); // One entry for each unique item. diff --git a/Source/cmDebuggerAdapter.cxx b/Source/cmDebuggerAdapter.cxx index 832897622f..7cf9efe45b 100644 --- a/Source/cmDebuggerAdapter.cxx +++ b/Source/cmDebuggerAdapter.cxx @@ -394,7 +394,7 @@ void cmDebuggerAdapter::OnBeginFunctionCall(cmMakefile* mf, dap::array hitBreakpoints; hitBreakpoints.resize(hits.size()); 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.hitBreakpointIds = hitBreakpoints; } diff --git a/Source/cmDebuggerBreakpointManager.cxx b/Source/cmDebuggerBreakpointManager.cxx index dfd131c825..b33985b408 100644 --- a/Source/cmDebuggerBreakpointManager.cxx +++ b/Source/cmDebuggerBreakpointManager.cxx @@ -33,7 +33,7 @@ int64_t cmDebuggerBreakpointManager::FindFunctionStartLine( auto location = find_if(ListFileFunctionLines[sourcePath].begin(), ListFileFunctionLines[sourcePath].end(), - [=](cmDebuggerFunctionLocation const& loc) { + [=](cmDebuggerFunctionLocation loc) { return loc.StartLine <= line && loc.EndLine >= line; }); @@ -47,11 +47,10 @@ int64_t cmDebuggerBreakpointManager::FindFunctionStartLine( int64_t cmDebuggerBreakpointManager::CalibrateBreakpointLine( std::string const& sourcePath, int64_t line) { - auto location = find_if(ListFileFunctionLines[sourcePath].begin(), - ListFileFunctionLines[sourcePath].end(), - [=](cmDebuggerFunctionLocation const& loc) { - return loc.StartLine >= line; - }); + auto location = find_if( + ListFileFunctionLines[sourcePath].begin(), + ListFileFunctionLines[sourcePath].end(), + [=](cmDebuggerFunctionLocation loc) { return loc.StartLine >= line; }); if (location != ListFileFunctionLines[sourcePath].end()) { return location->StartLine; diff --git a/Source/cmDuration.cxx b/Source/cmDuration.cxx index b017d0a511..7981e777f9 100644 --- a/Source/cmDuration.cxx +++ b/Source/cmDuration.cxx @@ -4,7 +4,7 @@ #include "cmDuration.h" template -T cmDurationTo(cmDuration const& duration) +T cmDurationTo(cmDuration duration) { /* This works because the comparison operators for duration rely on * std::common_type. @@ -23,5 +23,5 @@ T cmDurationTo(cmDuration const& duration) .count(); } -template int cmDurationTo(cmDuration const&); -template unsigned int cmDurationTo(cmDuration const&); +template int cmDurationTo(cmDuration); +template unsigned int cmDurationTo(cmDuration); diff --git a/Source/cmDuration.h b/Source/cmDuration.h index c0268f99c0..378af9c6f5 100644 --- a/Source/cmDuration.h +++ b/Source/cmDuration.h @@ -16,9 +16,9 @@ using cmDuration = std::chrono::duration>; * the permissible valid values for T. */ template -T cmDurationTo(cmDuration const& duration); +T cmDurationTo(cmDuration duration); #ifndef CMDURATION_CPP -extern template int cmDurationTo(cmDuration const&); -extern template unsigned int cmDurationTo(cmDuration const&); +extern template int cmDurationTo(cmDuration); +extern template unsigned int cmDurationTo(cmDuration); #endif diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 88f9f0c03e..057b3fa0ec 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -3848,7 +3848,7 @@ bool ValidateAndConvertPermissions( return true; } -bool SetPermissions(std::string const& filename, mode_t const& perms, +bool SetPermissions(std::string const& filename, mode_t perms, cmExecutionStatus& status) { if (!cmSystemTools::SetPermissions(filename, perms)) { @@ -3953,8 +3953,7 @@ bool HandleChmodCommandImpl(std::vector const& args, bool recurse, if (cmSystemTools::FileExists(i, true)) { bool success = true; - mode_t const& filePermissions = - parsedArgs.FilePermissions ? fperms : perms; + mode_t filePermissions = parsedArgs.FilePermissions ? fperms : perms; if (filePermissions) { success = SetPermissions(i, filePermissions, status); } @@ -3965,7 +3964,7 @@ bool HandleChmodCommandImpl(std::vector const& args, bool recurse, else if (cmSystemTools::FileIsDirectory(i)) { bool success = true; - mode_t const& directoryPermissions = + mode_t directoryPermissions = parsedArgs.DirectoryPermissions ? dperms : perms; if (directoryPermissions) { success = SetPermissions(i, directoryPermissions, status); diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 3c2e7ec759..0126f666f2 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -702,7 +702,7 @@ bool CheckPathParametersEx(cmGeneratorExpressionContext* ctx, } bool CheckPathParameters(cmGeneratorExpressionContext* ctx, GeneratorExpressionContent const* cnt, - cm::string_view option, Arguments const& args, + cm::string_view option, Arguments args, int required = 1) { return CheckPathParametersEx(ctx, cnt, option, args.size(), required); @@ -1190,7 +1190,7 @@ inline bool CheckListParametersEx(cmGeneratorExpressionContext* ctx, } inline bool CheckListParameters(cmGeneratorExpressionContext* ctx, GeneratorExpressionContent const* cnt, - cm::string_view option, Arguments const& args, + cm::string_view option, Arguments args, int required = 1) { return CheckListParametersEx(ctx, cnt, option, args.size(), required); @@ -1225,7 +1225,7 @@ bool GetNumericArgument(std::string const& arg, cmList::index_type& value) bool GetNumericArguments( cmGeneratorExpressionContext* ctx, GeneratorExpressionContent const* cnt, - Arguments const& args, std::vector& indexes, + Arguments args, std::vector& indexes, cmList::ExpandElements expandElements = cmList::ExpandElements::No) { using IndexRange = cmRange; diff --git a/Source/cmList.cxx b/Source/cmList.cxx index 77b791679d..90874575a4 100644 --- a/Source/cmList.cxx +++ b/Source/cmList.cxx @@ -134,7 +134,7 @@ protected: } public: - StringSorter(cmList::SortConfiguration const& config) + StringSorter(cmList::SortConfiguration config) : Filters{ this->GetCompareFilter(config.Compare), this->GetCaseFilter(config.Case) } , SortMethod(this->GetComparisonFunction(config.Compare)) @@ -175,7 +175,7 @@ private: cmList::SortConfiguration::SortConfiguration() = default; -cmList& cmList::sort(SortConfiguration const& cfg) +cmList& cmList::sort(SortConfiguration cfg) { SortConfiguration config{ cfg }; @@ -910,7 +910,7 @@ cmList& cmList::RemoveItems(std::vector&& indexes) // compute all indexes std::vector idx(indexes.size()); 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); }); diff --git a/Source/cmList.h b/Source/cmList.h index c355910bd3..41b401bae7 100644 --- a/Source/cmList.h +++ b/Source/cmList.h @@ -863,7 +863,7 @@ public: { } }; - cmList& sort(SortConfiguration const& config = SortConfiguration{}); + cmList& sort(SortConfiguration config = SortConfiguration{}); // exception raised on error during transform operations class transform_error : public std::runtime_error diff --git a/Source/cmOSXBundleGenerator.cxx b/Source/cmOSXBundleGenerator.cxx index e25da96a2b..118b833253 100644 --- a/Source/cmOSXBundleGenerator.cxx +++ b/Source/cmOSXBundleGenerator.cxx @@ -58,7 +58,7 @@ void cmOSXBundleGenerator::CreateAppBundle(std::string const& targetName, void cmOSXBundleGenerator::CreateFramework( 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()) { return; diff --git a/Source/cmOSXBundleGenerator.h b/Source/cmOSXBundleGenerator.h index bfd9aec5e3..153cbccade 100644 --- a/Source/cmOSXBundleGenerator.h +++ b/Source/cmOSXBundleGenerator.h @@ -34,7 +34,7 @@ public: // create a framework at a given root void CreateFramework(std::string const& targetName, std::string const& root, std::string const& config, - SkipParts const& skipParts = SkipParts{}); + SkipParts skipParts = SkipParts{}); // create a cf bundle at a given root void CreateCFBundle(std::string const& targetName, std::string const& root, diff --git a/Source/cmPackageInfoReader.cxx b/Source/cmPackageInfoReader.cxx index 0def09d03f..b684897dae 100644 --- a/Source/cmPackageInfoReader.cxx +++ b/Source/cmPackageInfoReader.cxx @@ -180,7 +180,7 @@ std::string DeterminePrefix(std::string const& filepath, } // 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* const start = iter.memberName(&end); diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index f5797c08d3..6930eb96e8 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -325,8 +325,8 @@ cmQtAutoGen::ConfigStrings> generateListOptions( cmQtAutoGenInitializer::cmQtAutoGenInitializer( cmQtAutoGenGlobalInitializer* globalInitializer, - cmGeneratorTarget* genTarget, IntegerVersion const& qtVersion, - bool mocEnabled, bool uicEnabled, bool rccEnabled, bool globalAutogenTarget, + cmGeneratorTarget* genTarget, IntegerVersion qtVersion, bool mocEnabled, + bool uicEnabled, bool rccEnabled, bool globalAutogenTarget, bool globalAutoRccTarget) : GlobalInitializer(globalInitializer) , GenTarget(genTarget) diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index 09015fe834..afb3bfa7eb 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -93,7 +93,7 @@ public: cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer, cmGeneratorTarget* genTarget, - IntegerVersion const& qtVersion, bool mocEnabled, + IntegerVersion qtVersion, bool mocEnabled, bool uicEnabled, bool rccEnabled, bool globalAutogenTarget, bool globalAutoRccTarget); diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx index 98911c0bad..769efea425 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.cxx +++ b/Source/cmSetSourceFilesPropertiesCommand.cxx @@ -37,7 +37,7 @@ bool cmSetSourceFilesPropertiesCommand(std::vector const& args, }; auto isAPropertyKeyword = - [](std::vector::const_iterator const& arg_it) { + [](std::vector::const_iterator arg_it) { return std::any_of( std::begin(prop_names), std::end(prop_names), [&arg_it](cm::string_view prop_name) { return *arg_it == prop_name; }); diff --git a/Source/cmStandardLevel.h b/Source/cmStandardLevel.h index dbf71b8bbd..1f191a47fe 100644 --- a/Source/cmStandardLevel.h +++ b/Source/cmStandardLevel.h @@ -14,7 +14,7 @@ public: { } 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_; } diff --git a/Source/cmStandardLevelResolver.cxx b/Source/cmStandardLevelResolver.cxx index 1bb865d06e..d6690affed 100644 --- a/Source/cmStandardLevelResolver.cxx +++ b/Source/cmStandardLevelResolver.cxx @@ -542,7 +542,7 @@ std::string cmStandardLevelResolver::GetEffectiveStandard( } std::string cmStandardLevelResolver::GetLevelString( - std::string const& lang, cmStandardLevel const& level) const + std::string const& lang, cmStandardLevel level) const { auto mapping = StandardComputerMapping.find(lang); if (mapping == StandardComputerMapping.end()) { diff --git a/Source/cmStandardLevelResolver.h b/Source/cmStandardLevelResolver.h index 154364107d..242a9714e5 100644 --- a/Source/cmStandardLevelResolver.h +++ b/Source/cmStandardLevelResolver.h @@ -30,7 +30,7 @@ public: std::string const& config) const; std::string GetLevelString(std::string const& lang, - cmStandardLevel const& level) const; + cmStandardLevel level) const; bool AddRequiredTargetFeature(cmTarget* target, std::string const& feature, std::string* error = nullptr) const; diff --git a/Source/cmWindowsRegistry.cxx b/Source/cmWindowsRegistry.cxx index 0a0add3318..154e6d9885 100644 --- a/Source/cmWindowsRegistry.cxx +++ b/Source/cmWindowsRegistry.cxx @@ -524,7 +524,7 @@ namespace std { template <> struct hash { - size_t operator()(cmWindowsRegistry::View const& v) const noexcept + size_t operator()(cmWindowsRegistry::View v) const noexcept { return static_cast< typename underlying_type::type>(v); diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h index ba4f7630a7..e15542d401 100644 --- a/Source/cmXMLWriter.h +++ b/Source/cmXMLWriter.h @@ -108,8 +108,7 @@ private: * 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. */ - static std::time_t SafeContent( - std::chrono::system_clock::time_point const& value) + static std::time_t SafeContent(std::chrono::system_clock::time_point value) { return std::chrono::system_clock::to_time_t(value); } diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 612217abca..897be85176 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -455,8 +455,8 @@ void cmake::CleanupCommandsAndMacros() #ifndef CMAKE_BOOTSTRAP void cmake::SetWarningFromPreset(std::string const& name, - cm::optional const& warning, - cm::optional const& error) + cm::optional warning, + cm::optional error) { if (warning) { if (*warning) { diff --git a/Source/cmake.h b/Source/cmake.h index 6d464de45c..c859beb132 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -388,8 +388,8 @@ public: #ifndef CMAKE_BOOTSTRAP void SetWarningFromPreset(std::string const& name, - cm::optional const& warning, - cm::optional const& error); + cm::optional warning, + cm::optional error); void ProcessPresetVariables(); void PrintPresetVariables(); void ProcessPresetEnvironment(); diff --git a/Tests/CMakeLib/testCommon.h b/Tests/CMakeLib/testCommon.h index b7379d5905..78c6f24f5a 100644 --- a/Tests/CMakeLib/testCommon.h +++ b/Tests/CMakeLib/testCommon.h @@ -29,7 +29,7 @@ namespace { -inline int runTests(std::initializer_list> const& tests, +inline int runTests(std::initializer_list> tests, bool const fail_fast = true) { int result = 0;