<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2708: recursive_directory_iterator::recursion_pending() is incorrectly specified</title>
<meta property="og:title" content="Issue 2708: recursive_directory_iterator::recursion_pending() is incorrectly specified">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2708.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#Open">Open</a> status.</em></p>
<h3 id="2708"><a href="lwg-active.html#2708">2708</a>. <code>recursive_directory_iterator::recursion_pending()</code> is incorrectly specified</h3>
<p><b>Section:</b> 31.12.12.2 <a href="https://wg21.link/fs.rec.dir.itr.members">[fs.rec.dir.itr.members]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Eric Fiselier <b>Opened:</b> 2016-05-09 <b>Last modified:</b> 2022-12-18</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#fs.rec.dir.itr.members">issues</a> in [fs.rec.dir.itr.members].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The current specification of <code>recursion_pending()</code> says (31.12.12.2 <a href="https://wg21.link/fs.rec.dir.itr.members">[fs.rec.dir.itr.members]</a>/24):
</p>
<blockquote><p>
<i>Returns</i>: <code>true</code> if <code>disable_recursion_pending()</code> has not been called subsequent to the prior construction
or increment operation, otherwise <code>false</code>.
</p></blockquote>
<p>
This language does not take into account cases where the prior construction was a copy construction from a iterator,
<code>it</code>, where <code>it.recursion_pending() == false</code>.
</p>

<p><i>[2016-08 Chicago]</i></p>

<p>Wed AM: Move to Open</p>

<p><i>[2018-1-26 issues processing telecon]</i></p>

<p>Status to 'Tentatively Ready'; Casey will explore whether making <code>recursion_pending</code> an exposition-only member makes this clearer.</p>

<strong>Previous resolution from Eric [SUPERSEDED]:</strong>
<blockquote class="note">
<p>
This wording is relative to N4582.
</p>

<ol>
<li><p>Change 31.12.12.2 <a href="https://wg21.link/fs.rec.dir.itr.members">[fs.rec.dir.itr.members]</a> as indicated:</p>

<blockquote>
<pre>
explicit recursive_directory_iterator(const path&amp; p);
recursive_directory_iterator(const path&amp; p, directory_options options);
recursive_directory_iterator(const path&amp; p, directory_options options, error_code&amp; ec) noexcept;
recursive_directory_iterator(const path&amp; p, error_code&amp; ec) noexcept;
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-3- <i>Postcondition</i>: <del><code>options() == options</code> for the signatures with a <code>directory_options</code> argument,
otherwise <code>options() == directory_options::none</code>.</del>
</p>
<ul>
<li><p><ins><code>options() == options</code> for the signatures with a <code>directory_options</code> argument, otherwise
<code>options() == directory_options::none</code>.</ins></p></li>
<li><p><ins><code>recursion_pending() == true</code>.</ins></p></li>
</ul>
<p>
[&hellip;]
</p>
</blockquote>
<blockquote class="note">
<p>
[<i>Drafting note</i>: The following changes the specification of <code>recursion_pending()</code> seemingly recursive.
Perhaps it would be easier to specify <code>recursion_pending()</code> in terms of a exposition only member in
<code>recursive_directory_iterator</code>.]
</p>
</blockquote>
<pre>
bool recursion_pending() const;
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-24- <i>Returns</i>: <del><code>true</code> if <code>disable_recursion_pending()</code> has not been called subsequent to the
prior construction or increment operation, otherwise <code>false</code></del><ins><code>false</code> if
<code>disable_recursion_pending()</code> has been called subsequent to the prior construction or increment operation,
otherwise the value of <code>recursion_pending()</code> set by that operation</ins>.
<p/>
[&hellip;]
</p>
</blockquote>
<pre>
recursive_directory_iterator&amp; operator++();
recursive_directory_iterator&amp; increment(error_code&amp; ec) noexcept;
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-27- <i>Effects</i>: As specified by Input iterators (24.2.3), except that: [&hellip;]
<p/>
<ins>-?- <i>Postcondition</i>: <code>recursion_pending() == true</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2018-01-29: Casey provides a PR with an exposition-only member]</i></p>

<p>Status to 'Review'.</p>
<strong>Previous resolution from Casey [SUPERSEDED]:</strong>
<blockquote class="note">
<p>
This wording is relative to N4713.
</p>

