Skip to content

Fix find of an empty substring at the end of a string_view - #63

Merged
martinmoene merged 1 commit into
nonstd-lite:masterfrom
fhgffy:fix-empty-find-end
Oct 5, 2026
Merged

martinmoene merged 1 commit into
nonstd-lite:masterfrom
fhgffy:fix-empty-find-end

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

An empty substring should match at pos whenever pos <= size(). The nonstd implementation currently returns npos at pos == size(), including when both views are empty.

Handle this valid empty match before the existing boundary check and search-result conversion. The existing nonempty search path and rejection of positions beyond the end remain unchanged.

Add regression coverage for the view, C-string and counted-pointer overloads; default/literal empty views; interior, end, beyond-end and npos positions; nonempty controls; wide characters; and C++14-and-later constant evaluation.

Validation

Tested locally on Linux x86_64 with GCC 14.2.0:

  • New tests fail on upstream 2b39e871c60f615e91f27b52881d9552ce4d0a6c: runtime failures in C++98/11 and four failing constant-expression assertions in C++14/17/20
  • Patched upstream suite: all 93 cases pass in C++98/11/14/17/20 at both -O0 and -O2, using the default search configuration
  • Official CMake Release build, including examples, and all four CTests pass
  • Direct comparison with std::basic_string_view: all 384 checks pass for each C++17/20 × -O0/-O2 run, covering char, wchar_t, char16_t and char32_t

Clang, MSVC, older compiler versions and remote CI have not been run locally.

@fhgffy
fhgffy marked this pull request as ready for review October 5, 2026 06:32
@martinmoene
martinmoene merged commit dadf871 into nonstd-lite:master Oct 5, 2026
9 checks passed
martinmoene added a commit that referenced this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants