From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B4FBE386F450; Fri, 5 Mar 2021 09:09:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4FBE386F450 From: "kip at thevertigo dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator Date: Fri, 05 Mar 2021 09:09:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kip at thevertigo 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: Fri, 05 Mar 2021 09:09:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99402 Bug ID: 99402 Summary: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kip at thevertigo dot com Target Milestone: --- The following is a minimal: // Standard C++ / POSIX system headers... #include #include #include using namespace std; int main() { // Container of eleven elements... const set Source =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Goal is to copy the first ten elements in to here, or 0 to 9 inclusi= ve. // It has space for ten elements... vector Destination(10); // This should point to the end of the source range, or element with va= lue // 10 which is the first value after the range to be copied... const auto EndIterator =3D next(cbegin(Source), 10); // This results in memory corruption, or an abort with STL debugging // enabled. copy_n(..., 10, ...) works fine... copy(cbegin(Source), EndIterator, begin(Destination)); return 0; } Compile and run with the following: $ g++-10 -D_GLIBCXX_DEBUG test.cpp -o test -g3 -std=3Dc++17 && ./test=20 I see the following: /usr/include/c++/10/bits/stl_algobase.h:566: In function: _OI std::copy(_II, _II, _OI) [with _II =3D=20 __gnu_debug::_Safe_iterator,=20 std::__debug::set, std::bidirectional_iterator_tag>; _OI =3D=20 __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator > >,=20 std::__debug::vector, std::random_access_iterator_tag>] Error: attempt to subscript a dereferenceable (start-of-sequence) itera= tor=20 11 step from its current position, which falls outside its dereferencea= ble=20 range. Objects involved in the operation: iterator "__result" @ 0x0x7ffc3a448040 { type =3D __gnu_cxx::__normal_iterator > > (mutable iterator); state =3D dereferenceable (start-of-sequence); references sequence with type 'std::__debug::vector >' @ 0x0x7ffc3a4480d0 } Aborted (core dumped) I've been advised from another who ran the same test that this works fine w= ith GCC 8 and 9, so it may be a regression.=