https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77356
Bug ID: 77356 Summary: regex error for a ECMAScript syntax string Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: wmi at google dot com Target Milestone: --- For the testcase 1.cxx: ---------------------------------------- #include <regex> int main() { static const char* kNumericAnchor ="(\\$|usd)(usd|\\$|to|and|up to|[0-9,\\.\\-\\sk])+"; const std::regex re(kNumericAnchor); return 0; } ---------------------------------------- ~/workarea/gcc-r239713/build/install/bin/g++ -std=c++11 -O0 1.cxx -Wl,-rpath=/usr/local/google/home/wmi/workarea/gcc-r239713/build/install/lib64 ./a.out terminate called after throwing an instance of 'std::regex_error' what(): Unexpected end of bracket expression. Aborted (core dumped) I have no problem to compile and run the testcase using libc++. For libstdc++, the exception is thrown because the second dash '-' is not in any range and it is not the start or end of bracket expression. According to the comment in _M_expression_term in src/libstdc++-v3/include/bits/regex_compiler.tcc this is not allowed in POSIX syntax but allowed in ECMAScript syntax. Since the input is ECMAScript syntax, libstdc++ shoudn't throw exception for it?