Boost C++ Libraries: Ticket #10380: filesystem directory iterator throws on increment https://svn.boost.org/trac10/ticket/10380 <p> The following code throws an exception: </p> <p> std::for_each( recursive_directory_iterator(path_to_root_dir), recursive_directory_iterator(), </p> <blockquote> <p> []( const directory_entry&amp; de ) { </p> <blockquote> <p> remove_all( de.path() ); </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> ); </p> </blockquote> <p> if path_to_root_dir contains only a single sub-directory. This happens in the increment operator of the iterator at line 791 (boost/filesystem/operations.hpp: m_stack.push(directory_iterator(m_stack.top()-&gt;path())); </p> <p> The sub-directory is successfully deleted. The exception is thrown after the deletion when the iterator is incremented </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10380 Trac 1.4.3 Richard <richard.j@…> Wed, 20 Aug 2014 05:56:31 GMT <link>https://svn.boost.org/trac10/ticket/10380#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10380#comment:1</guid> <description> <p> Forgot to mention: this happens on Windows 7/VS2010. </p> <p> This also happens if there is more than one subdirectory. </p> <p> If the remove_all invalidates the iterator, I would find that completely acceptable. I would, howver, expect some statements in the docs, which I could not find. </p> </description> <category>Ticket</category> </item> </channel> </rss>