0

I have the following regular expression object that I create:

std::regex magStripe{R"(^%B(\d+)\^)"};

(Full, working sample here)

When this regex object is constructed, std::regex_error is thrown with code set to 2, which happens to be std::regex_constants::error_escape. I did some process of elimination and when I remove the \d, it works just fine.

I tested this on VS 2013 and it does not throw an exception. I tested this on Coliru and it seems to completely crash. If I use clang++ it works.

Why isn't this regex working on GCC? Am I doing something wrong?

void.pointer
  • 24,859
  • 31
  • 132
  • 243
  • Which version of GCC exactly? – πάντα ῥεῖ Oct 28 '14 at 21:36
  • I'm not sure what version. If you look at the first link, on ideone.com it just says "C++11". Locally on my machine, I'm using GCC 4.8 from Android NDK r10 which also fails. – void.pointer Oct 28 '14 at 21:37
  • I get the same compiler error without the \d. – Oliver Charlesworth Oct 28 '14 at 21:38
  • 4
    `GCC 4.8` is known, to be buggy about [regex](http://en.cppreference.com/w/cpp/regex/basic_regex), and incomplete support. – πάντα ῥεῖ Oct 28 '14 at 21:38
  • Thanks; for now I've switched to `boost::regex` until it is working again. It appears GCC 4.9 fixes this problem: https://gcc.gnu.org/gcc-4.9/changes.html -- it is currently available in Android NDK r10c – void.pointer Oct 28 '14 at 22:09
  • gcc 4.9 is still buggy the last time I see a question on SO (http://stackoverflow.com/questions/26272592/bug-in-stdregex), it affects even the latest version 4.9.1. I suggest that you stay away from it for a while. – nhahtdh Oct 29 '14 at 02:20

0 Answers0