Skip to content

Commit

Permalink
New issue from Barry: "Reversing an infinite range leads to an infini…
Browse files Browse the repository at this point in the history
…te loop"
  • Loading branch information
Dani-Hub committed Nov 25, 2023
1 parent 123ed37 commit 909cdff
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions xml/issue4019.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">

<issue num="4019" status="New">
<title>Reversing an infinite range leads to an infinite loop</title>
<section><sref ref="[range.reverse]"/></section>
<submitter>Barry Revzin</submitter>
<date>25 Nov 2023</date>
<priority>99</priority>

<discussion>
<p>
Consider the following:
</p>
<blockquote><pre>
auto a = views::iota(0) | views::reverse;
auto b = views::repeat(42) | views::reverse;
</pre></blockquote>
<p>
Here, <tt>views::iota(0)</tt> and <tt>views::repeat(42)</tt> are both non-common bidirectional (even random-access) ranges.
They are also infinite ranges, even if the standard doesn't really recognize that.
<p/>
<tt>views::reverse</tt> on a non-common range will actually compute the end iterator for you. So while both declarations
of <tt>a</tt> and <tt>b</tt> above compile, attempting to use either in any way will lead to an infinite loop when you
<tt>try a.begin()</tt> or <tt>b.begin()</tt>.
<p/>
A reddit posts suggests disallowing reversing a non-common range but that likely breaks reasonable use-cases. We could at
the very least recognize ranges whose sentinel is <tt>unreachable_t</tt> and reject those from consideration. For instance,
we could change <sref ref="[range.iter.op.next]"/>/3 to <i>Mandate</i> that <tt>S</tt> is not <tt>unreachable_t</tt>.
</p>
</discussion>

<resolution>
</resolution>

</issue>

0 comments on commit 909cdff

Please sign in to comment.