From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5B0C33857C5F; Wed, 24 Mar 2021 14:19:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B0C33857C5F From: "hewillk at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hewillk at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Mar 2021 14:19:26 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99752 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 =3D ranges::next(__first1, __last1); 677 if (__first2 =3D=3D __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 #include int main() { auto r =3D std::views::iota(0); std::ranges::empty_view e; std::ranges::find_end(r, e); } But according to the [alg.find.end]: "i be last1 if [first2, last2) is empt= y",=20 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 =3D ranges::next(__first, __last); 1575 if (__first =3D=3D __middle) 1576 return {__lasti, __lasti}; 1577 if (__last =3D=3D __middle) 1578 return {std::move(__first), std::move(__lasti)};=