Skip to content

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

Open
frederick-vs-ja wants to merge 2 commits into
microsoft:mainfrom
frederick-vs-ja:lwg-4125
Open

Implement LWG-4125 move_iterator's default constructor should be constrained#6322
frederick-vs-ja wants to merge 2 commits into
microsoft:mainfrom
frederick-vs-ja:lwg-4125

Conversation

@frederick-vs-ja

@frederick-vs-ja 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 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 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.

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

Labels

LWG Library Working Group issue

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

LWG-4125 move_iterator's default constructor should be constrained <xutility>: default_initializable<move_iterator<It>> may be problematic for Clang

4 participants