public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hewillk at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/99752] New: ranges::find_end should return empty subrange when search range is empty
Date: Wed, 24 Mar 2021 14:19:26 +0000	[thread overview]
Message-ID: <bug-99752-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 99752
           Summary: ranges::find_end should return empty subrange when
                    search range is empty
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

In ranges::find_end implementation:

674     else
675       {
676         auto __i = ranges::next(__first1, __last1);
677         if (__first2 == __last2)
678           return {__i, __i};

when the examined range is not bidirectional_range and the search range is
empty, we still do the ranges::next call, this makes the following code
infinite loop:

#include <algorithm>
#include <ranges>

int main() {
  auto r = std::views::iota(0);
  std::ranges::empty_view<int> e;
  std::ranges::find_end(r, e);
}

But according to the [alg.find.end]: "i be last1 if [first2, last2) is empty", 
so I think this is a library bug since in such case ranges::find_end never
return.

Same situations in ranges::rotate with performance loss in more rare
conditions:

1573      {
1574    auto __lasti = ranges::next(__first, __last);
1575    if (__first == __middle)
1576      return {__lasti, __lasti};
1577    if (__last == __middle)
1578      return {std::move(__first), std::move(__lasti)};

             reply	other threads:[~2021-03-24 14:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 14:19 hewillk at gmail dot com [this message]
2021-03-24 14:48 ` [Bug libstdc++/99752] " hewillk at gmail dot com
2021-03-24 14:53 ` hewillk at gmail dot com
2021-03-24 14:56 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99752-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).