From b5a6fb65640b56382dcd0d3c92c0ddfa20cb65db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= Date: Mon, 20 Oct 2025 21:18:55 +0200 Subject: [PATCH] ``: Fix `regex_error` when matching a repeated pattern containing a lookahead assertion --- stl/inc/regex | 2 +- tests/std/tests/VSO_0000000_regex_use/test.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/stl/inc/regex b/stl/inc/regex index d886365a2f3..973d4013a5a 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -3587,7 +3587,7 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Find_first_inner_capture case _N_assert: case _N_neg_assert: - if (_Find_first_inner_capture_group(static_cast<_Node_assert*>(_Nx), _Loop_state)) { + if (_Find_first_inner_capture_group(static_cast<_Node_assert*>(_Nx)->_Child, _Loop_state)) { _Found_group = true; _Nx = nullptr; } diff --git a/tests/std/tests/VSO_0000000_regex_use/test.cpp b/tests/std/tests/VSO_0000000_regex_use/test.cpp index b4fc9b2f8fa..6a718898113 100644 --- a/tests/std/tests/VSO_0000000_regex_use/test.cpp +++ b/tests/std/tests/VSO_0000000_regex_use/test.cpp @@ -2143,6 +2143,15 @@ void test_gh_5774() { g_regexTester.should_match("aaab", "a{1,3}?b"); } +void test_gh_5792() { + // GH-5792: : regex_match() throws regex_error(error_stack) + // when a repeated pattern contains a lookahead assertion + g_regexTester.should_match("", "(?:(?=ab))*"); + g_regexTester.should_match("", "(?:(?!ab))*"); + g_regexTester.should_not_match("bc", "(?:(?=ab))+bc"); + g_regexTester.should_match("bc", "(?:(?!ab))+bc"); +} + int main() { test_dev10_449367_case_insensitivity_should_work(); test_dev11_462743_regex_collate_should_not_disable_regex_icase(); @@ -2195,6 +2204,7 @@ int main() { test_gh_5576(); test_gh_5672(); test_gh_5774(); + test_gh_5792(); return g_regexTester.result(); }