<ol>
<li><p>Change  [fs.rec.dir.itr] as indicated:</p>
<blockquote>
<pre>
    [&hellip;]

    // other members as required by 24.3.5.3 <a href="https://wg21.link/input.iterators">[input.iterators]</a>, input iterators

  <ins>private:</ins>
    <ins>bool recurse_; // exposition-only</ins>
  };
}
</pre>
</blockquote>
</li>

<li><p>Change 31.12.12.2 <a href="https://wg21.link/fs.rec.dir.itr.members">[fs.rec.dir.itr.members]</a> as indicated:</p>

<blockquote>
<pre>
explicit recursive_directory_iterator(const path&amp; p);
recursive_directory_iterator(const path&amp; p, directory_options options);
recursive_directory_iterator(const path&amp; p, directory_options options, error_code&amp; ec) noexcept;
recursive_directory_iterator(const path&amp; p, error_code&amp; ec) noexcept;
</pre>
<blockquote>
<p>
[&hellip;]
</p><p>
-3- <i>Postconditions</i>: <del><code>options() == options</code> for the signatures with a <code>directory_options</code> argument,
otherwise <code>options() == directory_options::none</code>.</del>
</p>
<ul>
<li><p><ins><code>options() == options</code> for the signatures with a <code>directory_options</code> argument, otherwise
<code>options() == directory_options::none</code>.</ins></p></li>
<li><p><ins><code>recurse_ == true</code>.</ins></p></li>
</ul>
<p>
[&hellip;]
</p>
</blockquote>

<pre>
recursive_directory_iterator(const recursive_directory_iterator&amp; rhs);
</pre>
<blockquote>
<p>
[&hellip;]
</p><p>
-8- <i>Postconditions:</i>
</p><p>
[&hellip;]
</p><p>
(8.3) &mdash; <del><code>recursion_pending() == rhs.recursion_pending()</code></del><ins><code>recurse_ == rhs.recurse_</code></ins>
</p>
</blockquote>

<pre>
recursive_directory_iterator(recursive_directory_iterator&amp;&amp; rhs) noexcept;
</pre>
<blockquote>
<p>
[&hellip;]
</p><p>
-10- <i>Postconditions:</i> <code>options()</code>, <code>depth()</code>, and
<del><code>recursion_pending()</code></del><ins><code>recurse_</code></ins> have the values that <code>rhs.options()</code>,
<code>rhs.depth()</code>, and <del><code>rhs.recursion_pending()</code></del><ins><code>rhs.recurse_</code></ins>, respectively,
had before the function call.
</p>
</blockquote>

<pre>
recursive_directory_iterator&amp; operator=(const recursive_directory_iterator&amp; rhs);
</pre>
<blockquote>
<p>
[&hellip;]
</p><p>
-12- <i>Postconditions:</i>
</p><p>
[&hellip;]
</p><p>
(12.3) &mdash; <del><code>recursion_pending() == rhs.recursion_pending()</code></del><ins><code>recurse_ == rhs.recurse_</code></ins>
</p><p>
[&hellip;]
</p>
</blockquote>

<pre>
recursive_directory_iterator&amp; operator=(recursive_directory_iterator&amp;&amp; rhs) noexcept;
</pre>
<blockquote>
<p>
[&hellip;]
</p><p>
-15- <i>Postconditions:</i> <code>options()</code>, <code>depth()</code>, and
<del><code>recursion_pending()</code></del><ins><code>recurse_</code></ins> have the values that <code>rhs.options()</code>,
<code>rhs.depth()</code>, and <del><code>rhs.recursion_pending()</code></del><ins><code>rhs.recurse_</code></ins>, respectively,
had before the function call.
</p><p>
[&hellip;]
</p>
</blockquote>

<pre>
bool recursion_pending() const;
</pre>
<blockquote>
<p>
-21- <i>Returns</i>: <del><code>true</code> if <code>disable_recursion_pending()</code> has not been called subsequent to the
prior construction or increment operation, otherwise <code>false</code></del><ins>recurse_</ins>.
</p><p>
[&hellip;]
</p>
</blockquote>

<pre>
recursive_directory_iterator&amp; operator++();
recursive_directory_iterator&amp; increment(error_code&amp; ec) noexcept;
</pre>
<blockquote>
<p>
-23- <i>Effects</i>: As specified for the prefix increment operation of Input iterators
( [iterators.input]), except that:
</p><p>
[&hellip;]
</p><p>
<ins>-?- <i>Postcondition</i>: <code>recurse_ == true</code>.</ins>
</p>
</blockquote>

