<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 808: &sect;[forward] incorrect redundant specification</title>
<meta property="og:title" content="Issue 808: &sect;[forward] incorrect redundant specification">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue808.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#CD1">CD1</a> status.</em></p>
<h3 id="808"><a href="lwg-defects.html#808">808</a>. &sect;[forward] incorrect redundant specification</h3>
<p><b>Section:</b> 22.2.4 <a href="https://wg21.link/forward">[forward]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Jens Maurer <b>Opened:</b> 2008-03-13 <b>Last modified:</b> 2016-02-01</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#forward">issues</a> in [forward].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
p4 (forward) says:
</p>
<blockquote><p>
<i>Return type:</i> If <code>T</code> is an lvalue-reference type, an lvalue; otherwise, an rvalue.
</p></blockquote>

<p>
First of all, lvalue-ness and rvalue-ness are properties of an expression,
not of a type (see 7.2.1 <a href="https://wg21.link/basic.lval">[basic.lval]</a>).  Thus, the phrasing "Return type" is wrong.
Second, the phrase says exactly what the core language wording says for
folding references in 13.4.2 <a href="https://wg21.link/temp.arg.type">[temp.arg.type]</a>/p4  and for function return values
in 7.6.1.3 <a href="https://wg21.link/expr.call">[expr.call]</a>/p10.  (If we feel the wording should be retained, it should
at most be a note with cross-references to those sections.)
</p>
<p>
The prose after the example talks about "forwarding as an <code>int&amp;</code> (an lvalue)" etc.
In my opinion, this is a category error:  "<code>int&amp;</code>" is a type, "lvalue" is a
property of an expression, orthogonal to its type.  (Btw, expressions cannot
have reference type, ever.)
</p>
<p>
Similar with move:
</p>
<blockquote><p>
Return type: an rvalue.
</p></blockquote>
<p>
is just wrong and also redundant.
</p>


<p id="res-808"><b>Proposed resolution:</b></p>
<p>
Change 22.2.4 <a href="https://wg21.link/forward">[forward]</a> as indicated:
</p>

<blockquote>
<pre>
template &lt;class T&gt; T&amp;&amp; forward(typename identity&lt;T&gt;::type&amp;&amp; t);
</pre>

<blockquote>
<p>...</p>
<p>
<del><i>Return type:</i> If <code>T</code> is an lvalue-reference type, an lvalue; otherwise, an rvalue.</del>
</p>
<p>...</p>
<p>
-7- In the first call to <code>factory</code>, <code>A1</code> is deduced as <code>int</code>, so 2 is forwarded to <code>A</code>'s constructor
as <del>an <code>int&amp;&amp;</code> (</del>an rvalue<del>)</del>. In the second call to factory, <code>A1</code> is deduced
as <code>int&amp;</code>, so <code>i</code> is forwarded to <code>A</code>'s constructor as <del>an <code>int&amp;</code> (</del>an lvalue<del>)</del>.
In both cases, <code>A2</code> is deduced as double, so 1.414 is forwarded to <code>A</code>'s constructor as
<del><code>double&amp;&amp;</code> (</del>an rvalue<del>)</del>.
</p>
</blockquote>

<pre>
template &lt;class T&gt; typename remove_reference&lt;T&gt;::type&amp;&amp; move(T&amp;&amp; t);
</pre>

<blockquote>
<p>...</p>
<p>
<del><i>Return type:</i>  an rvalue.</del>
</p>
</blockquote>

</blockquote>






</body>
</html>
