Skip to content

Commit 4aaba2f

Browse files
committed
New issue from Jiang An: "std::optional<T&>::swap possibly selects ADL-found swap"
1 parent c93d1ef commit 4aaba2f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

xml/issue4439.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4439" status="New">
5+
<title><tt>std::optional&lt;T&amp;&gt;::swap</tt> possibly selects ADL-found `swap`</title>
6+
<section><sref ref="[optional.ref.swap]"/></section>
7+
<submitter>Jiang An</submitter>
8+
<date>31 Oct 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
Currently, <sref ref="[optional.ref.swap]"/> p1 specifies an "unqualified" `swap` call, which
14+
possibly selects an ADL-found swap function due to <sref ref="[contents]"/> and
15+
<sref ref="[swappable.requirements]"/>.
16+
<p/>
17+
It's unlike to be intentional to call ADL-found `swap` on pointers (given `ranges::swap`
18+
doesn't), and the unconditional `noexcept` also suggests that user-provided `swap` functions
19+
shouldn't interfere with <tt>optional&lt;T&amp;&gt;::swap</tt>.
20+
</p>
21+
</discussion>
22+
23+
<resolution>
24+
<p>
25+
This wording is relative to <paper num="N5014"/>.
26+
</p>
27+
28+
<ol>
29+
30+
<li><p>Modify <sref ref="[optional.ref.swap]"/> as indicated:</p>
31+
32+
<blockquote>
33+
<pre>
34+
constexpr void swap(optional&amp; rhs) noexcept;
35+
</pre>
36+
<blockquote>
37+
<p>
38+
-1- <i>Effects</i>: Equivalent to: <tt><ins>std::</ins>swap(<i>val</i>, rhs.<i>val</i>)</tt>.
39+
</p>
40+
</blockquote>
41+
</blockquote>
42+
</li>
43+
</ol>
44+
45+
</resolution>
46+
47+
</issue>

0 commit comments

Comments
 (0)