I'm playing with C++20 ranges with GCC implementations (v10.2 & v11).
To test the behavior of std::views::join
, I tried to generate a nested view using single
and then I flat it using join
.
#include <ranges>
#include <iostream>
int main() {
auto data = std::views::single(1);
auto v =
data
| std::views::transform([](const auto &s) { return std::views::single(s); })
| std::views::join
;
for (auto &&x : v) { // Infinite loop + segfault
std::cout << x << '\n';
}
}
I expected to find one iterator of the for loop with the initial value (1). But no... It goes into an infinite loop which segfaults since I use the value.
If I replace the nested std::views::single
with std::views::iota(a,b)
or std::views::empty<int>
, the behavior is perfectly OK.
Do you have an idea if this is the correct expected behavior (and why)?
edit
std::ranges::next(v.begin()) == v.end()
must be true.
This was a bug in GCC 10.3 and 11.1 .
It has been fixed in GCC trunk and 11.1.1 .