Skip to content

Commit 0d5580c

Browse files
committed
New issue from Jiang An: "Should swapping a built-in array or std::array with itself result in UB?"
1 parent b4d49f7 commit 0d5580c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

xml/issue4165.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4165" status="New">
5+
<title>Should swapping a built-in array or `std::array` with itself result in UB?</title>
6+
<section><sref ref="[concept.swappable]"/><sref ref="[utility.swap]"/><sref ref="[array.members]"/></section>
7+
<submitter>Jiang An</submitter>
8+
<date>13 Oct 2024</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
Currently, the `std::swap` overload for built-in arrays, the `swap` member function of
14+
`std::array`, the `std::swap` overload for `std::array`, and the expression-equivalent-to
15+
operation of `std::ranges::swap` for built-in arrays are specified to be equivalent to performing
16+
`std::(ranges::)swap_ranges`. As `swap_ranges` functions require that the swapped ranges shall
17+
not overlap (<sref ref="[alg.swap]"/>/2), swapping a built-in array or a nonzero-length
18+
<tt>std::array</tt> with itself results in undefined behavior.
19+
<p/>
20+
It seems that no other swap operation in the standard library has precondition that both arguments
21+
don't refer to the same object. Should we make self-swapping of arrays well-defined? If so,
22+
perhaps we should change the semantics to plain loops that execute `swap` or `ranges::swap` on
23+
elements.
24+
</p>
25+
</discussion>
26+
27+
<resolution>
28+
</resolution>
29+
30+
</issue>

0 commit comments

Comments
 (0)