Fix/remove some bad std::moves#9172
Merged
Ericson2314 merged 2 commits intoNixOS:masterfrom Oct 16, 2023
Merged
Conversation
tomberek
approved these changes
Oct 16, 2023
Member
|
I was preferring the first one because I thought |
Contributor
Author
No, there is no guarantee on that. It would be nice of the implementer of the move-constructor/assignment-operator to implement it this way, but it is not safe to assume anything on the state of the moved-from object. |
tebowy
pushed a commit
to tebowy/nix
that referenced
this pull request
Jul 11, 2024
Fix/remove some bad std::moves (cherry picked from commit 8c049a9) Change-Id: I720273378d2506a13883acee28abd096d099b0d4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
While being at it, I grepped through the source to identify more positions with bad
std::moveusage.I particularly fixed 2 types of moves (grouped in two different commits):
bla = *std::move(some_optional);- this moves an optional and then copies its content. The dereference operator must go into the movereturn std::move(some_stack_var)- these moves are superfluous as they would be moved to the caller anyway, but they even forbid named return value optimization (NRVO) where it would otherwise be applicable.Context
Priorities
Add 👍 to pull requests you find important.