The primary template for _CachedPosition is a dummy implementation for
non-forward ranges, the iterators for which generally can't be cached.
Because this implementation doesn't actually cache anything, _M_has_value
is defined to be false and so calls to _M_get (which are always guarded
by _M_has_value) are unreachable.
Still, to suppress a "control reaches end of non-void function" warning
I made _M_get return {}, but after P2325 input iterators are no longer
necessarily default constructible so this workaround now breaks valid
programs.
This patch fixes this by instead using __builtin_unreachable to squelch
the warning.
PR libstdc++/101231
libstdc++-v3/ChangeLog:
* include/std/ranges (_CachedPosition::_M_get): For non-forward
ranges, just call __builtin_unreachable.
* testsuite/std/ranges/istream_view.cc (test05): New test.
_M_get(const _Range&) const
{
__glibcxx_assert(false);
- return {};
+ __builtin_unreachable();
}
constexpr void
static_assert(!std::forward_iterator<It>);
}
+void
+test05()
+{
+ // PR libstdc++/101231
+ auto words = std::istringstream{"42"};
+ auto is = ranges::istream_view<int>(words);
+ auto r = is | views::filter([](auto) { return true; });
+ for (auto x : r)
+ ;
+}
+
int
main()
{
test02();
test03();
test04();
+ test05();
}