Skip to content

Implement LWG-4125 move_iterator's default constructor should be constrained - #6322

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
frederick-vs-ja:lwg-4125
Jul 11, 2026
Merged

Implement LWG-4125 move_iterator's default constructor should be constrained#6322
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
frederick-vs-ja:lwg-4125

Conversation

@frederick-vs-ja

@frederick-vs-ja A. Jiang (frederick-vs-ja) commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #6314. Fixes #3377 (by making LLVM-60293 and VSO-1900294 no longer relevant).

Unblocked libcxx test(s):

  • std/iterators/predef.iterators/move.iterators/move.iterator/iterator_concept_conformance.compile.pass.cpp

Remarks:

  • The associated constraint is added since C++20, which is consistent with WG21-P2325R3 that is clearly a DR against C++20.
  • This PR also uses the default member initializer = _Iter(); in C++14 mode. Due to lack of guaranteed copy elision in C++14, such default member initializer would cause one more move construction when RVO is not performed. The move construction is required to be well-formed, and in most (but not all) situations it won't cause side effects.
  • Pre-existing default member initializer {} accepts invalid cases. E.g. empty_list_input_iter added to the test file can be direct-list-initialized from {}, but can't be value initialized. So the default constructor of empty_list_input_iter should be ill-formed in old modes.
Copilot AI review requested due to automatic review settings June 20, 2026 10:48
@frederick-vs-ja
A. Jiang (frederick-vs-ja) requested a review from a team as a code owner June 20, 2026 10:48
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Jun 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the LWG-4125 resolution, which constrains move_iterator's default constructor so it only participates when the underlying iterator type is default-initializable. This also resolves the long-standing Clang/EDG divergence described in #3377 (LLVM-60293) by ensuring the default constructor is genuinely absent — rather than present-but-deleted via a default member initializer — for non-default-initializable iterators.

Changes:

  • In <xutility>, move_iterator's defaulted default constructor gains a requires default_initializable<_Iter> constraint (C++20), and the _Current member initializer changes from list-init {} to value-init _Iter() (C++17) to avoid wrongly selecting an initializer_list constructor; in C++14 the default constructor becomes user-provided (: _Current()) and intentionally non-constexpr.
  • Adds tests for the new constraint, including a new empty_list_input_iter helper that is initializable via {} but not value-initializable.
  • Removes the now-unnecessary __clang__/__EDG__ workaround in the join_with test that previously guarded the range-of-rvalue delimiter case.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
stl/inc/xutility Constrains move_iterator() with default_initializable<_Iter> (C++20), switches the member initializer to value-init, and restructures the constructor across C++14/17/20 modes.
tests/std/tests/P0896R4_ranges_iterator_machinery/test.cpp Adds empty_list_input_iter and static_asserts validating default_initializable<move_iterator<...>> and iterator-category metaprogramming.
tests/std/tests/P2441R2_views_join_with/test.cpp Removes the LLVM-60293/VSO-1900294 workaround now that the root cause is fixed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stl/inc/xutility Outdated
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the LWG Library Working Group issue label Jun 22, 2026
Copilot AI review requested due to automatic review settings June 23, 2026 05:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Initial Review to Ready To Merge in STL Code Reviews Jul 9, 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 Stephan T. Lavavej (StephanTLavavej) moved this from Ready To Merge to Merging in STL Code Reviews Jul 10, 2026
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 3731b3d into microsoft:main Jul 11, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Jul 11, 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

LWG Library Working Group issue

4 participants