Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use return_value_policy::move for rvalues #510

Merged
merged 1 commit into from
Nov 20, 2016

Conversation

dean0x7d
Copy link
Member

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, including optional. The issue is that type_caster_generic::cast has overloads for const& and &&, but the STL casters such as list_caster::cast only have a const& overload. Thus, the move policy is never properly applied. Rather than add overloads to all type caster, the rvalue check is done in cpp_function.

This PR also makes an additional adjustment to remove the copy policy exception: rvalues now always use the move policy. This is also safe for copy-only rvalues because the move policy has an internal fallback to copying.

Fixes pybind#509.

The move policy was already set for rvalues in PR pybind#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 commit fixes it.

This also makes an additional adjustment to remove the `copy` policy
exception: rvalues now always use the `move` policy. This is also safe
for copy-only rvalues because the `move` policy has an internal fallback
to copying.
@wjakob
Copy link
Member

wjakob commented Nov 20, 2016

Thank you!

@wjakob wjakob merged commit d079f41 into pybind:master Nov 20, 2016
@aldanor
Copy link
Member

aldanor commented Nov 20, 2016

Thanks @dean0x7d, this seems to fix it indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional caster r.v.p. problems
3 participants