Skip to content

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

Merged
wjakob merged 3 commits into
pybind:masterfrom
sgsaenger:copy_constructible_fix
Oct 31, 2019
Merged

test pair-copyability on C++17 upwards#1886
wjakob merged 3 commits into
pybind:masterfrom
sgsaenger:copy_constructible_fix

Conversation

@sgsaenger

@sgsaenger sgsaenger commented Aug 16, 2019

Copy link
Copy Markdown
Contributor

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

wjakob commented Aug 16, 2019

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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.
@sgsaenger sgsaenger force-pushed the copy_constructible_fix branch from a3657ee to 3600093 Compare October 30, 2019 10:01
@wjakob

wjakob commented Oct 31, 2019

Copy link
Copy Markdown
Member

Looks good to me—thanks!

@wjakob wjakob merged commit a83d69e into pybind:master Oct 31, 2019
@sgsaenger

Copy link
Copy Markdown
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