[Bug c++/65861] libstdc++ is silently generating wrong code when its std::search is given an input iterator

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 6 14:06:43 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65861

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #9)
> There are actually good reasons *not* to reject input iterators at
> compile-time.
> 
> You could have an iterator which meets most, but not all, the forward
> iterator requirements, and so must have input_iterator_tag as its category.
> Such as iterator could work fine with std::search, if we don't reject it via
> a static assertion.
> 
> (istreambuf_iterator is not such an iterator, as it's genuinely a
> single-pass iterator, and so can't be used ... but we can't reliably detect
> that as the only property we can test is the iterator_category tag).

Since C++20 we can also check the iterator_concept tag. That means we can allow
iterators that identify as input iterators according to iterator_category, but
forward iterators (or stronger) according to iterator_concept.


More information about the Gcc-bugs mailing list