Boost logo

Boost Users :

Subject: [Boost-users] boost::filesystem::path::iterator and libstdc++ std::search
From: Oleksandr Senkovych (bjsenya_at_[hidden])
Date: 2016-11-11 08:40:49

Hi guys.

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

Here's a sample code that crashes:

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 and was not able to file a bug, so can I ask
you to help me with it?

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at