https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122194
Bug ID: 122194
Summary: flat_bug iterators not random access
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: terra at gnome dot org
Target Milestone: ---
Created attachment 62519
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62519&action=edit
Preprocessed source
It looks like flat_map's iterators are just input_iterator.
I read the spec as requiring random access. I note that a reverse_iterator
is required which doesn't make sense without at least bidirectional
iterators (which is what the program below actually checks for).
$ cat flatbug.C
#include <flat_map>
#include <iostream>
int
main()
{
std::flat_map<int,int> m;
m[1] = 2;
auto it = m.end();
auto it2 = std::prev(it);
std::cerr << it2->first << std::endl;
return 0;
}
# Not optimized
$ g++ -std=gnu++23 flatbug.C
$ ./a.out
/usr/local/products/gcc/15.1.0/include/c++/15.1.0/bits/stl_iterator_base_funcs.h:163:
constexpr void std::__advance(_InputIterator&, _Distance, input_iterator_tag)
[with _InputIterator = _Flat_map_impl<int, int, less<int>, vector<int,
allocator<int> >, vector<int, allocator<int> >, false>::_Iterator<false>;
_Distance = long int]: Assertion '__n >= 0' failed.
Aborted (core dumped)
(Expected to print "1", not assert.)
$ g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/products/gcc/15.1.0/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/products/gcc/15.1.0/lib/gcc/x86_64-suse-linux/15.1.0/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../../gcc-15.1.0/configure
--enable-languages=c,c++,fortran,jit --enable-host-shared --with-pic
--enable-targets=x86_64-suse-linux,i686-suse-linux
--prefix=/usr/local/products/gcc/15.1.0 --with-gnu-as
--with-as=/usr/local/products/gcc/binutils-2.44/bin/as
--with-ld=/usr/local/products/gcc/binutils-2.44/bin/ld.gold --enable-link-mutex
--enable-gnu-indirect-functions --enable-linux-futex --enable-threads=posix
--enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new
x86_64-suse-linux --enable-libstdcxx-backtrace=yes --with-zstd
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.1.0 (GCC)