Boost Users :
From: Axel F. (axelf_at_[hidden])
Date: 2002-06-18 18:08:34
> Weird, but looks more like a VC bug than a regex one - after all the
> difference between the two examples is whether the string passed to
> regex_format is a variable or a temporary, so unless I'm missing something
> it's got to be a compiler problem?
Well, I don't think, it's a compiler problem.
stringbuf::str() retuns a temporary string. This is passed on to
The real problem is, the data in matchInfo is not stored as a copy of the
processed string, but as a reference to its characters.
So, when the temoprary string is being destroyed, the result in matchInfo is
Even the following short code failes, using a temporary string as argument
using namespace std;
using namespace boost;
string str = "123456";
if (regex_match(str, match1, exp))
cout << "matchInfo=" << match1.str() << "\n";
cout << "match1.size()=" << match1.str().size() << "\n\n";
regex_match(string("123456"), match2, exp);
cout << "match2=" << match2.str() << "\n";
cout << "match2.size()=" << match2.str().size() << "\n\n";
For me, it outputs:
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net