Boost C++ Libraries: Ticket #11910: recursive_directory_iterator doesn't set end iterator properly when exception is thrown in increment() https://svn.boost.org/trac10/ticket/11910 <p> in operations.hpp the increment function looks like this: </p> <pre class="wiki"> void increment() { BOOST_ASSERT_MSG(m_imp.get(), "increment of end recursive_directory_iterator"); m_imp-&gt;increment(0); if (m_imp-&gt;m_stack.empty()) m_imp.reset(); // done, so make end iterator } </pre><p> The problem occurs when you are incrementing using the ++ operator. If there is an exception, the stack is never checked to see if it is empty because the m_imp-&gt;increment() throws an exception. This leaves the recursive iterator in a bad state. </p> <p> I fixed it by doing this: </p> <pre class="wiki"> void increment() { BOOST_ASSERT_MSG(m_imp.get(), "increment of end recursive_directory_iterator"); try { m_imp-&gt;increment(0); } catch(filesystem_error e) { if (m_imp-&gt;m_stack.empty()) m_imp.reset(); // done, so make end iterator throw(e); } if (m_imp-&gt;m_stack.empty()) m_imp.reset(); // done, so make end iterator } </pre><p> but I'm not sure that is the right way to address this issue. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11910 Trac 1.4.3 David Raphael <draphael@…> Wed, 13 Jan 2016 16:50:01 GMT summary changed https://svn.boost.org/trac10/ticket/11910#comment:1 https://svn.boost.org/trac10/ticket/11910#comment:1 <ul> <li><strong>summary</strong> <span class="trac-field-old">recursive_directory_iterator doesn't set end_iterator properly when exception is thrown in increment()</span> → <span class="trac-field-new">recursive_directory_iterator doesn't set end iterator properly when exception is thrown in increment()</span> </li> </ul> Ticket