<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2811: "Selected constructor" wording is incorrect for optional/variant/any</title>
<meta property="og:title" content="Issue 2811: &quot;Selected constructor&quot; wording is incorrect for optional/variant/any">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2811.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="2811"><a href="lwg-active.html#2811">2811</a>. "Selected constructor" wording is incorrect for <code>optional</code>/<code>variant</code>/<code>any</code></h3>
<p><b>Section:</b> 22.5.3.2 <a href="https://wg21.link/optional.ctor">[optional.ctor]</a>, 22.5.3.4 <a href="https://wg21.link/optional.assign">[optional.assign]</a>, 22.6.3.2 <a href="https://wg21.link/variant.ctor">[variant.ctor]</a>, 22.7.4.2 <a href="https://wg21.link/any.cons">[any.cons]</a>, 22.7.4.4 <a href="https://wg21.link/any.modifiers">[any.modifiers]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2016-10-29 <b>Last modified:</b> 2020-06-13</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#optional.ctor">issues</a> in [optional.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>
Throughout <code>optional</code>/<code>variant</code>/<code>any</code>'s specification references are made to "the selected constructor 
of <code>T</code>". For example, 22.5.3.2 <a href="https://wg21.link/optional.ctor">[optional.ctor]</a>/16 says of the constructor from <code>const T&amp;</code>:
</p>
<blockquote><p>
-16- <i>Remarks:</i> If <code>T</code>'s selected constructor is a <code>constexpr</code> constructor, this constructor shall be a 
<code>constexpr</code> constructor.
</p></blockquote>
<p>
Similarly, the in-place constructor has this wording (22.5.3.2 <a href="https://wg21.link/optional.ctor">[optional.ctor]</a>/25-26):
</p>
<blockquote><p>
-25- <i>Throws:</i> Any exception thrown by the selected constructor of <code>T</code>.
<p/>
-26- <i>Remarks:</i> If <code>T</code>'s constructor selected for the initialization is a <code>constexpr</code> constructor, 
this constructor shall be a <code>constexpr</code> constructor.
</p></blockquote>
<p>
If <code>T</code> is a scalar type, it has no constructor at all. Moreover, even for 
class types, the in-place constructor wording ignores any implicit conversion done on the argument before the selected 
constructor is called, which 1) may not be valid in constant expressions and 2) may throw an exception; such exceptions 
aren't thrown "by the selected constructor of <code>T</code>" but outside it.
<p/>
The wording should probably be recast to refer to the entire initialization.
</p>

<p><i>[Issues Telecon 16-Dec-2016]</i></p>

<p>Priority 3; Jonathan to provide wording.</p>

<p><i>[2020-06-11; Nina Dinka Ranns comments and provides initial wording]</i></p>

<p>
This wording depends on the current resolution for LWG <a href="lwg-active.html#2833" title="Library needs to specify what it means when it declares a function constexpr (Status: Open)">2833</a><sup><a href="https://cplusplus.github.io/LWG/issue2833" title="Latest snapshot">(i)</a></sup>, which covers the <code>constexpr</code> 
portion of this issue.
</p>


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

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

