Make std::function tolerate semantically non-CopyConstructible objects
commit8ce6f78c1f9f91a504cd606b41d4a8d51fb6e5da
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 9 May 2018 13:28:11 +0000 (9 13:28 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 9 May 2018 13:28:11 +0000 (9 13:28 +0000)
treee898f8b7f1c15e8de320cf1d3b76ec85331873c8
parentc78074085f71aa45d258b1f1c8ef9298d45059f0
Make std::function tolerate semantically non-CopyConstructible objects

To satisfy the CopyConstructible requirement a callable object stored in
a std::function must behave the same when copied from a const or
non-const source. If copying a non-const object doesn't produce an
equivalent copy then the behaviour is undefined. But we can make our
std::function more tolerant of such objects by ensuring we always copy
from a const lvalue.

Additionally use an if constexpr statement in the _M_get_pointer
function to avoid unnecessary instantiations in the discarded branch.

* include/bits/std_function.h (_Base_manager::_M_get_pointer):
Use constexpr if in C++17 mode.
(_Base_manager::_M_clone(_Any_data&, const _Any_data&, true_type)):
Copy from const object.
* testsuite/20_util/function/cons/non_copyconstructible.cc: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260080 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/std_function.h
libstdc++-v3/testsuite/20_util/function/cons/non_copyconstructible.cc [new file with mode: 0644]