<div dir="ltr"><div><div><div><div>Hi guys.<br><br></div>Several days ago I've faced a strange issue with boost::filesystem::path::iterator - it segfaults when used in some STL algorithms.<br><br></div>Here's a sample code that crashes:<br><br><a href="http://melpon.org/wandbox/permlink/58aIbfJWeGgMKMdF">http://melpon.org/wandbox/permlink/58aIbfJWeGgMKMdF</a><br><br></div>I looked at the issue a little bit and discovered that the reason for that is this part of iterator code:<br><br> const path& dereference() const { return m_element; }<br><br></div><div>So when using std::search libstdc++ has to convert binary predicate to unary for later use in std::find_if: <br><br> __first1 =<br> std::__find_if(__first1, __last1,<br> __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));<br><br></div><div>It does this by capturing dereferenced value of second iterator (__first2 in a piece of code above) but since iterator is passed by-value, this wrapper holds dangling reference to local member of iterator.m_element.<br><br></div><div>Now according to C++ standard part 24.2.1 [iterator.requirements.general]:<br><br>10. Destruction of an iterator may invalidate pointers and references previously obtained from that iterator.<br><br></div><div>So this looks like a violation of a standard by libstdc++ library. Unfortunately I couldn't get my account registered at <a href="https://gcc.gnu.org/bugzilla/">https://gcc.gnu.org/bugzilla/</a> and was not able to file a bug, so can I ask you to help me with it?<br></div></div>