|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8"> |
| 5 | +<title>Issue 4255: move_only_function constructor should recognize empty copyable_functions</title> |
| 6 | +<meta property="og:title" content="Issue 4255: move_only_function constructor should recognize empty copyable_functions"> |
| 7 | +<meta property="og:description" content="C++ library issue. Status: New"> |
| 8 | +<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4255.html"> |
| 9 | +<meta property="og:type" content="website"> |
| 10 | +<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png"> |
| 11 | +<meta property="og:image:alt" content="C++ logo"> |
| 12 | +<style> |
| 13 | + p {text-align:justify} |
| 14 | + li {text-align:justify} |
| 15 | + pre code.backtick::before { content: "`" } |
| 16 | + pre code.backtick::after { content: "`" } |
| 17 | + blockquote.note |
| 18 | + { |
| 19 | + background-color:#E0E0E0; |
| 20 | + padding-left: 15px; |
| 21 | + padding-right: 15px; |
| 22 | + padding-top: 1px; |
| 23 | + padding-bottom: 1px; |
| 24 | + } |
| 25 | + ins {background-color:#A0FFA0} |
| 26 | + del {background-color:#FFA0A0} |
| 27 | + table.issues-index { border: 1px solid; border-collapse: collapse; } |
| 28 | + table.issues-index th { text-align: center; padding: 4px; border: 1px solid; } |
| 29 | + table.issues-index td { padding: 4px; border: 1px solid; } |
| 30 | + table.issues-index td:nth-child(1) { text-align: right; } |
| 31 | + table.issues-index td:nth-child(2) { text-align: left; } |
| 32 | + table.issues-index td:nth-child(3) { text-align: left; } |
| 33 | + table.issues-index td:nth-child(4) { text-align: left; } |
| 34 | + table.issues-index td:nth-child(5) { text-align: center; } |
| 35 | + table.issues-index td:nth-child(6) { text-align: center; } |
| 36 | + table.issues-index td:nth-child(7) { text-align: left; } |
| 37 | + table.issues-index td:nth-child(5) span.no-pr { color: red; } |
| 38 | + @media (prefers-color-scheme: dark) { |
| 39 | + html { |
| 40 | + color: #ddd; |
| 41 | + background-color: black; |
| 42 | + } |
| 43 | + ins { |
| 44 | + background-color: #225522 |
| 45 | + } |
| 46 | + del { |
| 47 | + background-color: #662222 |
| 48 | + } |
| 49 | + a { |
| 50 | + color: #6af |
| 51 | + } |
| 52 | + a:visited { |
| 53 | + color: #6af |
| 54 | + } |
| 55 | + blockquote.note |
| 56 | + { |
| 57 | + background-color: rgba(255, 255, 255, .10) |
| 58 | + } |
| 59 | + } |
| 60 | +</style> |
| 61 | +</head> |
| 62 | +<body> |
| 63 | +<hr> |
| 64 | +<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> |
| 65 | +<h3 id="4255"><a href="lwg-active.html#4255">4255</a>. move_only_function constructor should recognize empty copyable_functions</h3> |
| 66 | +<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> |
| 67 | + <b>Submitter:</b> Tomasz Kamiński <b>Opened:</b> 2025-05-12 <b>Last modified:</b> 2025-05-12</p> |
| 68 | +<p><b>Priority: </b>Not Prioritized |
| 69 | +</p> |
| 70 | +<p><b>View other</b> <a href="lwg-index-open.html#func.wrap.move.ctor">active issues</a> in [func.wrap.move.ctor].</p> |
| 71 | +<p><b>View all other</b> <a href="lwg-index.html#func.wrap.move.ctor">issues</a> in [func.wrap.move.ctor].</p> |
| 72 | +<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p> |
| 73 | +<p><b>Discussion:</b></p> |
| 74 | +<p> |
| 75 | +The standard currently requires that constructing <code>move_only_function</code> |
| 76 | +from empty <code>copyable_function</code>, creates an non-empty <code>move_only_function</code>, |
| 77 | +that contains an empty <code>copyable_function</code> as the target. For exampe: |
| 78 | +<code> |
| 79 | +std::copyable_function<int(int)> ce; |
| 80 | +std::move_only_function<int(int)> me(ce); |
| 81 | +</code> |
| 82 | +We require that invoking <code>me(1)</code> is undefined behavior (as it leads to call to the |
| 83 | +<code>ce(1)</code>), however it cannot be detected in the user code, as <code>me != nullptr</code> |
| 84 | +is true. |
| 85 | +</p> |
| 86 | + |
| 87 | +<p> |
| 88 | +We should require that the <code>move_only_function(F&& f)</code> constructor to create an |
| 89 | +empty object, if <code>f</code> is instantiation of of <code>copyable_function</code> and |
| 90 | +<code>f == nullptr</code> is true, i.e. f does not contain target object. |
| 91 | +</p> |
| 92 | + |
| 93 | +<p> |
| 94 | +This simplifies implementing avoidance of double wrapping per 22.10.17.1 <a href="https://wg21.link/func.wrap.general">[func.wrap.general]</a> p2, |
| 95 | +as transfering the target produces empty functor. |
| 96 | +</p> |
| 97 | + |
| 98 | +<p> |
| 99 | +The <code>copyable_function</code> cannot be constructed from <code>move_only_function</code>, |
| 100 | +as it requires functor to be copyable. Invkoing an empty <code>std::function</code> has well |
| 101 | +defined behavior (throws <code>bad_function_call</code>), and wrapping such object into |
| 102 | +other functors should reproduce that behavior |
| 103 | +</p> |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +<p id="res-4255"><b>Proposed resolution:</b></p> |
| 108 | +<p> |
| 109 | +This wording is relative to <a href="https://wg21.link/N5008">N5008</a>. |
| 110 | +</p> |
| 111 | +<ol> |
| 112 | + |
| 113 | +<li><p>Modify 22.10.17.1 <a href="https://wg21.link/func.wrap.general">[func.wrap.general]</a> as indicated:</p> |
| 114 | + |
| 115 | +<blockquote> |
| 116 | +<pre> |
| 117 | +template<class F> move_only_function(F&& f); |
| 118 | +</pre> |
| 119 | +<blockquote> |
| 120 | +[…] |
| 121 | +<p>-8- <i>Postconditions:</i>: <code>*this</code> has no target object if any of the following hold:</p> |
| 122 | +<ul> |
| 123 | + <li><p>(8.1) <code>f</code> is a null function pointer value, <del>or</del></p></li> |
| 124 | + <li><p>(8.2) <code>f</code> is a null member pointer value, or</p></li> |
| 125 | + <li><p>(8.2) <code>remove_cvref_t<F></code> is a specialization of the <code>move_only_function</code> |
| 126 | + <ins>or <code>copyable_function</code></ins> class template, and <code>f</code> has no target object.</p></li> |
| 127 | +</ul> |
| 128 | +</blockquote> |
| 129 | +</blockquote> |
| 130 | + |
| 131 | +</li> |
| 132 | +</ol> |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | +</body> |
| 140 | +</html> |
0 commit comments