
Hi *, I think I stumbled across a bug in boost.regex, but perhaps it is just me misunderstanding the docs. Basically it seems like regex_match breaks its postcondition when working with std::string input and smatch result. Attached is a new test case for the test suite (my first trial, I bet it does not fit into boost unchanged) which shows the bug (if it is one). Interestingly, using regex_match together with a const char pointer and cmatch results works like expected. I attached the new source file, which belongs into boost/libs/regex/test/regress together with changes to the Jamfiles as a diff. Any comments welcome. Greetings Torsten

Torsten Landschoff wrote:
boost::smatch sm; BOOST_REGEX_TEST(boost::regex_match(std::string(text), sm, re));
Here is your problem. You're performing a match on a temporary std::string. After regex_match returns, sm will be left holding iterators into a destroyed string. Try: std::string str(text); BOOST_REGEX_TEST(boost::regex_match(str, sm, re)); instead. -- Eric Niebler Boost Consulting www.boost-consulting.com

Hi Eric, On Mon, Jul 24, 2006 at 03:29:40PM -0700, Eric Niebler wrote:
Torsten Landschoff wrote:
boost::smatch sm; BOOST_REGEX_TEST(boost::regex_match(std::string(text), sm, re));
Here is your problem. You're performing a match on a temporary std::string. After regex_match returns, sm will be left holding iterators into a destroyed string. Try:
Ouch, of course. Perhaps I should not be trying getting a grip at boost::regex at this time. Thanks, I'll have to check if I produced the same bug at work. I think I am not as the string is a member over there, but I have to check. Thanks again and good night, Torsten

Ouch, of course. Perhaps I should not be trying getting a grip at boost::regex at this time.
Personally, I found boost.regex relatively easy to use. If you do need it, don't give up. This library is doing wonders for me. Steven "Torsten Landschoff" <torsten@landschoff.net> wrote in message news:20060724223800.GA26806@stargate.galaxy...
Hi Eric,
On Mon, Jul 24, 2006 at 03:29:40PM -0700, Eric Niebler wrote:
Torsten Landschoff wrote:
boost::smatch sm; BOOST_REGEX_TEST(boost::regex_match(std::string(text), sm, re));
Here is your problem. You're performing a match on a temporary std::string. After regex_match returns, sm will be left holding iterators into a destroyed string. Try:
Ouch, of course. Perhaps I should not be trying getting a grip at boost::regex at this time. Thanks, I'll have to check if I produced the same bug at work. I think I am not as the string is a member over there, but I have to check.
Thanks again and good night,
Torsten _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Eric Niebler
-
Steven Burns
-
Torsten Landschoff