Skip to content

Commit 2731df9

Browse files
author
github-actions
committed
Automatic update from GitHub Actions workflow
1 parent 45d2134 commit 2731df9

23 files changed

+981
-44
lines changed

issue4250.html

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Issue 4250: swap overloads for indirect and polymorphic only found by ADL</title>
6+
<meta property="og:title" content="Issue 4250: swap overloads for indirect and polymorphic only found by ADL">
7+
<meta property="og:description" content="C++ library issue. Status: New">
8+
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4250.html">
9+
<meta property="og:type" content="website">
10+
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
11+
<meta property="og:image:alt" content="C++ logo">
12+
<style>
13+
p {text-align:justify}
14+
li {text-align:justify}
15+
pre code.backtick::before { content: "`" }
16+
pre code.backtick::after { content: "`" }
17+
blockquote.note
18+
{
19+
background-color:#E0E0E0;
20+
padding-left: 15px;
21+
padding-right: 15px;
22+
padding-top: 1px;
23+
padding-bottom: 1px;
24+
}
25+
ins {background-color:#A0FFA0}
26+
del {background-color:#FFA0A0}
27+
table.issues-index { border: 1px solid; border-collapse: collapse; }
28+
table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
29+
table.issues-index td { padding: 4px; border: 1px solid; }
30+
table.issues-index td:nth-child(1) { text-align: right; }
31+
table.issues-index td:nth-child(2) { text-align: left; }
32+
table.issues-index td:nth-child(3) { text-align: left; }
33+
table.issues-index td:nth-child(4) { text-align: left; }
34+
table.issues-index td:nth-child(5) { text-align: center; }
35+
table.issues-index td:nth-child(6) { text-align: center; }
36+
table.issues-index td:nth-child(7) { text-align: left; }
37+
table.issues-index td:nth-child(5) span.no-pr { color: red; }
38+
@media (prefers-color-scheme: dark) {
39+
html {
40+
color: #ddd;
41+
background-color: black;
42+
}
43+
ins {
44+
background-color: #225522
45+
}
46+
del {
47+
background-color: #662222
48+
}
49+
a {
50+
color: #6af
51+
}
52+
a:visited {
53+
color: #6af
54+
}
55+
blockquote.note
56+
{
57+
background-color: rgba(255, 255, 255, .10)
58+
}
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
<hr>
64+
<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>
65+
<h3 id="4250"><a href="lwg-active.html#4250">4250</a>. <code class='backtick'>swap</code> overloads for <code class='backtick'>indirect</code> and <code class='backtick'>polymorphic</code> only found by ADL</h3>
66+
<p><b>Section:</b> 20.4.1.7 <a href="https://wg21.link/indirect.swap">[indirect.swap]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
67+
<b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2025-05-01 <b>Last modified:</b> 2025-05-01</p>
68+
<p><b>Priority: </b>Not Prioritized
69+
</p>
70+
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
71+
<p><b>Discussion:</b></p>
72+
<p>
73+
The non-member <code class='backtick'>swap</code> overloads for <code class='backtick'>std::indirect</code> and <code class='backtick'>std::polymorphic</code>
74+
are defined as hidden friends, so are only available via ADL.
75+
This means that calling <code class='backtick'>std::swap(i1, i2)</code> will always use the generic
76+
<code class='backtick'>std::swap</code> instead of the custom overload for <code class='backtick'>std::indirect</code>.
77+
</p>
78+
79+
80+
<p id="res-4250"><b>Proposed resolution:</b></p>
81+
<p>
82+
This wording is relative to <a href="https://wg21.link/N5008">N5008</a>.
83+
</p>
84+
<ol>
85+
86+
<li><p>Modify 20.2.2 <a href="https://wg21.link/memory.syn">[memory.syn]</a> as indicated:</p>
87+
88+
<blockquote>
89+
<pre><code>
90+
// 20.4.1, class template indirect
91+
template&lt;class T, class Allocator = allocator&lt;T&gt;&gt;
92+
class indirect;
93+
<ins>
94+
template&lt;class T, class Allocator&gt;
95+
constexpr void swap(indirect&lt;T, Allocator&gt;&amp; lhs, indirect&lt;T, Allocator&gt;&amp; rhs) noexcept(<i>see below</i>);
96+
</ins>
97+
// 20.4.1.10, hash support
98+
template&lt;class T, class Alloc&gt; struct hash&lt;indirect&lt;T, Alloc&gt;&gt;;
99+
100+
// 20.4.2, class template polymorphic
101+
template&lt;class T, class Allocator = allocator&lt;T&gt;&gt;
102+
class polymorphic;
103+
<ins>
104+
template&lt;class T, class Allocator&gt;
105+
constexpr void swap(polymorphic&lt;T, Allocator&gt;&amp; lhs, polymorphic&lt;T, Allocator&gt;&amp; rhs) noexcept(<i>see below</i>);
106+
</ins>
107+
</code></pre>
108+
</blockquote>
109+
</li>
110+
111+
<li><p>Modify 20.4.1.2 <a href="https://wg21.link/indirect.syn">[indirect.syn]</a> as indicated:</p>
112+
<blockquote>
113+
<pre><code>
114+
// 20.4.1.7, swap
115+
constexpr void swap(indirect&amp; other) noexcept(<i>see below</i>);
116+
<del>friend constexpr void swap(indirect&amp; lhs, indirect&amp; rhs) noexcept(<i>see below</i>);</del>
117+
</code></pre>
118+
</blockquote>
119+
</li>
120+
121+
<li><p>Modify 20.4.1.7 <a href="https://wg21.link/indirect.swap">[indirect.swap]</a> as indicated:</p>
122+
<blockquote>
123+
<pre><code>
124+
<ins>template&lt;class T, class Allocator&gt;</ins>
125+
constexpr void swap(indirect<ins>&lt;T, Allocator&gt;</ins>&amp; lhs, indirect<ins>&lt;T, Allocator&gt;</ins>&amp; rhs) noexcept(noexcept(lhs.swap(rhs)));
126+
</code></pre>
127+
<blockquote>-3- <i>Effects</i>: Equivalent to <code class='backtick'>lhs.swap(rhs)</code>.</blockquote>
128+
</blockquote>
129+
</li>
130+
131+
<li><p>Modify 20.4.2.2 <a href="https://wg21.link/polymorphic.syn">[polymorphic.syn]</a> as indicated:</p>
132+
<blockquote>
133+
<pre><code>
134+
// 20.4.2.7, swap
135+
constexpr void swap(polymorphic&amp; other) noexcept(<i>see below</i>);
136+
<del>friend constexpr void swap(polymorphic&amp; lhs, polymorphic&amp; rhs) noexcept(<i>see below</i>);</del>
137+
</code></pre>
138+
</blockquote>
139+
</li>
140+
141+
<li><p>Modify 20.4.2.7 <a href="https://wg21.link/polymorphic.swap">[polymorphic.swap]</a> as indicated:</p>
142+
<blockquote>
143+
<pre><code>
144+
<ins>template&lt;class T, class Allocator&gt;</ins>
145+
constexpr void swap(polymorphic<ins>&lt;T, Allocator&gt;</ins>&amp; lhs, polymorphic<ins>&lt;T, Allocator&gt;</ins>&amp; rhs) noexcept(noexcept(lhs.swap(rhs)));
146+
</code></pre>
147+
<blockquote>-3- <i>Effects</i>: Equivalent to <code class='backtick'>lhs.swap(rhs)</code>.</blockquote>
148+
</blockquote>
149+
</li>
150+
151+
</ol>
152+
153+
154+
155+
156+
157+
158+
</body>
159+
</html>

issue4251.html

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Issue 4251: Move assignment for indirect unnecessarily requires copy construction</title>
6+
<meta property="og:title" content="Issue 4251: Move assignment for indirect unnecessarily requires copy construction">
7+
<meta property="og:description" content="C++ library issue. Status: New">
8+
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4251.html">
9+
<meta property="og:type" content="website">
10+
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
11+
<meta property="og:image:alt" content="C++ logo">
12+
<style>
13+
p {text-align:justify}
14+
li {text-align:justify}
15+
pre code.backtick::before { content: "`" }
16+
pre code.backtick::after { content: "`" }
17+
blockquote.note
18+
{
19+
background-color:#E0E0E0;
20+
padding-left: 15px;
21+
padding-right: 15px;
22+
padding-top: 1px;
23+
padding-bottom: 1px;
24+
}
25+
ins {background-color:#A0FFA0}
26+
del {background-color:#FFA0A0}
27+
table.issues-index { border: 1px solid; border-collapse: collapse; }
28+
table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
29+
table.issues-index td { padding: 4px; border: 1px solid; }
30+
table.issues-index td:nth-child(1) { text-align: right; }
31+
table.issues-index td:nth-child(2) { text-align: left; }
32+
table.issues-index td:nth-child(3) { text-align: left; }
33+
table.issues-index td:nth-child(4) { text-align: left; }
34+
table.issues-index td:nth-child(5) { text-align: center; }
35+
table.issues-index td:nth-child(6) { text-align: center; }
36+
table.issues-index td:nth-child(7) { text-align: left; }
37+
table.issues-index td:nth-child(5) span.no-pr { color: red; }
38+
@media (prefers-color-scheme: dark) {
39+
html {
40+
color: #ddd;
41+
background-color: black;
42+
}
43+
ins {
44+
background-color: #225522
45+
}
46+
del {
47+
background-color: #662222
48+
}
49+
a {
50+
color: #6af
51+
}
52+
a:visited {
53+
color: #6af
54+
}
55+
blockquote.note
56+
{
57+
background-color: rgba(255, 255, 255, .10)
58+
}
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
<hr>
64+
<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>
65+
<h3 id="4251"><a href="lwg-active.html#4251">4251</a>. Move assignment for <code class='backtick'>indirect</code> unnecessarily requires copy construction</h3>
66+
<p><b>Section:</b> 20.4.1.5 <a href="https://wg21.link/indirect.asgn">[indirect.asgn]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
67+
<b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2025-05-01 <b>Last modified:</b> 2025-05-01</p>
68+
<p><b>Priority: </b>Not Prioritized
69+
</p>
70+
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
71+
<p><b>Discussion:</b></p>
72+
<p>
73+
The move assignment operator for <code class='backtick'>indirect</code> says:
74+
<blockquote>
75+
<i>Mandates</i>: <code>is_copy_constructible_t&lt;T&gt;</code> is <code class='backtick'>true</code>.
76+
</blockquote>
77+
78+
However, the only way it ever construct an object is:
79+
<blockquote>
80+
constructs a new owned object with the owned object of <code class='backtick'>other</code> as the argument
81+
as an rvalue
82+
</blockquote>
83+
and that only ever happens when <code><i>alloc</i> == other.<i>alloc</i></code>
84+
is false.
85+
</p>
86+
<p>
87+
It seems like we should require <code class='backtick'>is_move_constructible_v</code> instead,
88+
and only if the allocator traits mean we need to construct an object.
89+
</p>
90+
<p>
91+
Additionally, the noexcept-specifier for the move assignment doesn't match
92+
the effects. The noexcept-specifier says it can't throw if POCMA is true,
93+
but nothing in the effects says that ownership can be transferred in that case.
94+
We only do a non-throwing transfer when the allocators are equal.
95+
I think we should also transfer ownership when
96+
</p>
97+
98+
99+
<p id="res-4251"><b>Proposed resolution:</b></p>
100+
<p>
101+
This wording is relative to <a href="https://wg21.link/N5008">N5008</a>.
102+
</p>
103+
<ol>
104+
105+
<li><p>Modify 20.4.1.5 <a href="https://wg21.link/indirect.asgn">[indirect.asgn]</a> as indicated:</p>
106+
<blockquote>
107+
<pre><code>
108+
constexpr indirect&amp; operator=(indirect&amp;&amp; other)
109+
noexcept(allocator_traits&lt;Allocator&gt;::propagate_on_container_move_assignment::value ||
110+
allocator_traits&lt;Allocator&gt;::is_always_equal::value);
111+
</code></pre>
112+
<blockquote>
113+
<p>
114+
-5- <i>Mandates</i>:
115+
<ins>
116+
If
117+
<code>allocator_traits&lt;Allocator&gt;::propagate_on_container_move_assignment::value</code>
118+
is <code class='backtick'>false</code>
119+
and
120+
<code>allocator_traits&lt;Allocator&gt;::is_always_equal::value</code>
121+
is <code class='backtick'>false</code>,
122+
</ins>
123+
<code>is_<del>copy</del><ins>move</ins>_constructible_t&lt;T&gt;</code> is <code class='backtick'>true</code>.
124+
</p>
125+
<p>
126+
-6- <i>Effects</i>:
127+
If <code class='backtick'>addressof(other) == this</code> is <code class='backtick'>true</code>, there are no effects.
128+
Otherwise:
129+
<ol style="list-style-type:none">
130+
<li>(6.1) &mdash;
131+
The allocator needs updating if
132+
<code>allocator_traits&lt;Allocator&gt;::propagate_on_container_move_assignment::value</code>
133+
is <code class='backtick'>true</code>.
134+
</li>
135+
<li>(6.2) &mdash;
136+
If <code class='backtick'>other</code> is valueless, <code class='backtick'>*this</code> becomes valueless<del> and the owned object
137+
in <code class='backtick'>*this</code>, if any, is destroyed using
138+
<code>allocator_traits&lt;Allocator&gt;::destroy</code>
139+
and then the storage is deallocated</del>.
140+
</li>
141+
<li>(6.3) &mdash;
142+
Otherwise,
143+
<ins>if the allocator needs updating or</ins>
144+
if <code><i>alloc</i> == other.<i>alloc</i></code> is <code class='backtick'>true</code>,
145+
<del>
146+
swaps the owned objects in <code class='backtick'>*this</code> and <code class='backtick'>other</code>;
147+
the owned object in <code class='backtick'>other</code>, if any, is then destroyed using
148+
<code>allocator_traits&lt;Allocator&gt;::destroy</code>
149+
and then the storage is deallocated
150+
</del>
151+
<ins><code class='backtick'>*this</code> takes ownership of the owned object of <code class='backtick'>other</code></ins>.
152+
</li>
153+
<li>(6.4) &mdash;
154+
Otherwise, constructs a new owned object with the owned object of <code class='backtick'>other</code>
155+
as the argument as an rvalue, using either the allocator in <code class='backtick'>*this</code>
156+
or the allocator in <code class='backtick'>other</code> if the allocator needs updating.
157+
</li>
158+
<li>(6.5) &mdash;
159+
The previously owned object in <code class='backtick'>*this</code>, if any, is destroyed using
160+
<code>allocator_traits&lt;Allocator&gt;::destroy</code>
161+
and then the storage is deallocated.
162+
</li>
163+
<li>(6.6) &mdash;
164+
If the allocator needs updating,
165+
the allocator in <code class='backtick'>*this</code> is replaced with a copy of the allocator in <code class='backtick'>other</code>.
166+
</li>
167+
</ol>
168+
</p>
169+
<p>-7- <i>Postcondition</i>: <code class='backtick'>other</code> is valueless.</p>
170+
</blockquote>
171+
</blockquote>
172+
</li>
173+
</ol>
174+
175+
176+
177+
178+
179+
</body>
180+
</html>

0 commit comments

Comments
 (0)