Hi guys.

Several days ago I've faced a strange issue with boost::filesystem::path::iterator - it segfaults when used in some STL algorithms.

Here's a sample code that crashes:

http://melpon.org/wandbox/permlink/58aIbfJWeGgMKMdF

I looked at the issue a little bit and discovered that the reason for that is this part of iterator code:

    const path& dereference() const { return m_element; }

So when using std::search libstdc++ has to convert binary predicate to unary for later use in std::find_if:

      __first1 =
        std::__find_if(__first1, __last1,
        __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));

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.

Now according to C++ standard part 24.2.1 [iterator.requirements.general]:

10. Destruction of an iterator may invalidate pointers and references previously obtained from that iterator.

So this looks like a violation of a standard by libstdc++ library. Unfortunately I couldn't get my account registered at https://gcc.gnu.org/bugzilla/ and was not able to file a bug, so can I ask you to help me with it?