Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -3767,6 +3767,10 @@ namespace ranges {
++_Cur;
if (_Cur == _End) {
_Trailing_empty = true;
} else if constexpr (!forward_range<_Vw>) {
// LWG-4249: inner iteration can exhaust the base range before the sentinel comparison,
// so mark as trailing empty instead of appearing to be at the sentinel.
_Trailing_empty = true;
Comment thread
Copilot marked this conversation as resolved.
}
}
} else {
Expand Down
21 changes: 21 additions & 0 deletions tests/std/tests/P0896R4_views_lazy_split/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cassert>
#include <ranges>
#include <span>
#include <sstream>
#include <string_view>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -383,6 +384,24 @@ void test_lwg_4027() { // COMPILE-ONLY
static_assert(is_const_v<remove_reference_t<R1>>);
}

void test_lwg_4249() {
// Iterating over an inner range advances the shared current, so the outer iterator can only be
// incremented once more before reaching the end; it must not compare equal to default_sentinel
// in between.
istringstream is{"1 0 2"};
auto plain = views::istream<int>(is) | views::lazy_split(0);
auto j = plain.begin();
assert(j != plain.end());
assert(ranges::equal(*j, views::single(1)));
assert(j != plain.end());
++j;
assert(j != plain.end());
assert(ranges::equal(*j, views::single(2)));
Comment thread
tycket033-tech marked this conversation as resolved.
assert(j != plain.end());
++j;
assert(j == plain.end());
}

int main() {
static_assert(instantiation_test());
instantiation_test();
Expand All @@ -392,4 +411,6 @@ int main() {

static_assert(test_lwg_3904());
assert(test_lwg_3904());

test_lwg_4249();
}