<pre>
void disable_recursion_pending();
</pre>
<blockquote>
<p>
-28- <i>Postcondition<del>s</del>:</i> <code><del>recursion_pending()</del><ins>recurse_</ins> == false</code>.
</p><p>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2018-05-23: Casey restores the intended design with an expansion of the original PR]</i></p>

<p>
The intended design is that all copies of a single <code>recursive_directory_iterator</code> share a
common block of state which includes the values returned by <code>options</code>, <code>depth</code>, and
<code>recursion_pending</code> - hence the mandate that those functions not be called on a
non-dereferenceable iterator in 31.12.12 <a href="https://wg21.link/fs.class.rec.dir.itr">[fs.class.rec.dir.itr]</a> para 2. To allow an
implementation with such shared state, it's necessary to make changes to the value returned by
<code>recursion_pending()</code> visible to <em>all copies</em> of the same dereferenceable iterator.
</p><p>
Also:
</p>
<ul>
<li><p><code>pop</code> notionally calls <code>increment</code> repeatedly until the current directory is
exhausted, <code>pop</code> should affect the value of <code>recursion_pending</code> similarly to
<code>increment</code>.</p></li>
<li><p><code>options</code> is not valid for all constructor signatures described by
31.12.12.2 <a href="https://wg21.link/fs.rec.dir.itr.members">[fs.rec.dir.itr.members]</a> para 2.</p></li>
<li><p>the copies and moves don't specify what they actually <i>do</i></p></li>
<li><p>it's not quite kosher for the copies and moves to have postconditions on the value of
expressions that have UB if the iterator copied/moved from is not dereferenceable.</p></li>
</ul>

<p><i>[2018-06, Rapperswil, Wednesday evening]</i></p>

<p>
JW: p21 currently can just say "unspecified"<br/>
BO: if we are OK with only remote implementations we can remove the unspecifiedness<br/>
BO: the problematic business is the "recursion pending" bit<br/>
JW: I want time to work on this
<p/>
Move to open and note that Jonathan is reviewing and making recommendations.
</p>

<p><i>[2018-08-23 Batavia Issues processing]</i></p>

<p>General agreement that flag should be shared; Casey to reword.</p>

<p><i>[2022-12-18; Daniel comments]</i></p>

<p>
Note that this proposed wording has some overlap with LWG <a href="lwg-active.html#3668" title="[recursive_]directory_iterator constructors refer to undefined options (Status: New)">3668</a><sup><a href="https://cplusplus.github.io/LWG/issue3668" title="Latest snapshot">(i)</a></sup> for
<code>recursive_directory_iterator</code>'s constructors without <code>options</code> argument.
If we would like a different wording form for this textual location in one issue we
should resync the other issue to reduce the chance of a merge conflict.
</p>


<p id="res-2708"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4750.
</p>

<ol>
<li><p>Change 31.12.12.2 <a href="https://wg21.link/fs.rec.dir.itr.members">[fs.rec.dir.itr.members]</a> as indicated:</p>

