Index: include/regex =================================================================== --- include/regex +++ include/regex @@ -4265,6 +4265,9 @@ if (__first != __last && *__first == '\\') { _ForwardIterator __t1 = _VSTD::next(__first); + if (__t1 == __last) + __throw_regex_error(); + _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); if (__t2 != __t1) __first = __t2; Index: test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp =================================================================== --- test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp +++ test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp @@ -33,6 +33,7 @@ { assert(error_escape_thrown("[\\a]")); assert(error_escape_thrown("\\a")); + assert(error_escape_thrown("\\")); assert(error_escape_thrown("[\\e]")); assert(error_escape_thrown("\\e"));