Rvalue references to functions
7.2.1 [basic.lval]
Daniel Krügler

Created on 2009-03-23.00:00:00 last changed 144 months ago


Date: 2010-03-15.00:00:00

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

Date: 2010-02-15.00:00:00

Proposed resolution (February, 2010):

See paper N3030.

Date: 2020-12-15.00:00:00

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” ( [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, [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.)

Date User Action Args
2010-03-29 00:00:00adminsetmessages: + msg2666
2010-03-29 00:00:00adminsetstatus: review -> cd2
2010-02-16 00:00:00adminsetmessages: + msg2526
2010-02-16 00:00:00adminsetstatus: open -> review
2009-03-23 00:00:00admincreate