<regex>: Remove match mode _Skip_zero_length#6262
Open
muellerj2 wants to merge 1 commit intomicrosoft:mainfrom
Open
<regex>: Remove match mode _Skip_zero_length#6262muellerj2 wants to merge 1 commit intomicrosoft:mainfrom
<regex>: Remove match mode _Skip_zero_length#6262muellerj2 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
muellerj2
commented
Apr 18, 2026
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 |
Contributor
Author
There was a problem hiding this comment.
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).
|
|
||
| _BidIt _Start = _MyVal._At(0).second; | ||
| _BidIt _Start = _MyVal._At(0).second; | ||
| _MyVal._Pfx().first = _Start; |
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 setprefix().firstin thematch_resultsobject as if there were no such shift. This match mode was only used to implement the increment operator ofregex_iterator.Moreover,
_Regex_search2has an additional parameter_Orgwhich is only used to set the member_Orgin thematch_resultsobject.This PR moves the updates of the affected
match_resultsfields_Organdprefix().firstoutside_Regex_search2/3. Instead, the callers have to set these members correctly now. This allows the removal of the_Skip_zero_lengthmatch mode and the_Orgparameter. The implementation ofregex_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_matchand so on are called with amatch_resultsobject:match_resultsuses wrapped iterator types, so if_Regex_search2/3remained responsible for updating_Organdprefix().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_search3that are actually needed for matching (except for one wrapped iterator, which we need to correctly rewrap the unwrapped iterators when filling thematch_resultsobject 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.