public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
@ 2021-03-05  9:09 kip at thevertigo dot com
  2021-03-05 12:16 ` [Bug libstdc++/99402] [10/11 Regression] " redi at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: kip at thevertigo dot com @ 2021-03-05  9:09 UTC (permalink / raw)
  To: gcc-bugs

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

            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 <algorithm>
#include <set>
#include <vector>

using namespace std;

int main()
{
    // Container of eleven elements...
    const set<int> Source = { 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 inclusive.
    //  It has space for ten elements...
    vector<int> Destination(10);

    // This should point to the end of the source range, or element with value
    //  10 which is the first value after the range to be copied...
    const auto EndIterator = 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=c++17 && ./test 

I see the following:

    /usr/include/c++/10/bits/stl_algobase.h:566:
    In function:
        _OI std::copy(_II, _II, _OI) [with _II = 
        __gnu_debug::_Safe_iterator<std::_Rb_tree_const_iterator<int>, 
        std::__debug::set<int>, std::bidirectional_iterator_tag>; _OI = 
        __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<int*, 
        std::__cxx1998::vector<int, std::allocator<int> > >, 
        std::__debug::vector<int>, std::random_access_iterator_tag>]

    Error: attempt to subscript a dereferenceable (start-of-sequence) iterator 
    11 step from its current position, which falls outside its dereferenceable 
    range.

    Objects involved in the operation:
        iterator "__result" @ 0x0x7ffc3a448040 {
          type = __gnu_cxx::__normal_iterator<int*, std::__cxx1998::vector<int,
std::allocator<int> > > (mutable iterator);
          state = dereferenceable (start-of-sequence);
          references sequence with type 'std::__debug::vector<int,
std::allocator<int> >' @ 0x0x7ffc3a4480d0
        }
    Aborted (core dumped)

I've been advised from another who ran the same test that this works fine with
GCC 8 and 9, so it may be a regression.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-04-23 13:04 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05  9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
2021-03-05 12:16 ` [Bug libstdc++/99402] [10/11 Regression] " redi at gcc dot gnu.org
2021-03-05 12:30 ` redi at gcc dot gnu.org
2021-03-05 12:33 ` redi at gcc dot gnu.org
2021-03-05 12:40 ` redi at gcc dot gnu.org
2021-03-05 12:55 ` redi at gcc dot gnu.org
2021-03-05 12:59 ` redi at gcc dot gnu.org
2021-03-05 19:26 ` fdumont at gcc dot gnu.org
2021-03-05 20:00 ` kip at thevertigo dot com
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
2021-04-08 12:53 ` rguenth at gcc dot gnu.org
2021-04-13 20:51 ` [Bug libstdc++/99402] [10 " redi at gcc dot gnu.org
2021-04-13 22:19 ` kip at thevertigo dot com
2021-04-13 22:45 ` redi at gcc dot gnu.org
2021-04-23 12:02 ` fdumont at gcc dot gnu.org
2021-04-23 13:04 ` redi at gcc dot gnu.org

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).