Skip to content

Implement LWG-4259 P1148R0 changed the return values of searching functions of std::basic_string on some platforms - #6236

Merged
Stephan T. Lavavej (StephanTLavavej) merged 19 commits into
microsoft:mainfrom
YexuanXiao:wide-npos
Jul 21, 2026

Conversation

@YexuanXiao

@YexuanXiao Yexuan Xiao (YexuanXiao) commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #6208.

…nctions of std::basic_string on some platforms
Comment thread stl/inc/xstring Outdated
@YexuanXiao Yexuan Xiao (YexuanXiao) changed the title Implement LWG-4259: P1148R0 changed the return values of searching fu… Apr 8, 2026
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the LWG Library Working Group issue label Apr 8, 2026
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) changed the title Implement LWG-4259 P1148R0 changed the return values of searching fu… Apr 8, 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

Implements the LWG-4259/P1148R0 behavior change so std::basic_string searching functions return basic_string::npos (not a truncated size_t(-1)/string_view::npos) when basic_string::size_type is wider than size_t, and adds a regression test for that scenario.

Changes:

  • Add an internal helper to cast search results from size_t to basic_string::size_type, mapping size_t(-1) to basic_string::npos when needed.
  • Update all basic_string search-family functions (find*/rfind*) to use the helper.
  • Add a test using a custom allocator with a wider size_type to validate npos return values.
Show a summary per file
File Description
tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Adds a wide-size_type allocator + new test cases covering basic_string search functions returning npos.
stl/inc/xstring Fixes return-value casting for basic_string searching functions when size_type is wider than size_t.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 3
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread stl/inc/xstring Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Comment thread tests/std/tests/GH_005546_containers_size_type_cast/test.cpp Outdated
Copilot AI review requested due to automatic review settings July 20, 2026 19:46
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks! 😻 I pushed a bunch of nitpicky changes.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Initial Review to Ready To Merge in STL Code Reviews Jul 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.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Medium
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Ready To Merge to Merging in STL Code Reviews Jul 20, 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) merged commit 3a79198 into microsoft:main Jul 21, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Jul 21, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for implementing this LWG issue resolution, and apologies for how long it took to review this! 😹 🎉 🚀

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