<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2899: is_(nothrow_)move_constructible and tuple, optional and unique_ptr</title>
<meta property="og:title" content="Issue 2899: is_(nothrow_)move_constructible and tuple, optional and unique_ptr">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2899.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#C++20">C++20</a> status.</em></p>
<h3 id="2899"><a href="lwg-defects.html#2899">2899</a>. <code>is_(nothrow_)move_constructible</code> and <code>tuple</code>, <code>optional</code> and <code>unique_ptr</code></h3>
<p><b>Section:</b> 22.4 <a href="https://wg21.link/tuple">[tuple]</a>, 22.5 <a href="https://wg21.link/optional">[optional]</a>, 20.3.1.3.2 <a href="https://wg21.link/unique.ptr.single.ctor">[unique.ptr.single.ctor]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> United States <b>Opened:</b> 2017-02-03 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#tuple">issues</a> in [tuple].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<b>Addresses US 110</b>

<p>The move constructors for <code>tuple</code>, <code>optional</code>, and <code>unique_ptr</code> should return false for 
<code>is_(nothrow_)move_constructible_v&lt;<i>TYPE</i>&gt;</code> when their corresponding <i>Requires</i> clauses are not 
satisfied, as there are now several library clauses that are defined in terms of these traits. The same concern 
applies to the move-assignment operator. Note that <code>pair</code> and <code>variant</code> already satisfy this constraint.
</p>

<p><i>[2017-02-26, Scott Schurr provides wording]</i></p>


<p><i>[
2017-06-27 P2 after 5 positive votes on c++std-lib.
]</i></p>


<p><i>[2016-07, Toronto Thursday night issues processing]</i></p>

<p>The description doesn't match the resolution; Alisdair to investigate. Status to Open</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/n4640">N4640</a>.
</p>
<ol>
<li><p>Modify 22.4.4 <a href="https://wg21.link/tuple.tuple">[tuple.tuple]</a> as indicated:</p>

<blockquote>
<pre>
<i>// 20.5.3.1, tuple construction</i>
<i>EXPLICIT</i> constexpr tuple();
<i>EXPLICIT</i> constexpr tuple(const Types&amp;...); <i>// only if sizeof...(Types) &gt;= 1</i>
template &lt;class... UTypes&gt;
<i>EXPLICIT</i> constexpr tuple(UTypes&amp;&amp;...) <ins>noexcept(<i>see below</i>)</ins>; <i>// only if sizeof...(Types) &gt;= 1</i>

tuple(const tuple&amp;) = default;
tuple(tuple&amp;&amp;) = default;

template &lt;class... UTypes&gt;
<i>EXPLICIT</i> constexpr tuple(const tuple&lt;UTypes...&gt;&amp;);
template &lt;class... UTypes&gt;
<i>EXPLICIT</i> constexpr tuple(tuple&lt;UTypes...&gt;&amp;&amp;) <ins>noexcept(<i>see below</i>)</ins>;

template &lt;class U1, class U2&gt;
<i>EXPLICIT</i> constexpr tuple(const pair&lt;U1, U2&gt;&amp;); <i>// only if sizeof...(Types) == 2</i>
template &lt;class U1, class U2&gt;
<i>EXPLICIT</i> constexpr tuple(pair&lt;U1, U2&gt;&amp;&amp;) <ins>noexcept(<i>see below</i>)</ins>; <i>// only if sizeof...(Types) == 2</i>

[&hellip;]

<i>// 20.5.3.2, tuple assignment</i>
tuple&amp; operator=(const tuple&amp;);
tuple&amp; operator=(tuple&amp;&amp;) noexcept(<i>see below</i>);

template &lt;class... UTypes&gt;
tuple&amp; operator=(const tuple&lt;UTypes...&gt;&amp;);
template &lt;class... UTypes>
tuple&amp; operator=(tuple&lt;UTypes...&gt;&amp;&amp;) <ins>noexcept(<i>see below</i>)</ins>;

