Always use return_value_policy::move for rvalues #510
Merged
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.
Fixes #509.
The move policy was already set for rvalues in PR #473, but this only applied to directly cast user-defined types. The problem is that STL containers cast values indirectly and the rvalue information is lost. Therefore the move policy was not set correctly. This PR fixes it.
The tests are included only for a
std::list
, but the same underlying issue applies for all STL containers, includingoptional
. The issue is thattype_caster_generic::cast
has overloads forconst&
and&&
, but the STL casters such aslist_caster::cast
only have aconst&
overload. Thus, themove
policy is never properly applied. Rather than add overloads to all type caster, the rvalue check is done incpp_function
.This PR also makes an additional adjustment to remove the
copy
policy exception: rvalues now always use themove
policy. This is also safe for copy-only rvalues because themove
policy has an internal fallback to copying.