Skip to content
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
10 changes: 7 additions & 3 deletions stl/inc/regex
Original file line number Diff line number Diff line change
Expand Up @@ -4096,11 +4096,15 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N
_Frame._Loop_idx_sav = _Sav._Loop_idx;
_Frame._Loop_frame_idx_sav = _Sav._Loop_frame_idx;
_Sav._Loop_frame_idx = _Frame_idx;
if (_Progress) {
++_Sav._Loop_idx;
} else { // try only one more match after an empty match

// optimization: try only one more match after an empty match
// if there is no maximum number of reps
if (!_Progress && _Nr->_Max < 0) {
_Sav._Loop_idx = _Nr->_Min;
} else {
++_Sav._Loop_idx;
}

_STD fill(_Tgt_state._Grp_valid.begin() + static_cast<ptrdiff_t>(_Sav._Group_first),
_Tgt_state._Grp_valid.end(), false);
_Next = _Nr->_Next;
Expand Down
8 changes: 8 additions & 0 deletions tests/std/tests/VSO_0000000_regex_use/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,13 @@ void test_gh_5792() {
g_regexTester.should_match("bc", "(?:(?!ab))+bc");
}

void test_gh_5797() {
// GH-5797: <regex>: Loops with bounded number of repetitions and context-dependent empty alternative are mishandled
g_regexTester.should_match("bc", "(?:b|c|(?=bc)){3}");
g_regexTester.should_match("bc", "(^|b|c){3}");
g_regexTester.should_match("bc", "(^|b|c){3}", regex_constants::extended);
}

void test_gh_5798() {
// GH-5798: <regex>: Process generic loops non-recursively.
// This extends our test coverage on non-simple loops,
Expand Down Expand Up @@ -2401,6 +2408,7 @@ int main() {
test_gh_5774();
test_gh_5790();
test_gh_5792();
test_gh_5797();
test_gh_5798();

return g_regexTester.result();
Expand Down