`<regex>`: Correctly set up `match_results` for match attempts on default-constructed regexes by muellerj2 · Pull Request #6185 · microsoft/STL · GitHub
Skip to content

<regex>: Correctly set up match_results for match attempts on default-constructed regexes#6185

Merged
StephanTLavavej merged 1 commit into
microsoft:mainfrom
muellerj2:regex-set-up-match_results-for-empty-regexes
Mar 27, 2026
Merged

<regex>: Correctly set up match_results for match attempts on default-constructed regexes#6185
StephanTLavavej merged 1 commit into
microsoft:mainfrom
muellerj2:regex-set-up-match_results-for-empty-regexes

Conversation

@muellerj2

@muellerj2 muellerj2 commented Mar 25, 2026

Copy link
Copy Markdown

Fixes #6181.

This PR moves the code to manipulate the match_results out of the _Matcher3::_Match function.

The code resetting the match_results becomes the first step in _Regex_match1 and _Regex_search2, thus ensuring that they are set up correctly for the early return when these functions are called on default-constructed regexes.

The code filling the match_results is moved into a new function _Matcher3::_Copy_captures. This function is called by _Regex_match1 and _Regex_search2 now after finding a successful match.

The changes in this PR and #6164 mean that _Matcher3 no longer depends on the (potentially wrapped) iterator type _BidIt except for the code in _Matcher3::_Copy_captures, so we can remove the type as a template parameter from the class and only template this specific member function on it. This also exposed one place in _Matcher3::_Skip where I accidentally failed to clean up some wrong _BidIt usage in #6164.

@muellerj2 muellerj2 requested a review from a team as a code owner March 25, 2026 21:35
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Mar 25, 2026
@StephanTLavavej StephanTLavavej added bug Something isn't working regex meow is a substring of homeowner labels Mar 26, 2026
@StephanTLavavej StephanTLavavej self-assigned this Mar 26, 2026
Comment thread stl/inc/regex
Comment on lines +4854 to +4856

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pre-existing, no change requested: I believe that _Matches._At(0) could be replaced with _Submatch0.

@StephanTLavavej StephanTLavavej removed their assignment Mar 26, 2026
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Mar 26, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required.

@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Mar 26, 2026
@StephanTLavavej StephanTLavavej merged commit bed5dd5 into microsoft:main Mar 27, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Mar 27, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

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

Labels

bug Something isn't working regex meow is a substring of homeowner

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

<regex>: match_results are not filled correctly when regex_match() and regex_search() are called on a default-constructed basic_regex

3 participants