Created attachment 32732 [details] Preprocessed source for testcase Source: --------[regextest.cpp]--------------------------------------------------------- #include <regex> int main() { std::regex description_keys("^description\\[.*\\]$", std::regex::extended); } -------------------------------------------------------------------------------- This RE has been used by code using boost::regex for around a decade. The failure is caused by escaping the "[" and "]" regex metacharacters with a backslash "\" to match the literal character, so nothing too complex really. I'm fairly sure this is completely correct. This compiles with GCC 4.9, but fails at runtime in the regex constructor, shown below: % gdb regextest GNU gdb (GDB) 7.6.2 (Debian 7.6.2-1) This GDB was configured as "x86_64-linux-gnu". (gdb) run Starting program: /tmp/regextest warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffd000 warning: Could not load shared library symbols for linux-vdso.so.1. Do you need "set solib-search-path" or "set sysroot"? Traceback (most recent call last): File "/usr/lib/debug/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20-gdb.py", line 59, in <module> from libstdcxx.v6.printers import register_libstdcxx_printers ImportError: No module named libstdcxx.v6.printers terminate called after throwing an instance of 'std::regex_error' what(): regex_error Program received signal SIGABRT, Aborted. 0x00000033248353a9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) bt #0 0x00000033248353a9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 #1 0x00000033248384c8 in __GI_abort () at abort.c:89 #2 0x00007ffff7d1fd55 in __gnu_cxx::__verbose_terminate_handler () at ../../../../src/libstdc++-v3/libsupc++/vterminate.cc:95 #3 0x00007ffff7d1ddd6 in __cxxabiv1::__terminate (handler=<optimized out>) at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:47 #4 0x00007ffff7d1de21 in std::terminate () at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:57 #5 0x00007ffff7d1e038 in __cxxabiv1::__cxa_throw (obj=0x62b550, tinfo=0x7ffff7fb13d0 <typeinfo for std::regex_error>, dest= 0x7ffff7d74f70 <std::regex_error::~regex_error()>) at ../../../../src/libstdc++-v3/libsupc++/eh_throw.cc:87 #6 0x00007ffff7d74325 in std::__throw_regex_error (__ecode=std::regex_constants::_S_error_escape) at ../../../../../src/libstdc++-v3/src/c++11/functexcept.cc:141 #7 0x0000000000404f56 in std::__detail::_Scanner<char>::_M_eat_escape_posix (this=0x7fffffffe5b8) at /usr/include/c++/4.9/bits/regex_scanner.tcc:395 #8 0x0000000000405c59 in std::__detail::_Scanner<char>::_M_scan_normal (this=0x7fffffffe5b8) at /usr/include/c++/4.9/bits/regex_scanner.tcc:110 #9 0x0000000000404fc3 in std::__detail::_Scanner<char>::_M_advance (this=0x7fffffffe5b8) at /usr/include/c++/4.9/bits/regex_scanner.tcc:80 #10 0x000000000040426a in std::__detail::_Compiler<std::regex_traits<char> >::_M_match_token (this=0x7fffffffe5a0, token=std::__detail::_ScannerBase::_S_token_closure0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:487 #11 0x00000000004080a5 in std::__detail::_Compiler<std::regex_traits<char> >::_M_quantifier (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:187 #12 0x0000000000406b85 in std::__detail::_Compiler<std::regex_traits<char> >::_M_term (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:138 #13 0x000000000040522e in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:118 #14 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #15 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #16 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #17 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #18 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #19 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #20 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #21 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #22 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #23 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #24 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #25 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #26 0x0000000000405251 in std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:121 #27 0x0000000000404122 in std::__detail::_Compiler<std::regex_traits<char> >::_M_disjunction (this=0x7fffffffe5a0) at /usr/include/c++/4.9/bits/regex_compiler.tcc:97 #28 0x000000000040391c in std::__detail::_Compiler<std::regex_traits<char> >::_Compiler (this=0x7fffffffe5a0, __b=0x62b028 "^description\\[.*\\]$", __e=0x62b03b "", __traits=..., __flags=std::regex_constants::extended) at /usr/include/c++/4.9/bits/regex_compiler.tcc:82 #29 0x00000000004034e4 in std::__detail::__compile_nfa<std::regex_traits<char> > (__first=0x62b028 "^description\\[.*\\]$", __last=0x62b03b "", __traits=..., __flags=std::regex_constants::extended) at /usr/include/c++/4.9/bits/regex_compiler.h:155 #30 0x0000000000403257 in std::basic_regex<char, std::regex_traits<char> >::basic_regex<char const*> (this=0x7fffffffe800, __first=0x41bc6e "^description\\[.*\\]$", __last=0x41bc81 "", __f=std::regex_constants::extended) at /usr/include/c++/4.9/bits/regex.h:528 #31 0x0000000000402fdf in std::basic_regex<char, std::regex_traits<char> >::basic_regex (this=0x7fffffffe800, __p=0x41bc6e "^description\\[.*\\]$", __f=std::regex_constants::extended) at /usr/include/c++/4.9/bits/regex.h:452 #32 0x0000000000402588 in main () at regextest.cpp:5
Reduced: #include <regex> int main() { std::regex description_keys("\\]", std::regex::extended); } POSIX says this is undefined: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04_02 The closing brace is not a POSIX ERE special character so should not be escaped. As a GNU extension we accept it with -std=gnu++11
(Unsetting fields I accidentally filled in on the wrong browser tab)
Thanks for the clarification. Just for reference for anyone else running into this behaviour: clang++3.3: compiles and runs VS2012: compiles and throws regex_error VS2013: compiles and throws regex_error