|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4257" status="New"> |
| 5 | +<title>Skipping indirection is not allowed for <code>function_ref</code></title> |
| 6 | +<section><sref ref="[func.wrap.general]"/></section> |
| 7 | +<submitter>Tomasz Kamiński</submitter> |
| 8 | +<date>15 May 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +Currently the wording in <sref ref="[func.wrap.general]"/> allows implementation |
| 14 | +to avoid double indirection when onstructing owning functions wrappers from another one: |
| 15 | +</p> |
| 16 | +<blockquote> |
| 17 | +<p> 2- Let <tt>t</tt> be an object of a type that is a specialization of <tt>function</tt>, |
| 18 | +<tt>copyable_function</tt>, or <tt>move_only_function</tt>, such that the target object |
| 19 | +<tt>x</tt> of <tt>t</tt> has a type that is a specialization of <tt>function</tt>, |
| 20 | +<tt>copyable_function</tt>, or <tt>move_only_function</tt> |
| 21 | +Each argument of the invocation of <tt>x</tt> evaluated as part of the invocation of <tt>t</tt> |
| 22 | +may alias an argument in the same position in the invocation of <tt>t</tt> that has the same type, |
| 23 | +even if the corresponding parameter is not of reference type.</p> |
| 24 | +</blockquote> |
| 25 | + |
| 26 | +<p> |
| 27 | +However, the wording does not cover a <code>function_ref</code>, disallowing implementation to perform |
| 28 | +this optimization when signatures are compatible, for example: |
| 29 | +</p> |
| 30 | +<pre> |
| 31 | +std::function_ref<void() noexcept> f1(ptr); |
| 32 | +std::function_ref<void()> f1(f2); |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> |
| 36 | +We should include specialization of the function_ref in the list. Note that this allows, |
| 37 | +but does not require implementation to perform such optimization. As consequence it is acceptable |
| 38 | +to specifiy the allowance for all combinations of polymorphic wrappers, even for creating |
| 39 | +owning wrapper from non-owning one, even if implementing such optimization may not be possible. |
| 40 | +</p> |
| 41 | + |
| 42 | +</discussion> |
| 43 | + |
| 44 | +<resolution> |
| 45 | +<p> |
| 46 | +This wording is relative to <paper num="N5008"/>. |
| 47 | +</p> |
| 48 | +<ol> |
| 49 | + |
| 50 | +<li><p>Modify <sref ref="[func.wrap.general]"/> as indicated:</p> |
| 51 | + |
| 52 | +<blockquote> |
| 53 | +<p> 2- Let <tt>t</tt> be an object of a type that is a specialization of <tt>function</tt>, |
| 54 | +<tt>copyable_function</tt>,<del> or</del> <tt>move_only_function</tt><ins>, or <tt>function_ref</tt></ins>, |
| 55 | +such that the target object <tt>x</tt> of <tt>t</tt> has a type that is a specialization of <tt>function</tt>, |
| 56 | +<tt>copyable_function</tt>, <del>or </del><tt>move_only_function</tt><ins>, or <tt>function_ref</tt></ins>. |
| 57 | +Each argument of the invocation of <tt>x</tt> evaluated as part of the invocation of <tt>t</tt> |
| 58 | +may alias an argument in the same position in the invocation of <tt>t</tt> that has the same type, |
| 59 | +even if the corresponding parameter is not of reference type.</p> |
| 60 | + |
| 61 | +</blockquote> |
| 62 | + |
| 63 | +</li> |
| 64 | +</ol> |
| 65 | + |
| 66 | +</resolution> |
| 67 | + |
| 68 | +</issue> |
0 commit comments