Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<regex>: Fix pointer-size constructor of basic_regex and remove error_parse #5211

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions stl/inc/regex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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)";
Expand Down Expand Up @@ -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 <class _STtraits, class _STalloc>
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/std/tests/VSO_0000000_regex_use/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
{
Expand Down Expand Up @@ -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();
Expand Down