This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Tentatively Ready status.
move_only_function constructor should recognize empty copyable_functionsSection: 22.10.17.4.3 [func.wrap.move.ctor] Status: Tentatively Ready Submitter: Tomasz Kamiński Opened: 2025-05-12 Last modified: 2025-10-22
Priority: Not Prioritized
View other active issues in [func.wrap.move.ctor].
View all other issues in [func.wrap.move.ctor].
View all issues with Tentatively Ready status.
Discussion:
The standard currently requires that constructing move_only_function
from empty copyable_function, creates an non-empty move_only_function,
that contains an empty copyable_function as the target. For example:
std::copyable_function<int(int)> ce; std::move_only_function<int(int)> me(ce);
We require that invoking me(1) is undefined behavior (as it leads to call to the
ce(1)), however it cannot be detected in the user code, as me != nullptr
is true.
We should require the move_only_function(F&& f) constructor to create an
empty object, if f is an instantiation of copyable_function and
f == nullptr is true, i.e. f does not contain target object.
This simplifies implementing avoidance of double wrapping per 22.10.17.1 [func.wrap.general] p2, as transferring the target produces an empty functor.
The copyable_function cannot be constructed from move_only_function,
as it requires functor to be copyable. Invoking an empty std::function has well
defined behavior (throws bad_function_call), and wrapping such object into
other functors should reproduce that behavior.
[2025-10-22; Reflector poll.]
Set status to Tentatively Ready after six votes in favour during reflector poll.
Proposed resolution:
This wording is relative to N5008.
Modify 22.10.17.4.3 [func.wrap.move.ctor] as indicated:
template<class F> move_only_function(F&& f);[…]-8- Postconditions::
*thishas no target object if any of the following hold:
(8.1) —
fis a null function pointer value,or(8.2) —
fis a null member pointer value, or(8.2) —
remove_cvref_t<F>is a specialization of themove_only_functionorcopyable_functionclass template, andfhas no target object.