|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8"> |
| 5 | +<title>Issue 4256: Incorrect constrains for function_ref constructors from nontype_t</title> |
| 6 | +<meta property="og:title" content="Issue 4256: Incorrect constrains for function_ref constructors from nontype_t"> |
| 7 | +<meta property="og:description" content="C++ library issue. Status: New"> |
| 8 | +<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4256.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="4256"><a href="lwg-active.html#4256">4256</a>. Incorrect constrains for <code>function_ref</code> constructors from <code>nontype_t</code></h3> |
| 66 | +<p><b>Section:</b> 22.10.17.6.3 <a href="https://wg21.link/func.wrap.ref.ctor">[func.wrap.ref.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-14 <b>Last modified:</b> 2025-05-14</p> |
| 68 | +<p><b>Priority: </b>Not Prioritized |
| 69 | +</p> |
| 70 | +<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p> |
| 71 | +<p><b>Discussion:</b></p> |
| 72 | +<p> |
| 73 | +For the following class: |
| 74 | +</p> |
| 75 | +<pre> |
| 76 | +struct M |
| 77 | +{ |
| 78 | + void operator(); |
| 79 | +}; |
| 80 | +</pre> |
| 81 | +<p> |
| 82 | +The constructor of <code>function_ref<void()></code> from <code>nontype_t</code> |
| 83 | +is considered to be valid candidate |
| 84 | +(is_constructible_v<function_ref<void()>, nontype_t<M{}>> is <code>true</code>), |
| 85 | +despite the fact that the corresponding invocation of template argument object, that is const lvalue, |
| 86 | +is ill-formed. As consequence we produce hard error from inside of this constructor. |
| 87 | +</p> |
| 88 | + |
| 89 | +<p> |
| 90 | +This is caused by the fact that for constructors with non-type <code>auto f</code> parameter, |
| 91 | +we are checking if <code><i>is-invocable-using</i><F></code> is <code>true</code>, |
| 92 | +where <code>F</code> is <code>decltype(f)</code> i.e. <code>M</code> for the example. |
| 93 | +We should use <code>const F&</code> or <code>decltype((f))</code>. |
| 94 | +</p> |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +<p id="res-4256"><b>Proposed resolution:</b></p> |
| 99 | +<p> |
| 100 | +This wording is relative to <a href="https://wg21.link/N5008">N5008</a>. |
| 101 | +</p> |
| 102 | +<ol> |
| 103 | + |
| 104 | +<li><p>Modify 22.10.17.6.3 <a href="https://wg21.link/func.wrap.ref.ctor">[func.wrap.ref.ctor]</a> as indicated:</p> |
| 105 | + |
| 106 | +<blockquote> |
| 107 | +<pre> |
| 108 | +template<auto f> constexpr function_ref(nontype_t<f>) noexcept; |
| 109 | +</pre> |
| 110 | +<blockquote> |
| 111 | +<p>-8- Let <code>F</code> be <code>decltype(f)</code>.</p> |
| 112 | +<p>-9- <i>Constraints</i>: <code><i>is-invocable-using</i><<ins>const </ins>F<ins>&</ins>></code> is <code>true</code>.</p> |
| 113 | +[…] |
| 114 | +</blockquote> |
| 115 | + |
| 116 | +<pre> |
| 117 | +template<auto f, class U> constexpr function_ref(nontype_t<f>, U&& obj) noexcept; |
| 118 | +</pre> |
| 119 | +<blockquote> |
| 120 | +<p>-12- Let <code>T</code> be <code>remove_reference_t<U></code> and <code>F</code> be <code>decltype(f)</code>.</p> |
| 121 | +<p>-13- <i>Constraints:</i>:</p> |
| 122 | +<ul> |
| 123 | + <li><p>(13.1) <code>is_rvalue_reference_v<U&&></code> is false, and</p></li> |
| 124 | + <li><p>(13.2) <code><i>is-invocable-using</i><<ins>const </ins>F<ins>&</ins>, T <i>cv</i>&></code> is <code>true</code>.</p></li> |
| 125 | +</ul> |
| 126 | +[…] |
| 127 | +</blockquote> |
| 128 | + |
| 129 | +<pre> |
| 130 | +template<auto f, class T> constexpr function_ref(nontype_t<f>, T <i>cv</i>* obj) noexcept; |
| 131 | +</pre> |
| 132 | +<blockquote> |
| 133 | +<p>-17- Let <code>F</code> be <code>decltype(f)</code>.</p> |
| 134 | +<p>-16- <i>Constraints</i>: <code><i>is-invocable-using</i><<ins>const </ins>F<ins>&</ins>, T <i>cv</i>*></code> is <code>true</code>.</p> |
| 135 | +[…] |
| 136 | +</blockquote> |
| 137 | +</blockquote> |
| 138 | + |
| 139 | +</li> |
| 140 | +</ol> |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | +</body> |
| 148 | +</html> |
0 commit comments