This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

std::regex: inserting std::wregex to std::vector loses some std::wregex values


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




Attachment: gdb_regex_vector_output.txt
Description: Text document

#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;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]