<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 846</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="846"></A><H4>846.
  
Rvalue references to functions
</H4>
<B>Section: </B>7.2.1&#160; [<A href="https://wg21.link/basic.lval">basic.lval</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD2
 &#160;&#160;&#160;

 <B>Submitter: </B>Daniel Kr&#252;gler
 &#160;&#160;&#160;

 <B>Date: </B>23 March, 2009<BR>


<P>[Voted into WP at March, 2010 meeting as document N3055.]</P>

<P>The status of rvalue references to functions is not clear in the
current wording.  For example, 7.2.1 [<A href="https://wg21.link/basic.lval#2">basic.lval</A>] paragraph 2
says,</P>

<BLOCKQUOTE>

An lvalue refers to an object or function. Some rvalue
expressions&#8212;those of (possibly cv-qualified) class or array
type&#8212;also refer to objects. [<I>Footnote:</I> 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.
&#8212;<I>end footnote</I>]

</BLOCKQUOTE>

<P>This would tend to indicate that there are no rvalues of function
type.  However, Clause 7 [<A href="https://wg21.link/expr#6">expr</A>] paragraph 6 says,</P>

<BLOCKQUOTE>

If an expression initially has the type &#8220;rvalue reference to
T&#8221; (9.3.4.3 [<A href="https://wg21.link/dcl.ref">dcl.ref</A>], 9.5.4 [<A href="https://wg21.link/dcl.init.ref">dcl.init.ref</A>]), the
type is adjusted to &#8220;T&#8221; 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.

</BLOCKQUOTE>

<P>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 [<A href="https://wg21.link/concept.operator#20">concept.operator</A>] paragraph 20 describes the
concept <TT>Callable</TT> as:</P>

<PRE>
    auto concept Callable&lt;typename F, typename... Args&gt; {
      typename result_type;
      result_type operator()(F&amp;, Args...);
      result_type operator()(F&amp;&amp;, Args...);
    }
</PRE>

<P>It would be strange if <TT>Callable</TT> were satisfied for a
function object type but not for a function type.</P>

<P>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 [<A href="https://wg21.link/expr.call#1">expr.call</A>] paragraph 1
says,</P>

<BLOCKQUOTE>

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 [<A href="https://wg21.link/conv.func">conv.func</A>]) is
suppressed on the postfix expression), or it shall have pointer to
function type.

</BLOCKQUOTE>

<P>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 [<A href="https://wg21.link/conv.func#1">conv.func</A>] paragraph 1 says,</P>

<BLOCKQUOTE>

An lvalue of function type <TT>T</TT> can be converted to an rvalue of
type &#8220;pointer to <TT>T</TT>.&#8221; The result is a pointer to
the function.

</BLOCKQUOTE>

<P>(See also issues <A HREF="664.html">664</A> and especially
<A HREF="690.html">690</A>.  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.)</P>

<P><B>Proposed resolution (February, 2010):</B></P>

<P>See paper N3030.</P>

<BR><BR>
</BODY>
</HTML>