<blockquote>
<pre>
constexpr optional(const optional&amp; rhs);
</pre>
<blockquote>
<p>
-3- [&hellip;]
<p/>
-4- [&hellip;]
<p/>
-5- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>T</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
<pre>
constexpr optional(optional&amp;&amp; rhs) noexcept(<i>see below</i>);
</pre>
<blockquote>
<p>
-7- [&hellip;]
<p/>
[&hellip;]
<p/>
-10- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>T</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;class... Args&gt; constexpr explicit optional(in_place_t, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-12- [&hellip;]
<p/>
[&hellip;]
<p/>
-15- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>T</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;class U, class... Args&gt;
  constexpr explicit optional(in_place_t, initializer_list&lt;U&gt; il, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-17- [&hellip;]
<p/>
[&hellip;]
<p/>
-20- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>T</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;class U = T&gt; constexpr explicit(<i>see below</i>) optional(U&amp;&amp; v);
</pre>
<blockquote>
<p>
-22- [&hellip;]
<p/>
[&hellip;]
<p/>
-25- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>T</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;class U&gt; explicit(<i>see below</i>) optional(const optional&lt;U&gt;&amp; rhs);
</pre>
<blockquote>
<p>
-27- [&hellip;]
<p/>
[&hellip;]
<p/>
-30- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>T</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;class U&gt; explicit(<i>see below</i>) optional(optional&lt;U&gt;&amp;&amp; rhs);
</pre>
<blockquote>
<p>
-32- [&hellip;]
<p/>
[&hellip;]
<p/>
-35- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>T</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>

</blockquote>
</li>

<li>
<p>Modify 22.6.3.2 <a href="https://wg21.link/variant.ctor">[variant.ctor]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class T, class... Args&gt; constexpr explicit variant(in_place_type_t&lt;T&gt;, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-20- [&hellip;]
<p/>
[&hellip;]
<p/>
-23- <i>Throws:</i> Any exception thrown by <del>calling the selected constructor of <code>T</code></del><ins>the 
initialization of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;class T, class U, class... Args&gt;
  constexpr explicit variant(in_place_type_t&lt;T&gt;, initializer_list&lt;U&gt; il, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-25- [&hellip;]
<p/>
[&hellip;]
<p/>
-28- <i>Throws:</i> Any exception thrown by <del>calling the selected constructor of <code>T</code></del><ins>the 
initialization of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;size_t I, class... Args&gt; constexpr explicit variant(in_place_index_t&lt;I&gt;, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-30 [&hellip;]
<p/>
[&hellip;]
<p/>
-33- <i>Throws:</i> Any exception thrown by <del>calling the selected constructor of <code>T<sub><i>I</i></sub></code></del><ins>the 
initialization of the contained value</ins>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>Modify 22.7.4.2 <a href="https://wg21.link/any.cons">[any.cons]</a> as indicated:</p>

<blockquote>
<pre>
any(const any&amp; other);
</pre>
<blockquote>
<p>
-2- <i>Effects:</i> [&hellip;]
<p/>
-3- <i>Throws:</i> Any exceptions <del>arising from calling the selected constructor for</del><ins>thrown 
by the initialization of</ins> the contained value.
</p>
</blockquote>
[&hellip;]
<pre>
template&lt;class T&gt;
  any(T&amp;&amp; value);
</pre>
<blockquote>
<p>
-5- [&hellip;]
<p/>
[&hellip;]
<p/>
-9- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>VT</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;class T, class... Args&gt;
  explicit any(in_place_type_t&lt;T&gt;, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-10- [&hellip;]
<p/>
[&hellip;]
<p/>
-15- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>VT</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
<pre>
template&lt;class T, class U, class... Args&gt;
  explicit any(in_place_type_t&lt;T&gt;, initializer_list&lt;U&gt; il, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-16- [&hellip;]
<p/>
[&hellip;]
<p/>
-21- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>VT</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>Modify 22.7.4.4 <a href="https://wg21.link/any.modifiers">[any.modifiers]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class T, class... Args&gt;
  decay_t&lt;T&gt;&amp; emplace(Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-1- [&hellip;]
<p/>
[&hellip;]
<p/>
-7- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>VT</code></del><ins>initialization 
of the contained value</ins>.
<p/>
-8- [&hellip;]
</p>
</blockquote>
<pre>
template&lt;class T, class U, class... Args&gt;
  decay_t&lt;T&gt;&amp; emplace(initializer_list&lt;U&gt; il, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-9- [&hellip;]
<p/>
[&hellip;]
<p/>
-15- <i>Throws:</i> Any exception thrown by the <del>selected constructor of <code>VT</code></del><ins>initialization 
of the contained value</ins>.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
