std::regex: inserting std::wregex to std::vector loses some std::wregex values
Stefan Schweter
stefan@schweter.it
Sun Sep 7 14:15:00 GMT 2014
Hi,
using GCC 4.9.1 it can reproduce a strange behavior with inserting
std::wregex values to a std::vector.
I'm using a loop which creates some std::wregex with imbuing and assigning.
After compiling and executing the program code, a core dump is returned.
Having a deeper look with gdb into the std::vector I can see, that only
the half of the std::wregex values have been properly inserted -> see
the _M_original_str variable.
Here is my code to reproduce the error:
#include <regex>
#include <vector>
int main()
{
std::setlocale(LC_ALL, "");
std::wstring current_token(L"II.");
std::vector<std::wregex> regex_vector;
for (int i = 0; i < 4; ++i)
{
std::regex_constants::syntax_option_type flag;
flag = std::regex_constants::icase;
std::wregex reg;
reg.imbue(std::locale(""));
reg.assign(L"^(M*(?:CM|DC{1,3}|D|CD|C{1,3}){0,1}(?:XC|LX{1,3}|L|XL|X{1,3}){0,1}(?:IX|VI{0,3}|IV|I{1,3}){0,1}\\.)$",
flag);
regex_vector.emplace_back(reg);
}
for (auto cit = regex_vector.cbegin(); cit != regex_vector.cend(); ++cit)
{
std::wstring::const_iterator it1 = current_token.begin();
std::wstring::const_iterator it2 = current_token.end();
std::wsmatch current_token_match;
std::regex_match(it1, it2, current_token_match, *cit);
}
return 0;
}
Compiled with g++ -g -std=c++11 std_regex.cpp.
For the gdb regex_vector output, see attachment.
Is this error known?
Thank you very much in advance + regards,
Stefan
-------------- next part --------------
(gdb) p regex_vector
$1 = std::vector of length 4, capacity 4 = {{static icase = <optimized out>, static nosubs = <optimized out>,
static optimize = <optimized out>, static collate = <optimized out>, static ECMAScript = <optimized out>,
static basic = <optimized out>, static extended = <optimized out>, static awk = <optimized out>,
static grep = <optimized out>, static egrep = <optimized out>, _M_flags = std::regex_constants::icase, _M_traits = {
_M_locale = {static none = 0, static ctype = 1, static numeric = 2, static collate = 4, static time = 8,
static monetary = 16, static messages = 32, static all = 63, _M_impl = 0x631040, static _S_classic = <optimized out>,
static _S_global = <optimized out>, static _S_categories = <optimized out>, static _S_once = <optimized out>}},
_M_original_str = L"", _M_automaton = std::shared_ptr (count 1, weak 0) 0x65ac50}, {static icase = <optimized out>,
static nosubs = <optimized out>, static optimize = <optimized out>, static collate = <optimized out>,
static ECMAScript = <optimized out>, static basic = <optimized out>, static extended = <optimized out>,
static awk = <optimized out>, static grep = <optimized out>, static egrep = <optimized out>,
_M_flags = std::regex_constants::icase, _M_traits = {_M_locale = {static none = 0, static ctype = 1, static numeric = 2,
static collate = 4, static time = 8, static monetary = 16, static messages = 32, static all = 63, _M_impl = 0x659ea0,
static _S_classic = <optimized out>, static _S_global = <optimized out>, static _S_categories = <optimized out>,
static _S_once = <optimized out>}}, _M_original_str = L"", _M_automaton = std::shared_ptr (count 1, weak 0) 0x65d350}, {
static icase = <optimized out>, static nosubs = <optimized out>, static optimize = <optimized out>,
static collate = <optimized out>, static ECMAScript = <optimized out>, static basic = <optimized out>,
static extended = <optimized out>, static awk = <optimized out>, static grep = <optimized out>,
static egrep = <optimized out>, _M_flags = std::regex_constants::icase, _M_traits = {_M_locale = {static none = 0,
static ctype = 1, static numeric = 2, static collate = 4, static time = 8, static monetary = 16, static messages = 32,
static all = 63, _M_impl = 0x659990, static _S_classic = <optimized out>, static _S_global = <optimized out>,
static _S_categories = <optimized out>, static _S_once = <optimized out>}},
_M_original_str = L"^(M*(?:CM|DC{1,3}|D|CD|C{1,3}){0,1}(?:XC|LX{1,3}|L|XL|X{1,3}){0,1}(?:IX|VI{0,3}|IV|I{1,3}){0,1}\\.)$",
_M_automaton = std::shared_ptr (count 1, weak 0) 0x66b410}, {static icase = <optimized out>,
static nosubs = <optimized out>, static optimize = <optimized out>, static collate = <optimized out>,
static ECMAScript = <optimized out>, static basic = <optimized out>, static extended = <optimized out>,
static awk = <optimized out>, static grep = <optimized out>, static egrep = <optimized out>,
_M_flags = std::regex_constants::icase, _M_traits = {_M_locale = {static none = 0, static ctype = 1, static numeric = 2,
static collate = 4, static time = 8, static monetary = 16, static messages = 32, static all = 63, _M_impl = 0x665010,
static _S_classic = <optimized out>, static _S_global = <optimized out>, static _S_categories = <optimized out>,
static _S_once = <optimized out>}},
_M_original_str = L"^(M*(?:CM|DC{1,3}|D|CD|C{1,3}){0,1}(?:XC|LX{1,3}|L|XL|X{1,3}){0,1}(?:IX|VI{0,3}|IV|I{1,3}){0,1}\\.)$",
_M_automaton = std::shared_ptr (count 1, weak 0) 0x66c7e0}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: std_regex.cpp
Type: text/x-c++src
Size: 842 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20140907/c3e25728/attachment.bin>
More information about the Libstdc++
mailing list