<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3972: Issues with join_with_view::iterator's iter_swap</title>
<meta property="og:title" content="Issue 3972: Issues with join_with_view::iterator's iter_swap">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3972.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<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>
<h3 id="3972"><a href="lwg-active.html#3972">3972</a>. Issues with <code>join_with_view::<i>iterator</i></code>'s <code>iter_swap</code></h3>
<p><b>Section:</b> 25.7.15.3 <a href="https://wg21.link/range.join.with.iterator">[range.join.with.iterator]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Hewill Kang <b>Opened:</b> 2023-09-04 <b>Last modified:</b> 2023-11-03</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#range.join.with.iterator">active issues</a> in [range.join.with.iterator].</p>
<p><b>View all other</b> <a href="lwg-index.html#range.join.with.iterator">issues</a> in [range.join.with.iterator].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The <code>iter_swap</code> customization for <code>join_with_view::<i>iterator</i></code> 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&lt;vector&lt;string&gt;&gt; x{{"a"}, {"b"}, {"c"}};
vector&lt;string_view&gt;    y{"-"};
auto r = x | views::join_with(y);
auto i = r.begin();
auto j = ranges::next(i);
ranges::iter_swap(j, i);
for (auto&amp;&amp; elem : r)
  cout &lt;&lt; elem &lt;&lt; " "; // <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 <code>string_view&amp;</code> and <code>string&amp;</code> respectively, 
which ultimately results in <code>string_view</code> being referenced to a local variable and left dangling.
</p>

<p><i>[2023-11-02; Reflector poll]</i></p>

<p>
Set priority to 2 after reflector poll.
</p>



<p id="res-3972"><b>Proposed resolution:</b></p>






</body>
</html>
