|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4026" status="New"> |
| 5 | +<title>Assignment operators of <tt>std::expected</tt> should propagate triviality</title> |
| 6 | +<section><sref ref="[expected.object.assign]"/><sref ref="[expected.void.assign]"/></section> |
| 7 | +<submitter>Jiang An</submitter> |
| 8 | +<date>16 Dec 2023</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +Currently, only copy and move constructors of <tt>std::expected</tt> are required to propagate triviality, |
| 14 | +while copy and move assignment operators are not. Given that the assignment operators of <tt>std::optional</tt> |
| 15 | +and <tt>std::variant</tt> are already required to propagate triviality, it seems to me that we should also |
| 16 | +apply such requirements for <tt>std::expected</tt>. |
| 17 | +<p/> |
| 18 | +Such changes are being made in libc++ (<a href="https://github.com/llvm/llvm-project/pull/74768">llvm/llvm-project#74768</a>). |
| 19 | +And it may be desired to make the triviality improvement portable. |
| 20 | +</p> |
| 21 | +</discussion> |
| 22 | + |
| 23 | +<resolution> |
| 24 | +<p> |
| 25 | +This wording is relative to <paper num="N4971"/>. |
| 26 | +</p> |
| 27 | + |
| 28 | +<ol> |
| 29 | + |
| 30 | +<li><p>Modify <sref ref="[expected.object.assign]"/> as indicated:</p> |
| 31 | + |
| 32 | +<blockquote> |
| 33 | +<pre> |
| 34 | +constexpr expected& operator=(const expected& rhs); |
| 35 | +</pre> |
| 36 | +<blockquote> |
| 37 | +<p> |
| 38 | +-2- <i>Effects</i>: […] |
| 39 | +<p/> |
| 40 | +[…] |
| 41 | +<p/> |
| 42 | +-4- <i>Remarks</i>: This operator is defined as deleted unless: |
| 43 | +</p> |
| 44 | +<ol style="list-style-type: none"> |
| 45 | +<li><p>[…]</p></li> |
| 46 | +</ol> |
| 47 | +<p> |
| 48 | +<ins>-?- This operator is trivial if:</ins> |
| 49 | +</p> |
| 50 | +<ol style="list-style-type: none"> |
| 51 | +<li><p><ins>(?.1) — <tt>is_trivially_copy_constructible_v<T></tt> is <tt>true</tt>, and</ins></p></li> |
| 52 | +<li><p><ins>(?.2) — <tt>is_trivially_copy_assignable_v<T></tt> is <tt>true</tt>, and</ins></p></li> |
| 53 | +<li><p><ins>(?.3) — <tt>is_trivially_destructible_v<T></tt> is <tt>true</tt>, and</ins></p></li> |
| 54 | +<li><p><ins>(?.4) — <tt>is_trivially_copy_constructible_v<E></tt> is <tt>true</tt>, and</ins></p></li> |
| 55 | +<li><p><ins>(?.5) — <tt>is_trivially_copy_assignable_v<E></tt> is <tt>true</tt>, and</ins></p></li> |
| 56 | +<li><p><ins>(?.6) — <tt>is_trivially_destructible_v<E></tt> is <tt>true</tt>.</ins></p></li> |
| 57 | +</ol> |
| 58 | +</blockquote> |
| 59 | +<pre> |
| 60 | +constexpr expected& operator=(expected&& rhs) noexcept(<i>see below</i>); |
| 61 | +</pre> |
| 62 | +<blockquote> |
| 63 | +<p> |
| 64 | +-5- <i>Constraints</i>: […] |
| 65 | +<p/> |
| 66 | +[…] |
| 67 | +<p/> |
| 68 | +-8- <i>Remarks</i>: The exception specification is equivalent to: |
| 69 | +<p/> |
| 70 | +[…] |
| 71 | +</p> |
| 72 | +<p> |
| 73 | +<ins>-?- This operator is trivial if:</ins> |
| 74 | +</p> |
| 75 | +<ol style="list-style-type: none"> |
| 76 | +<li><p><ins>(?.1) — <tt>is_trivially_move_constructible_v<T></tt> is <tt>true</tt>, and</ins></p></li> |
| 77 | +<li><p><ins>(?.2) — <tt>is_trivially_move_assignable_v<T></tt> is <tt>true</tt>, and</ins></p></li> |
| 78 | +<li><p><ins>(?.3) — <tt>is_trivially_destructible_v<T></tt> is <tt>true</tt>, and</ins></p></li> |
| 79 | +<li><p><ins>(?.4) — <tt>is_trivially_move_constructible_v<E></tt> is <tt>true</tt>, and</ins></p></li> |
| 80 | +<li><p><ins>(?.5) — <tt>is_trivially_move_assignable_v<E></tt> is <tt>true</tt>, and</ins></p></li> |
| 81 | +<li><p><ins>(?.6) — <tt>is_trivially_destructible_v<E></tt> is <tt>true</tt>.</ins></p></li> |
| 82 | +</ol> |
| 83 | + |
| 84 | +</blockquote> |
| 85 | +</blockquote> |
| 86 | +</li> |
| 87 | + |
| 88 | +<li><p>Modify <sref ref="[expected.void.assign]"/> as indicated:</p> |
| 89 | + |
| 90 | +<blockquote> |
| 91 | +<pre> |
| 92 | +constexpr expected& operator=(const expected& rhs); |
| 93 | +</pre> |
| 94 | +<blockquote> |
| 95 | +<p> |
| 96 | +-1- <i>Effects</i>: […] |
| 97 | +<p/> |
| 98 | +[…] |
| 99 | +<p/> |
| 100 | +-3- <i>Remarks</i>: This operator is defined as deleted unless <tt>is_copy_assignable_v<E></tt> |
| 101 | +is <tt>true</tt> and <tt>is_copy_constructible_v<E></tt> is <tt>true</tt>. |
| 102 | +<p/> |
| 103 | +<ins>-?- This operator is trivial if <tt>is_trivially_copy_constructible_v<E></tt>, |
| 104 | +<tt>is_trivially_copy_assignable_v<E></tt>, and <tt>is_trivially_destructible_v<E></tt> are |
| 105 | +all <tt>true</tt>.</ins> |
| 106 | +</p> |
| 107 | +</blockquote> |
| 108 | +<pre> |
| 109 | +constexpr expected& operator=(expected&& rhs) noexcept(<i>see below</i>); |
| 110 | +</pre> |
| 111 | +<blockquote> |
| 112 | +<p> |
| 113 | +-4- <i>Effects</i>: […] |
| 114 | +<p/> |
| 115 | +[…] |
| 116 | +<p/> |
| 117 | +-6- <i>Remarks</i>: The exception specification is equivalent to <tt>is_nothrow_move_constructible_v<E> && |
| 118 | +is_nothrow_move_assignable_v<E></tt>. |
| 119 | +<p/> |
| 120 | +-7- This operator is defined as deleted unless <tt>is_move_constructible_v<E></tt> is <tt>true</tt> |
| 121 | +and <tt>is_move_assignable_v<E></tt> is <tt>true</tt>. |
| 122 | +<p/> |
| 123 | +<ins>-?- This operator is trivial if <tt>is_trivially_move_constructible_v<E></tt>, |
| 124 | +<tt>is_trivially_move_assignable_v<E></tt>, and <tt>is_trivially_destructible_v<E></tt> are |
| 125 | +all <tt>true</tt>.</ins> |
| 126 | +</p> |
| 127 | + |
| 128 | +</blockquote> |
| 129 | +</blockquote> |
| 130 | +</li> |
| 131 | + |
| 132 | +</ol> |
| 133 | + |
| 134 | + |
| 135 | +</resolution> |
| 136 | + |
| 137 | +</issue> |
0 commit comments