<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2957: bind's specification doesn't apply the cv-qualification of the call wrapper to the callable object</title>
<meta property="og:title" content="Issue 2957: bind's specification doesn't apply the cv-qualification of the call wrapper to the callable object">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2957.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#Resolved">Resolved</a> status.</em></p>
<h3 id="2957"><a href="lwg-defects.html#2957">2957</a>. <code>bind</code>'s specification doesn't apply the <i>cv</i>-qualification of the call wrapper to the callable object</h3>
<p><b>Section:</b> 22.10.15.4 <a href="https://wg21.link/func.bind.bind">[func.bind.bind]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2017-05-04 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#func.bind.bind">issues</a> in [func.bind.bind].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
According to 22.10.15.4 <a href="https://wg21.link/func.bind.bind">[func.bind.bind]</a>/1.2,
</p>
<blockquote><p>
<code>fd</code> is an lvalue of type <code>FD</code> constructed from <code>std::forward&lt;F&gt;(f)</code>,
</p></blockquote>
<p>
and then uses <code>fd</code> throughout the specification, seemingly without
regard to the <i>cv</i>-qualification of the call wrapper <code>g</code>. But this
definition means that <code>fd</code> is always <i>cv</i>-unqualified, rather than having
its <i>cv</i>-qualification change with that of <code>g</code> as intended.
<p/>
LWG <a href="lwg-defects.html#2545" title="Simplify wording for bind without explicitly specified return type (Status: C++17)">2545</a><sup><a href="https://cplusplus.github.io/LWG/issue2545" title="Latest snapshot">(i)</a></sup> accidentally exacerbated the problem by removing any hint that
<code>fd</code>'s <i>cv</i>-qualifier followed that of the call wrapper.
<p/>
A similar issue affects the type of <code>td<sub><i>i</i></sub></code> for nested binds.
</p>

<p><i>[2017-07 Toronto Wed Issue Prioritization]</i></p>

<p>Priority 3</p>

<p><i>[2020-01 Resolved by the adoption of <a href="https://wg21.link/P1065">P1065</a> in Cologne.]</i></p>



<p id="res-2957"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4659">N4659</a>.</p>

<ol>
<li><p>Edit 22.10.15.4 <a href="https://wg21.link/func.bind.bind">[func.bind.bind]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class F, class... BoundArgs&gt;
  <i>unspecified</i> bind(F&amp;&amp; f, BoundArgs&amp;&amp;... bound_args);
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-3- <i>Returns:</i> A forwarding call wrapper <code>g</code> (22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>). The effect of 
<code>g(u<sub>1</sub>, u<sub>2</sub>, ..., u<sub><i>M</i></sub>)</code> shall be
</p>
<blockquote><pre>
<i>INVOKE</i>(<ins>static_cast&lt;FD <i>cv</i> &amp;&gt;(</ins>fd<ins>)</ins>, std::forward&lt;V<sub>1</sub>&gt;(v<sub>1</sub>), 
  std::forward&lt;V<sub>2</sub>&gt;(v<sub>2</sub>), ..., std::forward&lt;V<sub><i>N</i></sub>&gt;(v<sub><i>N</i></sub>))
</pre></blockquote>
<p>
where <ins><i>cv</i> represents the <i>cv</i>-qualifiers of <code>g</code> and</ins> the values and types of the bound arguments 
<code>v<sub>1</sub>, v<sub>2</sub>, . . . , v<sub><i>N</i></sub></code> are determined as specified below. The copy constructor 
and move constructor of the forwarding call wrapper shall throw an exception if and only if the corresponding constructor 
of <code>FD</code> or of any of the types <code>TD<sub><i>i</i></sub></code> throws an exception.
<p/>
[&hellip;]
</p>
</blockquote>
<pre>
template&lt;class R, class F, class... BoundArgs&gt;
  <i>unspecified</i> bind(F&amp;&amp; f, BoundArgs&amp;&amp;... bound_args);
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-7- <i>Returns:</i> A forwarding call wrapper <code>g</code> (22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>). The effect of 
<code>g(u<sub>1</sub>, u<sub>2</sub>, ..., u<sub><i>M</i></sub>)</code> shall be
</p>
<blockquote><pre>
<i>INVOKE</i>&lt;R&gt;(<ins>static_cast&lt;FD <i>cv</i> &amp;&gt;(</ins>fd<ins>)</ins>, std::forward&lt;V<sub>1</sub>&gt;(v<sub>1</sub>), 
  std::forward&lt;V<sub>2</sub>&gt;(v<sub>2</sub>), ..., std::forward&lt;V<sub><i>N</i></sub>&gt;(v<sub><i>N</i></sub>))
</pre></blockquote>
<p>
where <ins><i>cv</i> represents the <i>cv</i>-qualifiers of <code>g</code> and</ins> the values and types of the bound arguments 
<code>v<sub>1</sub>, v<sub>2</sub>, . . . , v<sub><i>N</i></sub></code> are determined as specified below. The copy constructor 
and move constructor of the forwarding call wrapper shall throw an exception if and only if the corresponding constructor 
of <code>FD</code> or of any of the types <code>TD<sub><i>i</i></sub></code> throws an exception.
<p/>
[&hellip;]
<p/>
-10- The values of the bound arguments <code>v<sub>1</sub>, v<sub>2</sub>, ... , v<sub><i>N</i></sub></code> and their 
corresponding types <code>V<sub>1</sub>, V<sub>2</sub>, ... , V<sub><i>N</i></sub></code> depend on 
the types <code>TD<sub><i>i</i></sub></code> derived from the call to <code>bind</code> and the <i>cv</i>-qualifiers <i>cv</i> of the 
call wrapper <code>g</code> as follows:
</p>
<ol style="list-style-type: none">
<li><p>(10.1) &mdash; [&hellip;]</p></li>
<li><p>(10.2) &mdash; if the value of <code>is_bind_expression_v&lt;TD<sub><i>i</i></sub>&gt;</code> is <code>true</code>, the 
argument is <code><ins>static_cast&lt;TD<sub><i>i</i></sub> <i>cv</i> &amp;&gt;(</ins>td<sub><i>i</i></sub><ins>)</ins>(std::forward&lt;U<sub><i>j</i></sub>&gt;(u<sub><i>j</i></sub>)...)</code> and its type <code>V<sub><i>i</i></sub></code> is 
<code>invoke_result_t&lt;TD<sub><i>i</i></sub> <i>cv</i> &amp;, U<sub><i>j</i></sub>...&gt;&amp;&amp;</code>;</p></li>
<li><p>(10.3) &mdash; [&hellip;]</p></li>
</ol>
</blockquote>
</blockquote>
</li>

</ol>





</body>
</html>
