<regex>: Avoid generating empty groups when parsing ? quantifiers#6267
Merged
StephanTLavavej merged 1 commit intoMay 15, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Removes unnecessary empty-group nodes from the generated NFA for ? quantifiers (including lazy ??), and adds a regression test to lock in the intended behavior.
Changes:
- Simplify NFA construction for
?by linking the empty alternative directly to_Endinstead of emitting an empty group. - Adjust the non-greedy (
??) pointer rewiring logic, using explicit assignments and_STD swap. - Add
GH-6267tests fora?vsa??match/search behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/std/tests/VSO_0000000_regex_use/test.cpp | Adds GH-6267 regression coverage for greedy vs lazy optional quantifiers. |
| stl/inc/regex | Removes empty-group nodes for ? and tweaks non-greedy rewiring logic accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
StephanTLavavej
approved these changes
May 14, 2026
Member
|
I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required. |
Member
|
Thanks for continuing to find ways to improve |
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.
Towards #5962. The parser currently generates empty groups when it represents zero-one quantifiers like
?by a_N_ifnode with an empty alternative, just as it did for empty alternatives in general before #6249. This removes this empty group from the generated NFA because it's completely unnecessary.Drive-by change: Replace the first
swap()call by explicit assignments, and qualify the otherswap()call because the nodes are STL-internal types, so ADL is not needed here.