Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#1990 closed Bugs (fixed)

xpressive: passing temporary regex to sregex_token_iterator causes runtime assertion

Reported by: jesse@… Owned by: Eric Niebler
Milestone: Boost 1.36.0 Component: xpressive
Version: Boost 1.35.0 Severity: Problem
Keywords: Cc:

Description

This program suprises me by causing a runtime assertion:

#include <string>
#include <boost/xpressive/xpressive.hpp>

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)
  ;
}

...the assertion:

suprise: /usr/local/include/boost-1_35/boost/xpressive/detail/utility/tracking_ptr.hpp:196: void
boost::xpressive::detail::enable_reference_tracking<Derived>::release() [with Derived = boost::xpressive::detail::regex_impl<__gnu_cxx::__normal_iterator<const char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >]: Assertion `0 < this->cnt_' failed.
Aborted

Changing the declarations like this causes it to work as I expect:

 sregex tab_delim(as_xpr("\t"));
 sregex_token_iterator   cur(x.begin(), x.end(), tab_delim, -1),
                         end;

...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?

[Note: Boost 1.35, OpenSuSE 10.3, g++ 4.1.2]

Eric Niebler's reply of 4/6/2008:

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.

Change History (3)

comment:1 by Marshall Clow, 14 years ago

Component: Nonexpressive
Owner: set to Eric Niebler

comment:2 by Eric Niebler, 14 years ago

Resolution: fixed
Status: newclosed

(In [46655]) regex iterators hold ref count to regex impl, fixes #1990

comment:3 by Eric Niebler, 14 years ago

(In [46656]) Merged revisions 46655 via svnmerge from https://svn.boost.org/svn/boost/trunk

........

r46655 | eric_niebler | 2008-06-24 09:24:50 -0700 (Tue, 24 Jun 2008) | 1 line

regex iterators hold ref count to regex impl, fixes #1990

........

Note: See TracTickets for help on using tickets.