From 17b49134fae6450c10fbbd7dfbc613ad08265b83 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:15:43 +0300 Subject: [PATCH 1/6] fix(treewide): fix incorrect usage of std::move `auto &&` and `T &&` are forwarding references and can be either lvalue or rvalue references. Moving from universal references is incorrect and should not be done. Moving from integral or floating-point values is pointless and just worsens debug performance. --- src/libstore/filetransfer.cc | 2 +- src/libstore/machines.cc | 2 +- src/libutil/executable-path.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index e9e4b2c44..42b93cfe0 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -153,7 +153,7 @@ struct curlFileTransfer : public FileTransfer template void fail(T && e) { - failEx(std::make_exception_ptr(std::move(e))); + failEx(std::make_exception_ptr(std::forward(e))); } LambdaSink finalSink; diff --git a/src/libstore/machines.cc b/src/libstore/machines.cc index 5e038fb28..eb729b697 100644 --- a/src/libstore/machines.cc +++ b/src/libstore/machines.cc @@ -33,7 +33,7 @@ Machine::Machine( systemTypes(systemTypes), sshKey(sshKey), maxJobs(maxJobs), - speedFactor(speedFactor == 0.0f ? 1.0f : std::move(speedFactor)), + speedFactor(speedFactor == 0.0f ? 1.0f : speedFactor), supportedFeatures(supportedFeatures), mandatoryFeatures(mandatoryFeatures), sshPublicHostKey(sshPublicHostKey) diff --git a/src/libutil/executable-path.cc b/src/libutil/executable-path.cc index 9fb5214b2..b5e22bab9 100644 --- a/src/libutil/executable-path.cc +++ b/src/libutil/executable-path.cc @@ -35,7 +35,7 @@ ExecutablePath ExecutablePath::parse(const OsString & path) std::make_move_iterator(strings.begin()), std::make_move_iterator(strings.end()), std::back_inserter(ret), - [](auto && str) { + [](OsString && str) { return fs::path{ str.empty() // "A zero-length prefix is a legacy feature that From af63d67ba5cca00cb7e99c41a15447e5a706b1e1 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:28:12 +0300 Subject: [PATCH 2/6] fix(libutils): make ref move assignable/constructible --- src/libutil/ref.hh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/libutil/ref.hh b/src/libutil/ref.hh index 3d0e64ab4..92688bf1e 100644 --- a/src/libutil/ref.hh +++ b/src/libutil/ref.hh @@ -18,11 +18,6 @@ private: std::shared_ptr p; public: - - ref(const ref & r) - : p(r.p) - { } - explicit ref(const std::shared_ptr & p) : p(p) { @@ -75,8 +70,6 @@ public: return ref((std::shared_ptr) p); } - ref & operator=(ref const & rhs) = default; - bool operator == (const ref & other) const { return p == other.p; From 6c3f720e2c7954f9cc3532056f3d215bdfdb3ca6 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:29:41 +0300 Subject: [PATCH 3/6] fix(treewide): move arguments where needed Moving from arguments where it should be done. --- src/libcmd/installable-flake.hh | 2 +- src/libcmd/installable-value.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcmd/installable-flake.hh b/src/libcmd/installable-flake.hh index 8e0a232ef..212403dd4 100644 --- a/src/libcmd/installable-flake.hh +++ b/src/libcmd/installable-flake.hh @@ -26,7 +26,7 @@ struct ExtraPathInfoFlake : ExtraPathInfoValue Flake flake; ExtraPathInfoFlake(Value && v, Flake && f) - : ExtraPathInfoValue(std::move(v)), flake(f) + : ExtraPathInfoValue(std::move(v)), flake(std::move(f)) { } }; diff --git a/src/libcmd/installable-value.hh b/src/libcmd/installable-value.hh index 60207cd23..4b6dbd306 100644 --- a/src/libcmd/installable-value.hh +++ b/src/libcmd/installable-value.hh @@ -59,7 +59,7 @@ struct ExtraPathInfoValue : ExtraPathInfo Value value; ExtraPathInfoValue(Value && v) - : value(v) + : value(std::move(v)) { } virtual ~ExtraPathInfoValue() = default; From 8dd787fbf6a204b565b031baf0036262177cecc8 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:33:57 +0300 Subject: [PATCH 4/6] fix(libutil): remove no-op move from const --- src/libutil/position.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libutil/position.cc b/src/libutil/position.cc index 5a2529262..946f167b6 100644 --- a/src/libutil/position.cc +++ b/src/libutil/position.cc @@ -9,7 +9,7 @@ Pos::Pos(const Pos * other) } line = other->line; column = other->column; - origin = std::move(other->origin); + origin = other->origin; } Pos::operator std::shared_ptr() const From 149802b9f5e1364ddf9905c63d2436e07b911078 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:39:26 +0300 Subject: [PATCH 5/6] fix(libstore): make BasicDerivation move-constructible/assignable --- src/libstore/derivations.hh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 58e5328a5..40740d545 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -298,6 +298,10 @@ struct BasicDerivation std::string name; BasicDerivation() = default; + BasicDerivation(BasicDerivation &&) = default; + BasicDerivation(const BasicDerivation &) = default; + BasicDerivation& operator=(BasicDerivation &&) = default; + BasicDerivation& operator=(const BasicDerivation &) = default; virtual ~BasicDerivation() { }; bool isBuiltin() const; From 0347bca15b98f89570d5c55f875931bb81b2eb00 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:43:58 +0300 Subject: [PATCH 6/6] fix(libstore/path-info): make ValidPathInfo move constructible/assignable --- src/libstore/path-info.hh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libstore/path-info.hh b/src/libstore/path-info.hh index 71f1476a6..9a4c466a8 100644 --- a/src/libstore/path-info.hh +++ b/src/libstore/path-info.hh @@ -176,17 +176,18 @@ struct ValidPathInfo : UnkeyedValidPathInfo { */ Strings shortRefs() const; - ValidPathInfo(const ValidPathInfo & other) = default; - ValidPathInfo(StorePath && path, UnkeyedValidPathInfo info) : UnkeyedValidPathInfo(info), path(std::move(path)) { }; ValidPathInfo(const StorePath & path, UnkeyedValidPathInfo info) : UnkeyedValidPathInfo(info), path(path) { }; ValidPathInfo(const Store & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash); - - virtual ~ValidPathInfo() { } }; +static_assert(std::is_move_assignable_v); +static_assert(std::is_copy_assignable_v); +static_assert(std::is_copy_constructible_v); +static_assert(std::is_move_constructible_v); + using ValidPathInfos = std::map; }