<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3046: Do not require reference_wrapper to support non-referenceable function types</title>
<meta property="og:title" content="Issue 3046: Do not require reference_wrapper to support non-referenceable function types">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3046.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="3046"><a href="lwg-active.html#3046">3046</a>. Do not require <code>reference_wrapper</code> to support non-referenceable function types</h3>
<p><b>Section:</b> 22.10.6 <a href="https://wg21.link/refwrap">[refwrap]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2017-12-14 <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#refwrap">issues</a> in [refwrap].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
[refwrap] says that <code>reference_wrapper&lt;T&gt;</code> is a "wrapper around a reference to an object or function of type <code>T</code>" 
but this doesn't actually constrain it, and doesn't forbid non-referenceable function types like <code>int() const</code>.
<p/>
There is no way to construct a <code>reference_wrapper&lt;int() const&gt;</code> but implementations are required to provide partial 
specializations for functions with <i>cv</i>-qualifiers and ref-qualifiers in order to define a nested <code>result_type</code>. 
It should be undefined to instantiate <code>reference_wrapper&lt;T&gt;</code> with a non-referenceable type, or with a reference type 
(since references to references are not possible). Making it undefined (rather than ill-formed or unspecified) means implementations 
are not required to diagnose such invalid specializations, but also don't have to go to the effort of supporting weak result types etc.
</p>
<p><i>[2018-01; Priority set to 3 after mailing list discussion]</i></p>


<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4713">N4713</a>.</p>

<ol>
<li><p>Modify 22.10.6 <a href="https://wg21.link/refwrap">[refwrap]</a> as indicated:</p>

<blockquote>
<p>
-1- <code>reference_wrapper&lt;T&gt;</code> is a <code>CopyConstructible</code> and <code>CopyAssignable</code> wrapper around a reference 
to an object or function of type <code>T</code>. <ins><code>T</code> shall be a referenceable type (3.45 <a href="https://wg21.link/defns.referenceable">[defns.referenceable]</a>) that 
is not a reference type.</ins>
<p/>
-2- <code>reference_wrapper&lt;T&gt;</code> shall be a trivially copyable type (6.9 <a href="https://wg21.link/basic.types">[basic.types]</a>).
</p>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2019-03-15; Daniel comments and provides revised wording]</i></p>

<p>
The current wording is now far behind the working draft and a synchronization is therefore recommended. In particular, with the
acceptance of <a href="https://wg21.link/p0357r1">P0357R1</a>, the specification of <code>reference_wrapper</code> has no longer any
<i>weak result type</i>. Second, I would like to concur with a <a href="http://lists.isocpp.org/lib/2017/12/5023.php">remark 
from Tomasz</a> to change the wording to replace the undefined behavior by an ill-formed program instead, because <em>every</em>
attempt to instantiate the definition of <code>reference_wrapper</code> will instantiate its member declarations, and this would
cause the program to become ill-formed anyway because of the illegal formation of references to non-referenceable function 
types for member functions such as <code>T&amp; get() const noexcept</code>.
<p/>
As concrete wording suggestion I would recommend wording that ensures that an ill-formed program is only required when a
specialization of <code>reference_wrapper</code> is instantiated, because in the absence of a constrained template parameter
we shouldn't require implementations to diagnose even forming the name of a <code>reference_wrapper</code> specialization such 
as in the following example:
</p>
<blockquote><pre>
using X = reference_wrapper&lt;int() const&gt;;
</pre></blockquote>
<p>
The wording below does not take advantage of a <i>Mandates:</i> element to prevent a dependency on LWG <a href="lwg-active.html#3193" title="Mandates: and Expects: elements are not defined for types (Status: New)">3193</a><sup><a href="https://cplusplus.github.io/LWG/issue3193" title="Latest snapshot">(i)</a></sup>
and because such an element is rarely used to specify class templates. If the committee wishes to use such an element, 
the equivalent wording would be:
</p>
<blockquote><p>
<i>Mandates:</i> <code>reference_wrapper</code> is instantiated with a referenceable type (3.45 <a href="https://wg21.link/defns.referenceable">[defns.referenceable]</a>) 
as the argument for the template parameter <code>T</code>.
</p></blockquote>


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

<ol>
<li><p>Modify 22.10.6 <a href="https://wg21.link/refwrap">[refwrap]</a> as indicated:</p>

<blockquote>
<p>
-1- <code>reference_wrapper&lt;T&gt;</code> is a <i>Cpp17CopyConstructible</i> and <i>Cpp17CopyAssignable</i> wrapper around a reference
to an object or function of type <code>T</code>. <ins>If <code>reference_wrapper</code> is instantiated with a non-referenceable type 
(3.45 <a href="https://wg21.link/defns.referenceable">[defns.referenceable]</a>) as the argument for the template parameter <code>T</code>, the program is ill-formed.</ins>
<p/>
-2- <code>reference_wrapper&lt;T&gt;</code> is a trivially copyable type (6.9 <a href="https://wg21.link/basic.types">[basic.types]</a>).
<p/>
-3- The template parameter <code>T</code> of <code>reference_wrapper</code> may be an incomplete type.
</p>
</blockquote>
</li>
</ol>





</body>
</html>
