This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 113d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-03-20


846. Rvalue references to functions

Section: 7.2.1  [basic.lval]     Status: CD2     Submitter: Daniel Krügler     Date: 23 March, 2009

[Voted into WP at March, 2010 meeting as document N3055.]

The status of rvalue references to functions is not clear in the current wording. For example, 7.2.1 [basic.lval] paragraph 2 says,

An lvalue refers to an object or function. Some rvalue expressions—those of (possibly cv-qualified) class or array type—also refer to objects. [Footnote: Expressions such as invocations of constructors and of functions that return a class type refer to objects, and the implementation can invoke a member function upon such objects, but the expressions are not lvalues. —end footnote]

This would tend to indicate that there are no rvalues of function type. However, Clause 7 [expr] paragraph 6 says,

If an expression initially has the type “rvalue reference to T” (9.3.4.3 [dcl.ref], 9.4.4 [dcl.init.ref]), the type is adjusted to “T” prior to any further analysis, and the expression designates the object or function denoted by the rvalue reference. If the expression is the result of calling a function, whether implicitly or explicitly, it is an rvalue; otherwise, it is an lvalue.

This explicitly indicates that rvalue references to functions are possible and that, in some cases, they yield function-typed rvalues. Furthermore, _N2914_.20.2.4 [concept.operator] paragraph 20 describes the concept Callable as:

    auto concept Callable<typename F, typename... Args> {
      typename result_type;
      result_type operator()(F&, Args...);
      result_type operator()(F&&, Args...);
    }

It would be strange if Callable were satisfied for a function object type but not for a function type.

However, assuming that rvalue references to functions are intended to be supported, it is not clear how an rvalue of function type is supposed to behave. For instance, 7.6.1.3 [expr.call] paragraph 1 says,

For an ordinary function call, the postfix expression shall be either an lvalue that refers to a function (in which case the function-to-pointer standard conversion (7.3.4 [conv.func]) is suppressed on the postfix expression), or it shall have pointer to function type.

From this, it appears that an rvalue of function type cannot be used in a function call. It can't be converted to a pointer to function, either, as 7.3.4 [conv.func] paragraph 1 says,

An lvalue of function type T can be converted to an rvalue of type “pointer to T.” The result is a pointer to the function.

(See also issues 664 and especially 690. The approach described in the latter issue, viewing rvalue references as essentially lvalues rather than as essentially rvalues, could resolve the specification problems described above by eliminating the concept of an rvalue of function type.)

Proposed resolution (February, 2010):

See paper N3030.