Skip to content

Commit 6a57871

Browse files
<regex>: Fix regex_error when matching a repeated pattern containing a lookahead assertion (#5793)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent ea857c7 commit 6a57871

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

stl/inc/regex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3521,7 +3521,7 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Find_first_inner_capture
35213521

35223522
case _N_assert:
35233523
case _N_neg_assert:
3524-
if (_Find_first_inner_capture_group(static_cast<_Node_assert*>(_Nx), _Loop_state)) {
3524+
if (_Find_first_inner_capture_group(static_cast<_Node_assert*>(_Nx)->_Child, _Loop_state)) {
35253525
_Found_group = true;
35263526
_Nx = nullptr;
35273527
}

tests/std/tests/VSO_0000000_regex_use/test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,15 @@ void test_gh_5790() {
22232223
}
22242224
}
22252225

2226+
void test_gh_5792() {
2227+
// GH-5792: <regex>: regex_match() throws regex_error(error_stack)
2228+
// when a repeated pattern contains a lookahead assertion
2229+
g_regexTester.should_match("", "(?:(?=ab))*");
2230+
g_regexTester.should_match("", "(?:(?!ab))*");
2231+
g_regexTester.should_not_match("bc", "(?:(?=ab))+bc");
2232+
g_regexTester.should_match("bc", "(?:(?!ab))+bc");
2233+
}
2234+
22262235
int main() {
22272236
test_dev10_449367_case_insensitivity_should_work();
22282237
test_dev11_462743_regex_collate_should_not_disable_regex_icase();
@@ -2276,6 +2285,7 @@ int main() {
22762285
test_gh_5672();
22772286
test_gh_5774();
22782287
test_gh_5790();
2288+
test_gh_5792();
22792289

22802290
return g_regexTester.result();
22812291
}

0 commit comments

Comments
 (0)