diff --git a/stl/inc/regex b/stl/inc/regex index b5fa6cae39..ea93da183d 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -149,7 +149,7 @@ namespace regex_constants { error_badrepeat, error_complexity, error_stack, - error_parse, + _Error_parse, // TRANSITION, was error_parse, keeping behavior error_syntax }; } // namespace regex_constants @@ -464,12 +464,12 @@ _EXPORT_STD class _NODISCARD regex_error : public runtime_error { // type of all public: explicit regex_error(regex_constants::error_type _Ex) : runtime_error(_Stringify(_Ex)), _Err(_Ex) {} - _NODISCARD regex_constants::error_type code() const { + _NODISCARD regex_constants::error_type code() const noexcept /* strengthened */ { return _Err; } private: - static const char* _Stringify(regex_constants::error_type _Ex) { // map error code to string + static const char* _Stringify(regex_constants::error_type _Ex) noexcept { // map error code to string switch (_Ex) { // select known error_type message case regex_constants::error_collate: return "regex_error(error_collate): The expression " @@ -515,7 +515,7 @@ private: return "regex_error(error_stack): There was insufficient " "memory to determine whether the regular expression " "could match the specified character sequence."; - case regex_constants::error_parse: + case regex_constants::_Error_parse: // TRANSITION, keeping behavior return "regex_error(error_parse)"; case regex_constants::error_syntax: return "regex_error(error_syntax)"; @@ -1820,12 +1820,10 @@ public: } basic_regex(_In_reads_(_Count) const _Elem* _Ptr, size_t _Count, flag_type _Flags = regex_constants::ECMAScript) { - if (_Ptr) { - _Reset(_Ptr, _Ptr + _Count, _Flags); - return; - } - - _Xregex_error(regex_constants::error_parse); +#if _ITERATOR_DEBUG_LEVEL != 0 + _STL_VERIFY(_Ptr != nullptr || _Count == 0, "constructing basic_regex from an invalid range"); +#endif // ^^^ _ITERATOR_DEBUG_LEVEL != 0 ^^^ + _Reset(_Ptr, _Ptr + _Count, _Flags); } template @@ -3652,7 +3650,11 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Match_pat(_Node_base* _Nx) { // c case _N_none: default: - _Xregex_error(regex_constants::error_parse); +#if _ITERATOR_DEBUG_LEVEL != 0 + _STL_VERIFY(false, "internal data of regex node corrupted"); +#else // ^^^ _ITERATOR_DEBUG_LEVEL != 0 / _ITERATOR_DEBUG_LEVEL == 0 vvv + return false; +#endif // ^^^ _ITERATOR_DEBUG_LEVEL == 0 ^^^ } if (_Failed) { diff --git a/tests/std/tests/GH_002206_unreserved_names/test.compile.pass.cpp b/tests/std/tests/GH_002206_unreserved_names/test.compile.pass.cpp index 8ba419dbd0..302200fc3e 100644 --- a/tests/std/tests/GH_002206_unreserved_names/test.compile.pass.cpp +++ b/tests/std/tests/GH_002206_unreserved_names/test.compile.pass.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #define ISA_AVAILABILITY delete +#define error_parse delete #define nsec delete #define sec delete #define xtime delete diff --git a/tests/std/tests/VSO_0000000_regex_use/test.cpp b/tests/std/tests/VSO_0000000_regex_use/test.cpp index ad2efc0d4a..0eea2f88ad 100644 --- a/tests/std/tests/VSO_0000000_regex_use/test.cpp +++ b/tests/std/tests/VSO_0000000_regex_use/test.cpp @@ -547,6 +547,17 @@ void test_VSO_226914_word_boundaries() { aWordAny.should_search_fail("aa", match_not_bow | match_not_eow); } +void test_construction_from_nullptr_and_zero() { + { + regex re(nullptr, 0); + assert(re.mark_count() == 0); + } + { + wregex re(nullptr, 0); + assert(re.mark_count() == 0); + } +} + void test_gh_993() { // GH-993 regex::icase is not handled correctly for some input. { @@ -695,6 +706,7 @@ int main() { test_VSO_225160_match_bol_flag(); test_VSO_225160_match_eol_flag(); test_VSO_226914_word_boundaries(); + test_construction_from_nullptr_and_zero(); test_gh_993(); test_gh_4995(); test_gh_5058();