Index: libcxx/include/regex =================================================================== --- libcxx/include/regex +++ libcxx/include/regex @@ -965,7 +965,9 @@ error_stack, __re_err_grammar, __re_err_empty, - __re_err_unknown + __re_err_unknown, + // Not sure whether placing it before unknown is considered ABI breakage. + __re_err_parse }; } // regex_constants @@ -2548,8 +2550,7 @@ : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) { - if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; - __parse(__p, __p + __traits_.length(__p)); + __init(__p, __p + __traits_.length(__p)); } _LIBCPP_INLINE_VISIBILITY @@ -2557,8 +2558,7 @@ : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) { - if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; - __parse(__p, __p + __len); + __init(__p, __p + __len); } // basic_regex(const basic_regex&) = default; @@ -2570,8 +2570,7 @@ : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) { - if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; - __parse(__p.begin(), __p.end()); + __init(__p.begin(), __p.end()); } template @@ -2581,8 +2580,7 @@ : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) { - if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; - __parse(__first, __last); + __init(__first, __last); } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY @@ -2591,8 +2589,7 @@ : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) { - if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; - __parse(__il.begin(), __il.end()); + __init(__il.begin(), __il.end()); } #endif // _LIBCPP_CXX03_LANG @@ -2708,6 +2705,9 @@ unsigned __loop_count() const {return __loop_count_;} template + void + __init(_ForwardIterator __first, _ForwardIterator __last); + template _ForwardIterator __parse(_ForwardIterator __first, _ForwardIterator __last); template @@ -3065,6 +3065,17 @@ template template +void +basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) +{ + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + _ForwardIterator __temp = __parse(__first, __last); + if ( __temp != __last) + __throw_regex_error(); +} + +template +template _ForwardIterator basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, _ForwardIterator __last) Index: libcxx/src/regex.cpp =================================================================== --- libcxx/src/regex.cpp +++ libcxx/src/regex.cpp @@ -53,6 +53,8 @@ return "An invalid regex grammar has been requested."; case regex_constants::__re_err_empty: return "An empty regex is not allowed in the POSIX grammar."; + case regex_constants::__re_err_parse: + return "The parser did not consume the entire regular expression."; default: break; }