`<regex>`: Tolerate iterators with `explicit` default ctors by StephanTLavavej · Pull Request #6146 · microsoft/STL · GitHub
Skip to content

<regex>: Tolerate iterators with explicit default ctors#6146

Merged
StephanTLavavej merged 1 commit into
microsoft:mainfrom
StephanTLavavej:regex-explicit-default-ctors
Mar 10, 2026
Merged

<regex>: Tolerate iterators with explicit default ctors#6146
StephanTLavavej merged 1 commit into
microsoft:mainfrom
StephanTLavavej:regex-explicit-default-ctors

Conversation

@StephanTLavavej

@StephanTLavavej StephanTLavavej commented Mar 6, 2026

Copy link
Copy Markdown
Member

Fixes internal VSO-2800682.

#6092 followed by #6127 implemented a small buffer optimization storing (potentially user-defined) iterators in an aggregate _Rx_capture_range_t<_BidIt>, then constructing that aggregate with _Ty{}:

STL/stl/inc/regex

Lines 1842 to 1846 in 8f6bbd3


STL/stl/inc/regex

Line 1748 in 8f6bbd3

_STD uninitialized_fill(_Ty_first, _Ty_last, _Ty{}); // uninitialized_value_construct() is C++17

This is sensitive to explicit default ctors, through Standardese that I was previously unfamiliar with. WG21-N5032 [dcl.init.aggr]/5:

For a non-union aggregate, each element that is not an explicitly initialized element is initialized as follows:

  • If the element has a default member initializer ([class.mem]), the element is initialized from that initializer.
  • Otherwise, if the element is not a reference, the element is copy-initialized from an empty initializer list ([dcl.init.list]).
  • Otherwise, the program is ill-formed.

The phrase "copy-initialized from an empty initializer list" is what rejects explicit default ctors.

Interestingly, the Standard requires forward-or-stronger iterators to be default-constructible, but only explicitly.
[forward.iterators]/1.2 "A class or pointer type X meets the Cpp17ForwardIterator requirements if [...] X meets the Cpp17DefaultConstructible requirements", then [tab:cpp17.defaultconstructible] requires only T t;, T u{};, T(), T{}.

We can fix our code by adding DMIs to activate [dcl.init.aggr]/5.1, which is a good idea in any event (helps avoid garbage-init).

Related: notepad-plus-plus/notepad-plus-plus#17816

@StephanTLavavej StephanTLavavej requested a review from a team as a code owner March 6, 2026 19:59
@StephanTLavavej StephanTLavavej added bug Something isn't working regex meow is a substring of homeowner labels Mar 6, 2026
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Mar 6, 2026
@StephanTLavavej StephanTLavavej moved this from Initial Review to Final Review in STL Code Reviews Mar 6, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member Author

@StephanTLavavej StephanTLavavej moved this from Final Review to Merging in STL Code Reviews Mar 9, 2026
@StephanTLavavej StephanTLavavej merged commit 14603b8 into microsoft:main Mar 10, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Mar 10, 2026
@StephanTLavavej StephanTLavavej deleted the regex-explicit-default-ctors branch March 10, 2026 12:45
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.

2 participants