Boost C++ Libraries: Ticket #1990: xpressive: passing temporary regex to sregex_token_iterator causes runtime assertion https://svn.boost.org/trac10/ticket/1990 <p> This program suprises me by causing a runtime assertion: </p> <pre class="wiki">#include &lt;string&gt; #include &lt;boost/xpressive/xpressive.hpp&gt; using namespace boost::xpressive; int main() { std::string x("a\tb\tc"); sregex_token_iterator cur(x.begin(), x.end(), as_xpr("\t"), -1), end; for(; cur != end; ++cur) ; } </pre><p> ...the assertion: </p> <pre class="wiki">suprise: /usr/local/include/boost-1_35/boost/xpressive/detail/utility/tracking_ptr.hpp:196: void boost::xpressive::detail::enable_reference_tracking&lt;Derived&gt;::release() [with Derived = boost::xpressive::detail::regex_impl&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt;]: Assertion `0 &lt; this-&gt;cnt_' failed. Aborted </pre><p> Changing the declarations like this causes it to work as I expect: </p> <pre class="wiki"> sregex tab_delim(as_xpr("\t")); sregex_token_iterator cur(x.begin(), x.end(), tab_delim, -1), end; </pre><p> ...maybe there's some "temporary" magic happening, or that I was just plain doing something I shouldn't have been doing (silly me!), or both? </p> <p> [Note: Boost 1.35, OpenSuSE 10.3, g++ 4.1.2] </p> <p> Eric Niebler's reply of 4/6/2008: </p> <pre class="wiki">Interesting. Currently the regex iterators hold a (bare) pointer to the regex to be used. If you pass in a temporary regex, it'll obviously not live long enough. It wouldn't be hard to make the regex iterators hold a reference count to the regex impl, which would make your code work. The down-side would be that copying regex iterators (a common operation?) would be more expensive. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1990 Trac 1.4.3 Marshall Clow Tue, 24 Jun 2008 15:56:40 GMT component changed; owner set https://svn.boost.org/trac10/ticket/1990#comment:1 https://svn.boost.org/trac10/ticket/1990#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Eric Niebler</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">xpressive</span> </li> </ul> Ticket Eric Niebler Tue, 24 Jun 2008 16:24:50 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1990#comment:2 https://svn.boost.org/trac10/ticket/1990#comment:2 <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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/46655" title="regex iterators hold ref count to regex impl, fixes #1990">[46655]</a>) regex iterators hold ref count to regex impl, fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1990" title="#1990: Bugs: xpressive: passing temporary regex to sregex_token_iterator causes ... (closed: fixed)">#1990</a> </p> Ticket Eric Niebler Tue, 24 Jun 2008 16:49:26 GMT <link>https://svn.boost.org/trac10/ticket/1990#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1990#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/46656" title="Merged revisions 46655 via svnmerge from ...">[46656]</a>) Merged revisions 46655 via svnmerge from <a class="ext-link" href="https://svn.boost.org/svn/boost/trunk"><span class="icon">​</span>https://svn.boost.org/svn/boost/trunk</a> </p> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/46655" title="regex iterators hold ref count to regex impl, fixes #1990">r46655</a> | eric_niebler | 2008-06-24 09:24:50 -0700 (Tue, 24 Jun 2008) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> regex iterators hold ref count to regex impl, fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1990" title="#1990: Bugs: xpressive: passing temporary regex to sregex_token_iterator causes ... (closed: fixed)">#1990</a> </p> </blockquote> <p> ........ </p> </description> <category>Ticket</category> </item> </channel> </rss>