<blockquote>
<pre>
explicit recursive_directory_iterator(const path&amp; p);
recursive_directory_iterator(const path&amp; p, directory_options options);
recursive_directory_iterator(const path&amp; p, directory_options options, error_code&amp; ec) noexcept;
recursive_directory_iterator(const path&amp; p, error_code&amp; ec) noexcept;
</pre>
<blockquote>
<p>
<ins>-?- For the signatures with no parameter <code>options</code>, let <code>options</code> be
<code>directory_options::none</code>.</ins>
</p><p>
-2- <i>Effects</i>: [&hellip;]
</p><p>
-3- <i>Postconditions</i>: <del><code>options() == options</code> for the signatures with a
<code>directory_options</code> argument, otherwise <code>options() == directory_options::none</code>.</del>
</p>
<ul>
<li><p><ins><code>this->options() == options</code></ins></p></li>
<li><p><ins><code>recursion_pending() == true</code></ins></p></li>
</ul>
<p>
[&hellip;]
</p>
</blockquote>
<pre>
recursive_directory_iterator(const recursive_directory_iterator&amp; rhs);
</pre>
<blockquote>
<p>
-7- <i>Effects</i>: Constructs an <del>object of class <code>recursive_directory_iterator</code></del>
<ins>iterator that denotes the same directory entry as <code>rhs</code>, if any.</ins>.
</p><p>
-8- <i>Postconditions</i>: <ins>If <code>rhs</code> is dereferenceable,</ins>
</p><p>
[&hellip;]
</p>
</blockquote>
<pre>
recursive_directory_iterator(recursive_directory_iterator&amp;&amp; rhs) noexcept;
</pre>
<blockquote>
<p>
-9- <i>Effects</i>: Constructs an <del>object of class <code>recursive_directory_iterator</code></del>
<ins>iterator that denotes the directory entry denoted by <code>rhs</code> before the function call, if
any.</ins>.
</p><p>
-10- <i>Postconditions</i>: <ins>If <code>rhs</code> is dereferenceable,</ins>  [&hellip;]
</p>
</blockquote>
<pre>
recursive_directory_iterator&amp; operator=(const recursive_directory_iterator&amp; rhs);
</pre>
<blockquote>
<p>
-11- <i>Effects</i>: <del>If <code>*this</code> and <code>rhs</code> are the same object, the member has no
effect.</del> <ins>Causes <code>*this</code> to denote the same directory entry denoted by <code>rhs</code>,
if any.</ins>
</p><p>
-12- <i>Postconditions</i>: <ins>If <code>rhs</code> is dereferenceable,</ins>
</p><p>
[&hellip;]
</p>
</blockquote>
<pre>
recursive_directory_iterator&amp; operator=(recursive_directory_iterator&amp;&amp; rhs) noexcept;
</pre>
<blockquote>
<p>
-14- <i>Effects</i>: <del>If <code>*this</code> and <code>rhs</code> are the same object, the member has no
effect.</del> <ins>Causes <code>*this</code> to denote the directory entry denoted by <code>rhs</code>
before the function call, if any.</ins>
</p><p>
-15- <i>Postconditions</i>: <ins>If <code>rhs</code> was dereferenceable before the function call,</ins>
[&hellip;]
</p><p>
-16- <i>Returns</i>: <code>*this</code>.
</p><p>
<ins>-x- <i>Remarks</i>: If <code>*this</code> and <code>rhs</code> do not refer to the same object, the
resulting state of <code>rhs</code> is unspecified (16.4.6.17 <a href="https://wg21.link/lib.types.movedfrom">[lib.types.movedfrom]</a>).</ins>
</p>
</blockquote>
<pre>
directory_options options() const;
</pre>
<blockquote>
<p>
-17- <i>Returns</i>: The value <del>of the argument passed to the constructor for the <code>options</code>
parameter, if present, otherwise <code>directory_options::none</code></del> <ins>established by the most
recently called member that has a postcondition for <code>options()</code></ins>.
</p><p>
[&hellip;]
</p>
</blockquote>
<pre>
bool recursion_pending() const;
</pre>
<blockquote>
<p>
-21- <i>Returns</i>: <del><code>true</code> if <code>disable_recursion_pending()</code> has not been called
subsequent to the prior construction or increment operation, otherwise <code>false</code>.</del> <ins>If
<code>disable_recursion_pending()</code> has been called on a copy of <code>*this</code>, an unspecified
value. Otherwise, the value established for <code>recursion_pending()</code> by the postcondition of the
most recent construction, assignment, increment, or <code>disable_recursion_pending</code> operation.</ins>
</p><p>
[&hellip;]
</p>
</blockquote>
<pre>
recursive_directory_iterator&amp; operator++();
recursive_directory_iterator&amp; increment(error_code&amp; ec);
</pre>
<blockquote>
<p>
-23- <i>Effects</i>: As specified for the prefix increment operation of Input iterators
(24.3.5.3 <a href="https://wg21.link/input.iterators">[input.iterators]</a>), except that: [&hellip;]
</p><p>
<ins>-?- <i>Postconditions</i>: If <code>*this</code> is dereferenceable,
<code>recursion_pending() == true</code>.</ins>
</p><p>
[&hellip;]
</p>
</blockquote>
<pre>
void pop();
void pop(error_code&amp; ec);
</pre>
<blockquote>
<p>
-26- <i>Effects</i>: If <code>depth() == 0</code>, set <code>*this</code> to
<code>recursive_directory_iterator()</code>. [&hellip;]
</p><p>
<ins>-?- <i>Postconditions</i>: If <code>*this</code> is dereferenceable,
<code>recursion_pending() == true</code>.</ins>
</p><p>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
