Skip to content

<regex>: Remove match mode _Skip_zero_length#6262

Open
muellerj2 wants to merge 1 commit intomicrosoft:mainfrom
muellerj2:regex-remove-matchmode-skip-zero-length
Open

<regex>: Remove match mode _Skip_zero_length#6262
muellerj2 wants to merge 1 commit intomicrosoft:mainfrom
muellerj2:regex-remove-matchmode-skip-zero-length

Conversation

@muellerj2
Copy link
Copy Markdown
Contributor

This removes a strange internal match mode _Skip_zero_length. Its only purpose was to shift the start of the pattern search one position later, but to set prefix().first in the match_results object as if there were no such shift. This match mode was only used to implement the increment operator of regex_iterator.

Moreover, _Regex_search2 has an additional parameter _Org which is only used to set the member _Org in the match_results object.

This PR moves the updates of the affected match_results fields _Org and prefix().first outside _Regex_search2/3. Instead, the callers have to set these members correctly now. This allows the removal of the _Skip_zero_length match mode and the _Org parameter. The implementation of regex_iterator::operator++() now follows more obviously the algorithm described in [re.regiter.incr].

This is also a preparatory step towards correct iterator unwrapping when regex_match and so on are called with a match_results object: match_results uses wrapped iterator types, so if _Regex_search2/3 remained responsible for updating _Org and prefix().first, the iterator values to assign would have to be passed as additional wrapped iterators to the function just to perform this assignment, on top of the unwrapped iterators it needs as well. By moving this to the caller, we will be able to pass only those unwrapped iterators to _Regex_search3 that are actually needed for matching (except for one wrapped iterator, which we need to correctly rewrap the unwrapped iterators when filling the match_results object in _Matcher3::_Copy_captures).

Drive-by change: _STD-qualify a few more calls.

Drive-by bugfix: I think regex_iterator::operator++() failed to call _Adopt(nullptr) in debug mode in one case when no more match was found.

@muellerj2 muellerj2 requested a review from a team as a code owner April 18, 2026 20:48
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Apr 18, 2026
Comment thread stl/inc/regex
Comment on lines +2869 to +2876
for (;;) {
_Matches._Org = _Pos;
_Matches._Pfx().first = _Pos;
if (!_STD _Regex_search3(_Pos, _Last, _STD addressof(_Matches), _Re, _Flags | _Not_null)) {
break;
}

// replace at each match
Copy link
Copy Markdown
Contributor Author

@muellerj2 muellerj2 Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just call _STD regex_search() instead. Then we can retain the previous while loop structure at the cost of an unnecessary _Adl_verify_range() call (and unnecessary _Get_unwrapped() calls in the future).

Comment thread stl/inc/regex

_BidIt _Start = _MyVal._At(0).second;
_BidIt _Start = _MyVal._At(0).second;
_MyVal._Pfx().first = _Start;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we don't have to set _MyVal._Org here, because the constructor already did this. This is even the case when an old version of the constructor gets picked by the linker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

1 participant