template &lt;class U1, class U2&gt;
tuple&amp; operator=(const pair&lt;U1, U2&gt;&amp;); <i>// only if sizeof...(Types) == 2</i>
template &lt;class U1, class U2&gt;
tuple&amp; operator=(pair&lt;U1, U2&gt;&amp;&amp;) <ins>noexcept(<i>see below</i>)</ins>; <i>// only if sizeof...(Types) == 2</i>
</pre>
</blockquote>
</li>

<li><p>Modify 22.4.4.2 <a href="https://wg21.link/tuple.cnstr">[tuple.cnstr]</a> as indicated:</p>

<blockquote>
<pre>
template &lt;class... UTypes&gt; <i>EXPLICIT</i> constexpr tuple(UTypes&amp;&amp;... u) <ins>noexcept(<i>see below</i>)</ins>;
</pre>
<blockquote>
<p>
-8- <i>Effects:</i> Initializes the elements in the tuple with the corresponding value in <code>std::forward&lt;UTypes&gt;(u)</code>.
<p/>
-9- <i>Remarks:</i> This constructor shall not participate in overload resolution unless <code>sizeof...(Types) ==
sizeof...(UTypes)</code> and <code>sizeof...(Types) >= 1</code> and <code>is_constructible_v&lt;T<sub><i>i</i></sub>, 
U<sub><i>i</i></sub>&amp;&amp;&gt;</code> is <code>true</code> for all <code><i>i</i></code>. The constructor is explicit if and only if 
<code>is_convertible_v&lt;U<sub><i>i</i></sub>&amp;&amp;, T<sub><i>i</i></sub>&gt;</code> is <code>false</code> for at least one 
<code><i>i</i></code>. <ins>The expression inside <code>noexcept</code> is equivalent to the logical AND of the following expressions:</ins>
</p>
<blockquote><pre>
<ins>is_nothrow_constructible_v&lt;T<sub><i>i</i></sub>, U<sub><i>i</i></sub>&amp;&amp;&gt;</ins>
</pre></blockquote>
<p>
<ins>where <code>T<sub><i>i</i></sub></code> is the <code><i>i</i></code><sup>th</sup> type in <code>Types</code>, and
<code>U<sub><i>i</i></sub></code> is the <code><i>i</i></code><sup>th</sup> type in <code>UTypes</code>.</ins>
</p>
</blockquote>
<p>
[&hellip;]
</p>
<pre>
template &lt;class... UTypes&gt; <i>EXPLICIT</i> constexpr tuple(tuple&lt;UTypes...&gt;&amp;&amp; u) <ins>noexcept(<i>see below</i>)</ins>;
</pre>
<blockquote>
<p>
-16- <i>Effects:</i> For all <code><i>i</i></code>, initializes the <code><i>i</i></code><sup>th</sup> element of <code>*this</code> with 
<code>std::forward&lt;U<sub><i>i</i></sub>&gt;(get&lt;<i>i</i>&gt;(u))</code>.
<p/>
-17- <i>Remarks:</i> This constructor shall not participate in overload resolution unless
<p/>
[&hellip;]
<p/>
The constructor is explicit if and only if <code>is_convertible_v&lt;U<sub><i>i</i></sub>&amp;&amp;, T<sub><i>i</i></sub>&gt;</code> 
is <code>false</code> for at least one <code><i>i</i></code>. <ins>The expression inside <code>noexcept</code> is equivalent to the logical AND of the following expressions:</ins>
</p>
<blockquote><pre>
<ins>is_nothrow_constructible_v&lt;T<sub><i>i</i></sub>, U<sub><i>i</i></sub>&amp;&amp;&gt;</ins>
</pre></blockquote>
<p>
<ins>where <code>T<sub><i>i</i></sub></code> is the <code><i>i</i></code><sup>th</sup> type in <code>Types</code>, and
<code>U<sub><i>i</i></sub></code> is the <code><i>i</i></code><sup>th</sup> type in <code>UTypes</code>.</ins>
</p>
</blockquote>
<p>
[&hellip;]
</p>
<pre>
template &lt;class U1, class U2&gt; <i>EXPLICIT</i> constexpr tuple(pair&lt;U1, U2&gt;&amp;&amp; u) <ins>noexcept(<i>see below</i>)</ins>;
</pre>
<blockquote>
<p>
-21- <i>Effects:</i> Initializes the first element with <code>std::forward&lt;U1&gt;(u.first)</code> and the second element with
<code>std::forward&lt;U2&gt;(u.second)</code>.
<p/>
-22- <i>Remarks:</i> This constructor shall not participate in overload resolution unless <code>sizeof...(Types) == 2</code>,
<code>is_constructible_v&lt;T0, U1&amp;&amp;&gt;</code> is <code>true</code> and <code>is_constructible_v&lt;T1, U2&amp;&amp;&gt;</code> is <code>true</code>.
<p/>
-23- The constructor is explicit if and only if <code>is_convertible_v&lt;U1&amp;&amp;, T0&gt;</code> is <code>false</code> or 
<code>is_convertible_v&lt;U2&amp;&amp;, T1&gt;</code> is <code>false</code>. <ins>The expression inside <code>noexcept</code> is equivalent to:</ins>
</p>
<blockquote><pre>
<ins>is_nothrow_constructible_v&lt;T0, U1&amp;&amp;&gt; &amp;&amp; is_nothrow_constructible_v&lt;T1, U2&amp;&amp;&gt;</ins>
</pre></blockquote>
</blockquote>
</blockquote>
</li>

