forked from lwg/issues
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New issue from Hewill Kang: "Issues with join_with_view::iterator's i…
…ter_swap"
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version='1.0' encoding='utf-8' standalone='no'?> | ||
<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> | ||
|
||
<issue num="3972" status="New"> | ||
<title>Issues with <tt>join_with_view::<i>iterator</i></tt>'s <tt>iter_swap</tt></title> | ||
<section><sref ref="[range.join.with.iterator]"/></section> | ||
<submitter>Hewill Kang</submitter> | ||
<date>04 Sep 2023</date> | ||
<priority>99</priority> | ||
|
||
<discussion> | ||
<p> | ||
The <tt>iter_swap</tt> customization for <tt>join_with_view::<i>iterator</i></tt> allows swapping iterators | ||
with different element types, potentially leading to unsafe behavior, <a href="https://godbolt.org/z/5qzGb881x">for example</a>: | ||
</p> | ||
<blockquote> | ||
<pre> | ||
vector<vector<string>> x{{"a"}, {"b"}, {"c"}}; | ||
vector<string_view> y{"-"}; | ||
auto r = x | views::join_with(y); | ||
auto i = r.begin(); | ||
auto j = ranges::next(i); | ||
ranges::iter_swap(j, i); | ||
for (auto&& elem : r) | ||
cout << elem << " "; // <span style="color:red;font-weight:bolder">AddressSanitizer: stack-use-after-return on address</span> | ||
</pre> | ||
</blockquote> | ||
<p> | ||
The above swaps two iterators whose reference are <tt>string_view&</tt> and <tt>string&</tt> respectively, | ||
which ultimately results in <tt>string_view</tt> being referenced to a local variable and left dangling. | ||
</p> | ||
</discussion> | ||
|
||
<resolution> | ||
|
||
</resolution> | ||
|
||
</issue> |