From 9c42cd6e939263096c589ff787a8f016744baaa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= Date: Mon, 16 Mar 2026 22:28:31 +0100 Subject: [PATCH 1/4] `_First_arg` => `_First` --- stl/inc/regex | 75 +++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/stl/inc/regex b/stl/inc/regex index 163c263b43..e94efa29fb 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -4852,16 +4852,16 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N template _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( - _BidIt _First_arg, _BidIt _Last, _Node_base* _Node_arg, unsigned int _Recursion_depth) { + _BidIt _First, _BidIt _Last, _Node_base* _Node_arg, unsigned int _Recursion_depth) { // skip until possible match - // assumes --_First_arg is valid + // assumes --_First is valid static constexpr char _Line_terminators_char[] = {static_cast(_Meta_cr), static_cast(_Meta_nl)}; static constexpr wchar_t _Line_terminators_wchar_t[] = {static_cast(_Meta_cr), static_cast(_Meta_nl), static_cast(_Meta_ls), static_cast(_Meta_ps)}; constexpr unsigned int _Max_recursion_depth = 50U; _Node_base* _Nx = _Node_arg ? _Node_arg : _Start; - while (_First_arg != _Last && _Nx) { // check current node + while (_First != _Last && _Nx) { // check current node switch (_Nx->_Kind) { // handle current node's type case _N_nop: break; @@ -4870,25 +4870,24 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( if (_Sflags & regex_constants::multiline) { // multiline mode: check for embedded line terminator // return iterator to character just after the newline; for input like "\nabc" - // matching "^abc", _First_arg could be pointing at 'a', so we need to check - // --_First_arg for '\n' - if (!_STD _Is_ecmascript_line_terminator(*_STD _Prev_iter(_First_arg))) { + // matching "^abc", _First could be pointing at 'a', so we need to check --_First for '\n' + if (!_STD _Is_ecmascript_line_terminator(*_STD _Prev_iter(_First))) { if constexpr (sizeof(_Elem) == 1) { - _First_arg = _STD find_first_of( - _First_arg, _Last, _Line_terminators_char, _STD end(_Line_terminators_char)); + _First = + _STD find_first_of(_First, _Last, _Line_terminators_char, _STD end(_Line_terminators_char)); } else { - _First_arg = _STD find_first_of( - _First_arg, _Last, _Line_terminators_wchar_t, _STD end(_Line_terminators_wchar_t)); + _First = _STD find_first_of( + _First, _Last, _Line_terminators_wchar_t, _STD end(_Line_terminators_wchar_t)); } - if (_First_arg != _Last) { - ++_First_arg; + if (_First != _Last) { + ++_First; } } - return _First_arg; + return _First; } else { - // non-multiline mode: never matches because --_First_arg is valid + // non-multiline mode: never matches because --_First is valid return _Last; } @@ -4896,11 +4895,10 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( if (_Sflags & regex_constants::multiline) { // multiline mode: matches at next line terminator or end of input if constexpr (sizeof(_Elem) == 1) { - return _STD find_first_of( - _First_arg, _Last, _Line_terminators_char, _STD end(_Line_terminators_char)); + return _STD find_first_of(_First, _Last, _Line_terminators_char, _STD end(_Line_terminators_char)); } else { return _STD find_first_of( - _First_arg, _Last, _Line_terminators_wchar_t, _STD end(_Line_terminators_wchar_t)); + _First, _Last, _Line_terminators_wchar_t, _STD end(_Line_terminators_wchar_t)); } } else { return _Last; // non-multiline mode: matches at end of input or not at all @@ -4910,21 +4908,20 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( { // check for string match _Node_str<_Elem>* _Node = static_cast<_Node_str<_Elem>*>(_Nx); auto _Str = _Node->_Data._Str(); - return _STD _Search_translate_left( - _First_arg, _Last, _Str, _Str + _Node->_Data._Size(), _Traits, _Sflags); + return _STD _Search_translate_left(_First, _Last, _Str, _Str + _Node->_Data._Size(), _Traits, _Sflags); } case _N_class: { // check for string match _Node_class<_Elem, _RxTraits>* _Node = static_cast<_Node_class<_Elem, _RxTraits>*>(_Nx); - for (; _First_arg != _Last; ++_First_arg) { // look for starting match - if (_Do_class(_Node, _First_arg) != _First_arg) { - return _First_arg; + for (; _First != _Last; ++_First) { // look for starting match + if (_Do_class(_Node, _First) != _First) { + return _First; } } } - return _First_arg; + return _First; case _N_group: break; @@ -4953,7 +4950,7 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( _Node_if* _Node = static_cast<_Node_if*>(_Nx); if (_Node->_Child) { - return _First_arg; + return _First; } break; } @@ -4962,7 +4959,7 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( { _Node_rep* _Node = static_cast<_Node_rep*>(_Nx); if (_Node->_Min == 0) { - return _First_arg; + return _First; } break; } @@ -4970,21 +4967,21 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_assert: { if (_Recursion_depth >= _Max_recursion_depth) { - return _First_arg; + return _First; } _Node_assert* _Node = static_cast<_Node_assert*>(_Nx); - _First_arg = _Skip(_First_arg, _Last, _Node->_Child, _Recursion_depth + 1U); + _First = _Skip(_First, _Last, _Node->_Child, _Recursion_depth + 1U); _BidIt _Next; for (;;) { - _Next = _Skip(_First_arg, _Last, _Node->_Next, _Recursion_depth + 1U); - if (_Next == _First_arg) { - return _First_arg; + _Next = _Skip(_First, _Last, _Node->_Next, _Recursion_depth + 1U); + if (_Next == _First) { + return _First; } - _First_arg = _Skip(_Next, _Last, _Node->_Child, _Recursion_depth + 1U); - if (_Next == _First_arg) { - return _First_arg; + _First = _Skip(_Next, _Last, _Node->_Child, _Recursion_depth + 1U); + if (_Next == _First) { + return _First; } } } @@ -4996,15 +4993,15 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_wbound: { bool _Negated = (_Nx->_Flags & _Fl_negate) != 0; - bool _Prev_word = _STD _Is_word(*_STD _Prev_iter(_First_arg)); - for (; _First_arg != _Last; ++_First_arg) { - bool _Next_word = _STD _Is_word(*_First_arg); + bool _Prev_word = _STD _Is_word(*_STD _Prev_iter(_First)); + for (; _First != _Last; ++_First) { + bool _Next_word = _STD _Is_word(*_First); if (_Negated == (_Next_word == _Prev_word)) { break; } _Prev_word = _Next_word; } - return _First_arg; + return _First; } case _N_begin: @@ -5017,13 +5014,13 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_back: case _N_end_rep: default: - return _First_arg; + return _First; } if (_Nx) { _Nx = _Nx->_Next; } } - return _First_arg; + return _First; } template From 8b2a2febce7599c8eabce0587f52550057834d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= Date: Mon, 16 Mar 2026 22:39:34 +0100 Subject: [PATCH 2/4] add const --- stl/inc/regex | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/stl/inc/regex b/stl/inc/regex index e94efa29fb..2716fb035d 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -2190,7 +2190,7 @@ public: return true; } - _BidIt _Skip(_BidIt, _BidIt, _Node_base* = nullptr, unsigned int _Recursion_depth = 0U); + _BidIt _Skip(_BidIt, _BidIt, const _Node_base* = nullptr, unsigned int _Recursion_depth = 0U); private: _Tgt_state_type _Tgt_state; @@ -2210,7 +2210,7 @@ private: void _Prepare_rep(_Node_rep*); bool _Find_first_inner_capture_group(_Node_base*, _Loop_vals_type*); void _Reset_capture_groups(unsigned int _First); - _It _Do_class(_Node_base*, _It); + _It _Do_class(const _Node_base*, _It); bool _Match_pat(_Node_base*); bool _Better_match(); bool _Is_wbound() const; @@ -4095,7 +4095,7 @@ _BidIt _Lookup_coll2(_Elem _First_ch, _BidIt _First, const _BidIt _Last, const _ } template -_It _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Do_class(_Node_base* _Nx, _It _First) { +_It _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Do_class(const _Node_base* const _Nx, _It _First) { // apply bracket expression bool _Found; _Elem _Ch = *_First; @@ -4109,7 +4109,7 @@ _It _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Do_class(_Node_base* _Nx, _It _Res0 = _First; ++_Res0; _It _Resx; - _Node_class<_Elem, _RxTraits>* _Node = static_cast<_Node_class<_Elem, _RxTraits>*>(_Nx); + const auto _Node = static_cast*>(_Nx); if (_Node->_Coll && (_Resx = _STD _Lookup_coll2(_Ch, _First, _End, _Node->_Coll, _Traits, _Sflags)) != _First) { // check for collation element @@ -4852,14 +4852,14 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N template _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( - _BidIt _First, _BidIt _Last, _Node_base* _Node_arg, unsigned int _Recursion_depth) { + _BidIt _First, const _BidIt _Last, const _Node_base* const _Node_arg, const unsigned int _Recursion_depth) { // skip until possible match // assumes --_First is valid static constexpr char _Line_terminators_char[] = {static_cast(_Meta_cr), static_cast(_Meta_nl)}; static constexpr wchar_t _Line_terminators_wchar_t[] = {static_cast(_Meta_cr), static_cast(_Meta_nl), static_cast(_Meta_ls), static_cast(_Meta_ps)}; constexpr unsigned int _Max_recursion_depth = 50U; - _Node_base* _Nx = _Node_arg ? _Node_arg : _Start; + const _Node_base* _Nx = _Node_arg ? _Node_arg : _Start; while (_First != _Last && _Nx) { // check current node switch (_Nx->_Kind) { // handle current node's type @@ -4906,14 +4906,14 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_str: { // check for string match - _Node_str<_Elem>* _Node = static_cast<_Node_str<_Elem>*>(_Nx); - auto _Str = _Node->_Data._Str(); + const auto _Node = static_cast*>(_Nx); + const auto _Str = _Node->_Data._Str(); return _STD _Search_translate_left(_First, _Last, _Str, _Str + _Node->_Data._Size(), _Traits, _Sflags); } case _N_class: { // check for string match - _Node_class<_Elem, _RxTraits>* _Node = static_cast<_Node_class<_Elem, _RxTraits>*>(_Nx); + const auto _Node = static_cast*>(_Nx); for (; _First != _Last; ++_First) { // look for starting match if (_Do_class(_Node, _First) != _First) { @@ -4947,7 +4947,7 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( // TRANSITION, ABI: After GH-5539, the parser no longer generates single-branch _N_if nodes. // But we have to retain this special handling to avoid performance regression // when an old parser gets mixed with a new matcher. - _Node_if* _Node = static_cast<_Node_if*>(_Nx); + const auto _Node = static_cast(_Nx); if (_Node->_Child) { return _First; @@ -4957,7 +4957,7 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_rep: { - _Node_rep* _Node = static_cast<_Node_rep*>(_Nx); + const auto _Node = static_cast(_Nx); if (_Node->_Min == 0) { return _First; } @@ -4970,8 +4970,8 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( return _First; } - _Node_assert* _Node = static_cast<_Node_assert*>(_Nx); - _First = _Skip(_First, _Last, _Node->_Child, _Recursion_depth + 1U); + const auto _Node = static_cast(_Nx); + _First = _Skip(_First, _Last, _Node->_Child, _Recursion_depth + 1U); _BidIt _Next; for (;;) { _Next = _Skip(_First, _Last, _Node->_Next, _Recursion_depth + 1U); @@ -4992,10 +4992,10 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_wbound: { - bool _Negated = (_Nx->_Flags & _Fl_negate) != 0; - bool _Prev_word = _STD _Is_word(*_STD _Prev_iter(_First)); + const bool _Negated = (_Nx->_Flags & _Fl_negate) != 0; + bool _Prev_word = _STD _Is_word(*_STD _Prev_iter(_First)); for (; _First != _Last; ++_First) { - bool _Next_word = _STD _Is_word(*_First); + const bool _Next_word = _STD _Is_word(*_First); if (_Negated == (_Next_word == _Prev_word)) { break; } From 8e7bcb2145bb7738bf755495e8537c0cafcd81da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= Date: Mon, 16 Mar 2026 22:45:19 +0100 Subject: [PATCH 3/4] correct _Skip signature --- stl/inc/regex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/regex b/stl/inc/regex index 2716fb035d..dc71f3d737 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -2190,7 +2190,7 @@ public: return true; } - _BidIt _Skip(_BidIt, _BidIt, const _Node_base* = nullptr, unsigned int _Recursion_depth = 0U); + _It _Skip(_It, _It, const _Node_base* = nullptr, unsigned int _Recursion_depth = 0U); private: _Tgt_state_type _Tgt_state; @@ -4851,8 +4851,8 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N } template -_BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( - _BidIt _First, const _BidIt _Last, const _Node_base* const _Node_arg, const unsigned int _Recursion_depth) { +_It _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( + _It _First, const _It _Last, const _Node_base* const _Node_arg, const unsigned int _Recursion_depth) { // skip until possible match // assumes --_First is valid static constexpr char _Line_terminators_char[] = {static_cast(_Meta_cr), static_cast(_Meta_nl)}; From 68a00fec30568d3fbb2cea14e3f6f8fc15c6ddef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= Date: Mon, 16 Mar 2026 22:53:35 +0100 Subject: [PATCH 4/4] name all parameters in declaration --- stl/inc/regex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/regex b/stl/inc/regex index dc71f3d737..79fa577afb 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -2190,7 +2190,7 @@ public: return true; } - _It _Skip(_It, _It, const _Node_base* = nullptr, unsigned int _Recursion_depth = 0U); + _It _Skip(_It _First, _It _Last, const _Node_base* _Node_arg = nullptr, unsigned int _Recursion_depth = 0U); private: _Tgt_state_type _Tgt_state;