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

test pair-copyability on C++17 upwards #1886

Merged
merged 3 commits into from
Oct 31, 2019

Conversation

sgsaenger
Copy link
Contributor

@sgsaenger sgsaenger commented Aug 16, 2019

The stdlib falsely detects containers like M=std::map<T, U> as copyable, even when one of T and U is not copyable.
Therefore we cannot rely on the stdlib dismissing std::pair<T, M> by itself, even on C++17.

Fixes #1885

@sgsaenger sgsaenger force-pushed the copy_constructible_fix branch 2 times, most recently from 7c222cf to 3d9cd8d Compare August 16, 2019 10:18
@wjakob
Copy link
Member

wjakob commented Aug 16, 2019

This looks good -- however, it would be good to have a test for a non-copyable data structure with pairs (e.g. std::map as you suggested) to ensure that this doesn't break in the future.

@sgsaenger
Copy link
Contributor Author

Upon writing the tests, i've noticed that the same problems seem to arise with std::is_copy_assignable, which is used in detail::map_assignment by bind_map.
I've just copied the constructible-fix in cast.h and created a custom is_copy_assignable.

@sgsaenger
Copy link
Contributor Author

Any updates on this, are the tests acceptable?

The stdlib falsely detects containers like M=std::map<T, U>
as copyable, even when one of T and U is not copyable.
Therefore we cannot rely on the stdlib dismissing std::pair<T, M>
by itself, even on C++17.
bind_map used std::is_copy_assignable which suffers from the same problems
as std::is_copy_constructible, therefore the same fix has been applied.
@wjakob
Copy link
Member

wjakob commented Oct 31, 2019

Looks good to me—thanks!

@wjakob wjakob merged commit a83d69e into pybind:master Oct 31, 2019
@sgsaenger
Copy link
Contributor Author

Thank you!

@sgsaenger sgsaenger deleted the copy_constructible_fix branch October 31, 2019 12:50
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.

False positives from is_copy_constructible with C++17
2 participants