From 8b5f9727c63ed6e260a911904175459f84a42bbc Mon Sep 17 00:00:00 2001 From: alexprabhatbara Date: Wed, 5 Feb 2025 00:31:21 +0530 Subject: [PATCH 1/4] capture groups in negative lookahead assertions are never matched --- stl/inc/regex | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/stl/inc/regex b/stl/inc/regex index 5491b129ed0..86fdaa202b1 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -334,10 +334,7 @@ public: template char_class_type lookup_classname(_Iter _First, _Iter _Last, bool _Icase = false) const { // map [_First, _Last) to character class mask value -#define _REGEX_CHAR_CLASS_NAME(n, c) \ - { \ - n, L##n, static_cast(_STD size(n) - 1), c \ - } +#define _REGEX_CHAR_CLASS_NAME(n, c) {n, L##n, static_cast(_STD size(n) - 1), c} static constexpr _Cl_names _Names[] = { // map class names to numeric constants _REGEX_CHAR_CLASS_NAME("alnum", _Ch_alnum), @@ -3610,7 +3607,6 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Match_pat(_Node_base* _Nx) { // c _Node_end_group* _Node = static_cast<_Node_end_group*>(_Nx); _Node_capture* _Node0 = static_cast<_Node_capture*>(_Node->_Back); if (_Cap || _Node0->_Idx != 0) { // update capture data - _Tgt_state._Grp_valid[_Node0->_Idx] = true; _Tgt_state._Grps[_Node0->_Idx]._End = _Tgt_state._Cur; } break; From 2a078d31df1e361b20113b46c07d97fb4f468dc3 Mon Sep 17 00:00:00 2001 From: alexprabhatbara Date: Wed, 5 Feb 2025 15:12:11 +0530 Subject: [PATCH 2/4] reset state after a successful negative assertion --- stl/inc/regex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stl/inc/regex b/stl/inc/regex index 86fdaa202b1..5e334731559 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -3580,7 +3580,11 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Match_pat(_Node_base* _Nx) { // c _Tgt_state = _St; _Failed = true; } else { - _Tgt_state._Cur = _Ch; + if (_Neg) { + _Tgt_state = _St; + } else { + _Tgt_state._Cur = _Ch; + } } break; From 331e2cbb21c17a12792aabc933939a4cbd2e653f Mon Sep 17 00:00:00 2001 From: alexprabhatbara Date: Wed, 5 Feb 2025 15:19:16 +0530 Subject: [PATCH 3/4] revert penultimate commit change --- stl/inc/regex | 1 + 1 file changed, 1 insertion(+) diff --git a/stl/inc/regex b/stl/inc/regex index 5e334731559..c780472aebb 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -3611,6 +3611,7 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Match_pat(_Node_base* _Nx) { // c _Node_end_group* _Node = static_cast<_Node_end_group*>(_Nx); _Node_capture* _Node0 = static_cast<_Node_capture*>(_Node->_Back); if (_Cap || _Node0->_Idx != 0) { // update capture data + _Tgt_state._Grp_valid[_Node0->_Idx] = true; _Tgt_state._Grps[_Node0->_Idx]._End = _Tgt_state._Cur; } break; From 82e96b6a053bb0de0bba10478bb1b9d03b25b56f Mon Sep 17 00:00:00 2001 From: alexprabhatbara Date: Sat, 8 Feb 2025 01:13:52 +0530 Subject: [PATCH 4/4] necessary optimizations --- stl/inc/regex | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/stl/inc/regex b/stl/inc/regex index c780472aebb..e58c47066bd 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -3572,19 +3572,14 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Match_pat(_Node_base* _Nx) { // c case _N_neg_assert: case _N_assert: { // check assert - _It _Ch = _Tgt_state._Cur; bool _Neg = _Nx->_Kind == _N_neg_assert; _Bt_state_t<_It> _St = _Tgt_state; if (_Match_pat(static_cast<_Node_assert*>(_Nx)->_Child) == _Neg) { // restore initial state and indicate failure _Tgt_state = _St; _Failed = true; - } else { - if (_Neg) { - _Tgt_state = _St; - } else { - _Tgt_state._Cur = _Ch; - } + } else if (!_Neg) { + _Tgt_state._Cur = _St._Cur; } break;