This makes the std::function constructor use perfect forwarding, to avoid an unnecessary move-construction of the target. This means we need to rewrite the _Function_base::_Base_manager::_M_init_functor function to use a forwarding reference, and so can reuse it for the clone operation. Also simplify the SFINAE constraints on the constructor, by combining the !is_same_v, function> constraint into the _Callable trait. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/std_function.h (_function_base::_Base_manager): Replace _M_init_functor with a function template using a forwarding reference, and a pair of _M_create function templates. Reuse _M_create for the clone operation. (function::_Decay_t): New alias template. (function::_Callable): Simplify by using _Decay. (function::function(F)): Change parameter to forwarding reference, as per LWG 2447. Add noexcept-specifier. Simplify constraints. (function::operator=(F&&)): Add noexcept-specifier. * testsuite/20_util/function/cons/lwg2774.cc: New test. * testsuite/20_util/function/cons/noexcept.cc: New test. Tested powerpc64le-linux. Committed to trunk.