<li><p>Modify 22.4.4.3 <a href="https://wg21.link/tuple.assign">[tuple.assign]</a> as indicated:</p>

<blockquote>
<pre>
template &lt;class... UTypes&gt; tuple&amp; operator=(tuple&lt;UTypes...&gt;&amp;&amp; u) <ins>noexcept(<i>see below</i>)</ins>;
</pre>
<blockquote>
<p>
-12- <i>Effects:</i> For all <code><i>i</i></code>, assigns <code>std::forward&lt;U<sub><i>i</i></sub>&gt;(get&lt;<i>i</i>&gt;(u))</code> 
to <code>get&lt;<i>i</i>&gt;(*this)</code>.
<p/>
-13- <i>Remarks:</i> This operator shall not participate in overload resolution unless <code>is_assignable_v&lt;T<sub><i>i</i></sub>&amp;, 
U<sub><i>i</i></sub>&amp;&amp;&gt; == true</code> for all <code><i>i</i></code> and <code>sizeof...(Types) == sizeof...(UTypes)</code>.
<ins>The expression inside <code>noexcept</code> is equivalent to the logical AND of the following expressions:</ins>
</p>
<blockquote><pre>
<ins>is_nothrow_assignable_v&lt;T<sub><i>i</i></sub>&amp;, U<sub><i>i</i></sub>&amp;&amp;&gt;</ins>
</pre></blockquote>
<p>
<ins>where <code>T<sub><i>i</i></sub></code> is the <code><i>i</i></code><sup>th</sup> type in <code>Types</code>, and
<code>U<sub><i>i</i></sub></code> is the <code><i>i</i></code><sup>th</sup> type in <code>UTypes</code>.</ins>
</p>
<p>
-14- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<p>
[&hellip;]
</p>
<pre>
template &lt;class U1, class U2&gt; tuple&amp; operator=(pair&lt;U1, U2&gt;&amp;&amp; u) <ins>noexcept(<i>see below</i>)</ins>;
</pre>
<blockquote>
<p>
-18- <i>Effects:</i> Assigns <code>std::forward&lt;U1&gt;(u.first)</code> to the first element of <code>*this</code> and
<code>std::forward&lt;U2&gt;(u.second)</code> to the second element of <code>*this</code>.
<p/>
-19- <i>Remarks:</i> This operator shall not participate in overload resolution unless <code>sizeof...(Types) == 2</code>
and <code>is_assignable_v&lt;T0&amp;, U1&amp;&amp;&gt;</code> is <code>true</code> for the first type <code>T0</code> in <code>Types</code> 
and <code>is_assignable_v&lt;T1&amp;, U2&amp;&amp;&gt;</code> is <code>true</code> for the second type <code>T1</code> in <code>Types</code>.
<ins>The expression inside <code>noexcept</code> is equivalent to:</ins>
</p>
<blockquote><pre>
<ins>is_nothrow_assignable_v&lt;T0&amp;, U1&amp;&amp;&gt; &amp;&amp; is_nothrow_assignable_v&lt;T1&amp;, U2&amp;&amp;&gt;</ins>
</pre></blockquote>
<p>
-20- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2019-02-14; Jonathan comments and provides revised wording]</i></p>

