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

Only allow unchecked()/mutable_unchecked() on an lvalue #962

Merged
merged 1 commit into from
Aug 13, 2017

Conversation

jagerman
Copy link
Member

This should mitigate accidental invocation on a temporary array.

Fixes #961.

This should mitigate accidental invocation on a temporary array.

Fixes pybind#961.
@dean0x7d
Copy link
Member

dean0x7d commented Aug 7, 2017

Seems fine to me -- preferable to keeping the underlying object alive via refcount. References/views in C++ never do that anyway. Even more so in our case, since the type itself (detail::unchecked_reference) is an implementation detail, the reference isn't expected to be kept around and the type isn't meant to be named.

As far as I can see, the only use case that might be prevented by the lvalue qualifier is:

py::array_t<double> get_array();
void foo(detail::unchecked_reference ref);

foo(get_array().unchecked<1>()); // valid temporary lifetime

But this isn't very likely, especially because of the detail:: part.

@jagerman jagerman merged commit eb0f1cc into pybind:master Aug 13, 2017
@dean0x7d dean0x7d modified the milestone: v2.2 Aug 13, 2017
@jagerman jagerman deleted the unchecked-lvalue-only branch August 14, 2017 20:25
@rwgk rwgk mentioned this pull request Feb 9, 2023
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.

None yet

2 participants