Re: [Boost-users] regex_token_iterator bug?

I can't reproduce that, can you provide test case?
Obviously my problem seems to be a little more subtile than i thought. I wrapped my example to a (actually three) stand alone program: #include <iostream> #include <iterator> #include <string> #include <boost/regex.hpp> boost::regex e("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\">", boost::regex::normal | boost::regbase::icase); int main(int argc, char** argv) { std::string s("<a href=\"mytest\"> hallo <\\a>\n" "<a href=\"duda\"> fjdu <\\a>\n"); const int subs[] = {1,0,}; boost::sregex_token_iterator i(s.begin(), s.end(), e, subs); boost::sregex_token_iterator j; while(i != j) { #ifdef USE_1 std::cout << i->length() << i++->str().length() << std::endl; #endif #ifdef USE_2 std::cout << i->length() << i->str().length() << std::endl; i++; #endif #ifdef USE_3 std::cout << i->length() ; std::cout << i++->str().length() << std::endl; #endif } return 0; } Suprisingly the "use_1" version is the only one that crashes with the output: 176 417 154 u1: ../boost_1_32_0/boost/shared_ptr.hpp:253: T* boost::shared_ptr<T>::operator->() const [with T = boost::regex_token_iterator_implementation<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, boost::regex_traits<char>, std::allocator<char> >]: Assertion `px != 0' failed. zsh: 31069 abort ./u1 I hope this is not a bug of my strange gcc (v3.3.3) version, and you can reproduce the error. Cheers, Joe. __________________________________ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250

#ifdef USE_1 std::cout << i->length() << i++->str().length() << std::endl; #endif
I believe that this is an issue with the evaluation of arguments: if you have a single expression the arguments are evaluated in an unspecified order - in this case the i++->str().length() gets evaluated before the i->length(), so i->length() is called on an end-of-sequence iterator (you should be able to confirm this by stepping through the code in your debugger). This is perfectly standard C++ I'm afraid, and is not a library or compiler bug. Hope this helps, John.

On Thu, 3 Feb 2005 11:19:49 -0000, John Maddock <john@johnmaddock.co.uk> wrote:
std::cout << i->length() << i++->str().length() <<
This is perfectly standard C++ I'm afraid, and is not a library or compiler bug.
... and why would you want to write your code that way anyhow? -- Caleb Epstein caleb dot epstein at gmail dot com
participants (3)
-
Caleb Epstein
-
Joe
-
John Maddock