Subject: [Boost-bugs] [Boost C++ Libraries] #4123: smatches contains wrong matches, access changes content
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-04-19 21:51:32
#4123: smatches contains wrong matches, access changes content
-------------------------------------+--------------------------------------
Reporter: g_sauthoff@⦠| Owner: johnmaddock
Type: Bugs | Status: new
Milestone: Boost 1.43.0 | Component: regex
Version: Boost Development Trunk | Severity: Problem
Keywords: |
-------------------------------------+--------------------------------------
{{{
$ cat main.cc
#include <boost/regex.hpp>
#include <iostream>
int main(int argc, char **argv)
{
boost::regex expr(argv[1]);
boost::smatch matches;
if (boost::regex_search(std::string(argv[2]), matches, expr)) {
for (size_t i = 0; i<matches.size(); ++i)
std::cout << "XXX " << matches[i] << '\n';
for (size_t i = 0; i<matches.size(); ++i)
std::cout << "YYY " << matches[i] << '\n';
for (size_t i = 0; i<matches.size(); ++i)
std::cout << "ZZZ " << matches[i] << '\n';
}
}
$ ./main 'to ([a-z]+) [A-Z]+ ([0-9]+)' 'fs to hello WORLD 123'
XXX to hello WORLD 123
XXX lo WO
XXX 23
YYY hello WORLD 12323
YYY WORLD
YYY 23
ZZZ lo WORLD 1232323
ZZZ LD 12
ZZZ 23
}}}
Expected output:
three times: hello 123
(or at least three times the same output)
Perhaps I am using the API wrong, but I am inspired by this
example(-output):
/usr/share/doc/libboost1.38-doc/HTML/libs/regex/doc/html/boost_regex/captures.html
I get the same results with boost 1.38.
Using Ubuntu 9.10, x86/64, g++ 4.4.1.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4123> 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:50:02 UTC