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

            Bug ID: 86658
           Summary: Debug mode: std::copy(..., std::inserter(...)) causes
                    "Error: attempt to copy-construct an iterator from a
                    singular iterator."
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

With recent GCC trunk:

> $ cat test.cc
> #define _GLIBCXX_DEBUG
> #include <algorithm>
> #include <iterator>
> #include <vector>
> int main() {
>   std::vector<int> v1{0};
>   std::vector<int> v2;
>   std::copy(v1.begin(), v1.end(), std::inserter(v2, v2.end()));
>   std::copy(v1.begin(), v1.end(), std::inserter(v2, v2.end()));
> }
> 
> $ gcc/inst/bin/g++ --version
> g++ (GCC) 9.0.0 20180724 (experimental)
> Copyright (C) 2018 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> $ gcc/inst/bin/g++ test.cc
> $ LD_LIBRARY_PATH=/home/sbergman/gcc/inst/lib64 ./a.out
> /home/sbergman/gcc/inst/include/c++/9.0.0/debug/safe_iterator.h:140:
> In function:
>     __gnu_debug::_Safe_iterator<_Iterator, _Sequence>::_Safe_iterator(const 
>     __gnu_debug::_Safe_iterator<_Iterator, _Sequence>&) [with _Iterator = 
>     __gnu_cxx::__normal_iterator<int*, std::__cxx1998::vector<int, 
>     std::allocator<int> > >; _Sequence = std::__debug::vector<int>]
> 
> Error: attempt to copy-construct an iterator from a singular iterator.
> 
> Objects involved in the operation:
>     iterator "this" @ 0x0x7fff69d830c8 {
>       type = __gnu_cxx::__normal_iterator<int*, std::__cxx1998::vector<int, 
> std::allocator<int> > > (mutable iterator);
>       state = singular;
>     }
>     iterator "other" @ 0x0x7fff69d83178 {
>       type = __gnu_cxx::__normal_iterator<int*, std::__cxx1998::vector<int, 
> std::allocator<int> > > (mutable iterator);
>       state = singular;
>       references sequence with type 'std::__debug::vector<int, 
> std::allocator<int> >' @ 0x0x7fff69d83280
>     }
> Aborted (core dumped)

Reply via email to