https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105720
Bug ID: 105720 Summary: std::views::split_view wrong behaviour in case of partial match Product: gcc Version: 10.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: andij.cr at gmail dot com Target Milestone: --- compiled with g++-10 -std=c++20 split_view_wrong.cpp -lfmt godbolt link https://gcc.godbolt.org/z/47TxWovd4 fmtlib used for exposition only #include <fmt/printf.h> #include <fmt/ranges.h> #include <ranges> #include <string_view> auto words_no_bug = std::string_view{"Hello-_-C++-_-20-_-!-_-"}; auto words_bug = std::string_view{"Hello--_-C++-_-20-_-!-_-"}; auto delim = std::string_view{"-_-"}; // needed because split_view is lazy in gcc 10.3 auto range_to_str = [](auto &&r) { return fmt::format("{}", fmt::join(r, "")); }; int main() { fmt::print("no bug: '{}' tokens: {}\n", words_no_bug, words_no_bug | std::views::split(delim) | std::views::transform(range_to_str)); fmt::print("bug: '{}' tokens: {}\n", words_bug, words_bug | std::views::split(delim) | std::views::transform(range_to_str)); } this code applies split to tokenize a text compiled with gcc-10.3 it wrongly produces no bug: 'Hello-_-C++-_-20-_-!-_-' tokens: ["Hello", "C++", "20", "!"] bug: 'Hello--_-C++-_-20-_-!-_-' tokens: ["Hello-", "20", "!"] while compiled with gcc-11.3 is correctly produces no bug: 'Hello-_-C++-_-20-_-!-_-' tokens: ["Hello", "C++", "20", "!"] bug: 'Hello--_-C++-_-20-_-!-_-' tokens: ["Hello-", "C++", "20", "!"] notice how the substring "--_-C++" instead of being split in ["-", "C++"] is split as ["-"], skipping the "C++" token. it's fixed from gcc-11, but i couldn't find a mention in the release notes about it