<p>
The suggested change was already made to <code>std::optional</code> by LWG <a href="lwg-defects.html#2756" title="C++ WP optional&lt;T&gt; should 'forward' T's implicit conversions (Status: C++17)">2756</a><sup><a href="https://cplusplus.github.io/LWG/issue2756" title="Latest snapshot">(i)</a></sup>. The current P/R for 2899 
doesn't resolve the issue for <code>std::tuple</code> or <code>std::unique_ptr</code>. I hope the following alternative does.
</p>

<p><i>[2019-02; Kona Wednesday night issue processing]</i></p>

<p>Status to Ready</p>


<p id="res-2899"><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.4.4.2 <a href="https://wg21.link/tuple.cnstr">[tuple.cnstr]</a> as indicated:</p>

<blockquote>
<pre>
tuple(tuple&amp;&amp; u) = default;
</pre>
<blockquote>
<p>
-13- <i><del>Requires</del><ins>Constraints</ins>:</i> <code>is_move_constructible_v&lt;T<sub><i>i</i></sub>&gt;</code> 
is <code>true</code> for all <code><i>i</i></code>.
<p/>
-14- <i>Effects:</i> For all <code><i>i</i></code>, initializes the <code><i>i</i></code><sup>th</sup> element of 
<code>*this</code> with <code>std::forward&lt;T<sub><i>i</i></sub>&gt;(get&lt;<i>i</i>&gt;(u))</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Modify 20.3.1.3.2 <a href="https://wg21.link/unique.ptr.single.ctor">[unique.ptr.single.ctor]</a> as indicated:</p>

<blockquote>
<pre>
unique_ptr(unique_ptr&amp;&amp; u) noexcept;
</pre>
<blockquote>
<p>
<ins>-?- <i>Constraints:</i> <code>is_move_constructible_v&lt;D&gt;</code> is <code>true</code>.</ins>
<p/>
-15- <i>Requires:</i> If <code>D</code> is not a reference type, <code>D</code> shall satisfy the 
<i>Cpp17MoveConstructible</i> requirements (Table 26). Construction of the deleter from an 
rvalue of type <code>D</code> shall not throw an exception.
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>

<li><p>Modify 20.3.1.3.4 <a href="https://wg21.link/unique.ptr.single.asgn">[unique.ptr.single.asgn]</a> as indicated:</p>

<blockquote>
<pre>
unique_ptr&amp; operator=(unique_ptr&amp;&amp; u) noexcept;
</pre>
<blockquote>
<p>
<ins>-?- <i>Constraints:</i> <code>is_move_assignable_v&lt;D&gt;</code> is <code>true</code>.</ins>
<p/>
-1- <i>Requires:</i> If <code>D</code> is not a reference type, <code>D</code> shall satisfy the 
<i>Cpp17MoveAssignable</i> requirements (Table 28) and assignment of the deleter from an 
rvalue of type <code>D</code> shall not throw an exception. Otherwise, <code>D</code> is a reference 
type; <code>remove_reference_t&lt;D&gt;</code> shall satisfy the <i>Cpp17CopyAssignable</i> 
requirements and assignment of the deleter from an lvalue of type <code>D</code> shall not throw an exception.
<p/>
-2- <i>Effects:</i> Calls <code>reset(u.release())</code> followed by <code>get_deleter() = std::forward&lt;D&gt;(u.get_deleter())</code>.
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
