[Boost-bugs] [Boost C++ Libraries] #1990: xpressive: passing temporary regex to sregex_token_iterator causes runtime assertion

Subject: [Boost-bugs] [Boost C++ Libraries] #1990: xpressive: passing temporary regex to sregex_token_iterator causes runtime assertion
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-06-05 17:41:52


#1990: xpressive: passing temporary regex to sregex_token_iterator causes runtime
assertion
----------------------------+-----------------------------------------------
 Reporter: jesse_at_[hidden] | Type: Bugs
   Status: new | Milestone: Boost 1.36.0
Component: None | Version: Boost 1.35.0
 Severity: Problem | Keywords:
----------------------------+-----------------------------------------------
 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.
 }}}

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1990>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC