<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3680: Constructor of move_only_function with empty ref-qualifier is over-constrained</title>
<meta property="og:title" content="Issue 3680: Constructor of move_only_function with empty ref-qualifier is over-constrained">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3680.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#New">New</a> status.</em></p>
<h3 id="3680"><a href="lwg-active.html#3680">3680</a>. Constructor of <code>move_only_function</code> with empty <code><i>ref</i></code>-qualifier is over-constrained</h3>
<p><b>Section:</b> 22.10.17.4.3 <a href="https://wg21.link/func.wrap.move.ctor">[func.wrap.move.ctor]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Zhihao Yuan <b>Opened:</b> 2022-02-27 <b>Last modified:</b> 2022-03-04</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#func.wrap.move.ctor">active issues</a> in [func.wrap.move.ctor].</p>
<p><b>View all other</b> <a href="lwg-index.html#func.wrap.move.ctor">issues</a> in [func.wrap.move.ctor].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The following test compiles and holds:
</p>
<blockquote><pre>
struct X
{
  int operator()() &amp; { return 1; }  // #1
  int operator()() &amp;&amp; { return 2; } // #2
};

using T = move_only_function&lt;int()&gt;;
assert(T(X{})() == 1);
</pre></blockquote>
<p>
In other words, <code>#2</code> is never used. But if you really remove <code>#2</code>, the code doesn't compile.
<p/>
The change was introduced between <a href="https://wg21.link/P0288R5" title=" any_invocable">P0288R5</a> and <a href="https://wg21.link/P0288R6" title=" any_invocable">P0288R6</a>, with 
an intention (assumed) to require <code>move_only_function&lt;R(Args...) <i>cv</i>&gt;</code>
erasing callable objects with <code>operator()</code> without <code><i>ref</i></code>-qualifiers. 
But the actual outcome outlawed programs that were valid when using <code>std::function</code>.
<p/>
It also outlaws future programs such as
</p>
<blockquote><pre>
T x = [captures](this auto&amp;) { return ...; }
</pre></blockquote>
<p>
where declaring <code>this auto&amp;&amp;</code> without forwarding only to satisfy
<code>move_only_function</code>'s constraints would be strange.
</p>

<p><i>[2022-03-04; Reflector poll]</i></p>

<p>
Set priority to 2 after reflector poll.
Probably needs a paper for LEWG.
</p>



<p id="res-3680"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4901" title=" Working Draft, Standard for Programming Language C++">N4901</a>.
</p>

<ol>
<li><p>Modify 22.10.17.4.3 <a href="https://wg21.link/func.wrap.move.ctor">[func.wrap.move.ctor]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class VT&gt;
  static constexpr bool <i>is-callable-from</i> = <i>see below</i>;
</pre>
<blockquote>
<p>
-1- If <code><i>noex</i></code> is <code>true</code>, <code><i>is-callable-from</i>&lt;VT&gt;</code> is equal to:
</p>
<blockquote><pre>
<del>is_nothrow_invocable_r_v&lt;R, VT <i>cv ref</i>, ArgTypes...&gt; &amp;&amp;</del>
is_nothrow_invocable_r_v&lt;R, VT <i>inv-quals</i>, ArgTypes...&gt;
</pre></blockquote>
<p>
Otherwise, <code><i>is-callable-from</i>&lt;VT&gt;</code> is equal to:
</p>
<blockquote><pre>
<del>is_invocable_r_v&lt;R, VT <i>cv ref</i>, ArgTypes...&gt; &amp;&amp;</del>
is_invocable_r_v&lt;R, VT <i>inv-quals</i>, ArgTypes...&gt;
</pre></blockquote>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
