Boost C++ Libraries: Ticket #1749: regex_match on filesystem iterator.leaf () leads to strange results in what[] https://svn.boost.org/trac10/ticket/1749 <p> Code fragment: </p> <pre class="wiki">boost::smatch what; boost::regex e ("^(tty:)(tty.+)$"); for (fs::directory_iterator itr_l2 (*itr_l1); itr_l2 != end_itr; ++itr_l2) { ... match = boost::regex_match ((*itr_l2).leaf(), what, e); leads to incorrect results in what[0], what[1]... when match occurs. </pre><p> libboost_filesystem.so.1.33.1 libboost_regex.so.1.33.1 Suse 10.1 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1749 Trac 1.4.3 John Maddock Fri, 04 Apr 2008 12:54:11 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1749#comment:1 https://svn.boost.org/trac10/ticket/1749#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The problem here is that the leaf() function returns a *temporary string value*, so by the time that regex_match returns the string matched against has gone out of scope, and the iterators stored in match_results&lt;&gt; have all been invalidated. Assigning the result of leaf() to a local string object before calling regex_match will fix this. </p> <p> HTH, John Maddock. </p> Ticket