https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115799
Bug ID: 115799 Summary: ranges::find's optimized branching for memchr is not quite right Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: hewillk at gmail dot com Target Milestone: --- ranges_util.h#L505: if constexpr (is_same_v<_Proj, identity>) if constexpr(__can_use_memchr_for_find<iter_value_t<_Iter>, _Tp>) if constexpr (sized_sentinel_for<_Sent, _Iter>) if constexpr (contiguous_iterator<_Iter>) if (!is_constant_evaluated()) { if (static_cast<iter_value_t<_Iter>>(__value) != __value) return __last; We should return __first + __n as __last may not be convertible to __first, for example: std::string s; auto r = std::ranges::find(std::counted_iterator{s.begin(), 3}, std::default_sentinel, ' ');