Skip to content

Commit 52903cf

Browse files
committed
New issue from Jiang An: "Assignment operators of std::expected should propagate triviality"
1 parent 53249bb commit 52903cf

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

xml/issue4026.xml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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&amp; operator=(const expected&amp; rhs);
35+
</pre>
36+
<blockquote>
37+
<p>
38+
-2- <i>Effects</i>: [&hellip;]
39+
<p/>
40+
[&hellip;]
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>[&hellip;]</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) &mdash; <tt>is_trivially_copy_constructible_v&lt;T&gt;</tt> is <tt>true</tt>, and</ins></p></li>
52+
<li><p><ins>(?.2) &mdash; <tt>is_trivially_copy_assignable_v&lt;T&gt;</tt> is <tt>true</tt>, and</ins></p></li>
53+
<li><p><ins>(?.3) &mdash; <tt>is_trivially_destructible_v&lt;T&gt;</tt> is <tt>true</tt>, and</ins></p></li>
54+
<li><p><ins>(?.4) &mdash; <tt>is_trivially_copy_constructible_v&lt;E&gt;</tt> is <tt>true</tt>, and</ins></p></li>
55+
<li><p><ins>(?.5) &mdash; <tt>is_trivially_copy_assignable_v&lt;E&gt;</tt> is <tt>true</tt>, and</ins></p></li>
56+
<li><p><ins>(?.6) &mdash; <tt>is_trivially_destructible_v&lt;E&gt;</tt> is <tt>true</tt>.</ins></p></li>
57+
</ol>
58+
</blockquote>
59+
<pre>
60+
constexpr expected&amp; operator=(expected&amp;&amp; rhs) noexcept(<i>see below</i>);
61+
</pre>
62+
<blockquote>
63+
<p>
64+
-5- <i>Constraints</i>: [&hellip;]
65+
<p/>
66+
[&hellip;]
67+
<p/>
68+
-8- <i>Remarks</i>: The exception specification is equivalent to:
69+
<p/>
70+
[&hellip;]
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) &mdash; <tt>is_trivially_move_constructible_v&lt;T&gt;</tt> is <tt>true</tt>, and</ins></p></li>
77+
<li><p><ins>(?.2) &mdash; <tt>is_trivially_move_assignable_v&lt;T&gt;</tt> is <tt>true</tt>, and</ins></p></li>
78+
<li><p><ins>(?.3) &mdash; <tt>is_trivially_destructible_v&lt;T&gt;</tt> is <tt>true</tt>, and</ins></p></li>
79+
<li><p><ins>(?.4) &mdash; <tt>is_trivially_move_constructible_v&lt;E&gt;</tt> is <tt>true</tt>, and</ins></p></li>
80+
<li><p><ins>(?.5) &mdash; <tt>is_trivially_move_assignable_v&lt;E&gt;</tt> is <tt>true</tt>, and</ins></p></li>
81+
<li><p><ins>(?.6) &mdash; <tt>is_trivially_destructible_v&lt;E&gt;</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&amp; operator=(const expected&amp; rhs);
93+
</pre>
94+
<blockquote>
95+
<p>
96+
-1- <i>Effects</i>: [&hellip;]
97+
<p/>
98+
[&hellip;]
99+
<p/>
100+
-3- <i>Remarks</i>: This operator is defined as deleted unless <tt>is_copy_assignable_v&lt;E&gt;</tt>
101+
is <tt>true</tt> and <tt>is_copy_constructible_v&lt;E&gt;</tt> is <tt>true</tt>.
102+
<p/>
103+
<ins>-?- This operator is trivial if <tt>is_trivially_copy_constructible_v&lt;E&gt;</tt>,
104+
<tt>is_trivially_copy_assignable_v&lt;E&gt;</tt>, and <tt>is_trivially_destructible_v&lt;E&gt;</tt> are
105+
all <tt>true</tt>.</ins>
106+
</p>
107+
</blockquote>
108+
<pre>
109+
constexpr expected&amp; operator=(expected&amp;&amp; rhs) noexcept(<i>see below</i>);
110+
</pre>
111+
<blockquote>
112+
<p>
113+
-4- <i>Effects</i>: [&hellip;]
114+
<p/>
115+
[&hellip;]
116+
<p/>
117+
-6- <i>Remarks</i>: The exception specification is equivalent to <tt>is_nothrow_move_constructible_v&lt;E&gt; &amp;&amp;
118+
is_nothrow_move_assignable_v&lt;E&gt;</tt>.
119+
<p/>
120+
-7- This operator is defined as deleted unless <tt>is_move_constructible_v&lt;E&gt;</tt> is <tt>true</tt>
121+
and <tt>is_move_assignable_v&lt;E&gt;</tt> is <tt>true</tt>.
122+
<p/>
123+
<ins>-?- This operator is trivial if <tt>is_trivially_move_constructible_v&lt;E&gt;</tt>,
124+
<tt>is_trivially_move_assignable_v&lt;E&gt;</tt>, and <tt>is_trivially_destructible_v&lt;E&gt;</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

Comments
 (0)