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

--- Comment #2 from Sam James <sjames at gcc dot gnu.org> ---
It shows up with Qing's patch nicely:
```
$ g++ p.cxx -fdiagnostics-show-context=3 -Warray-bounds -O3 -c
-U_GLIBCXX_ASSERTIONS
p.cxx: In function ‘void vector_func_2(std::vector<int>&)’:
p.cxx:15:43: warning: array subscript -1 is outside array bounds of ‘int
[2305843009213693951]’ [-Warray-bounds=]
   15 |     if (vect_copy.front() < vect_copy.back()) {
      |                             ~~~~~~~~~~~~~~^~
  ‘void vector_func_2(std::vector<int>&)’: event 1
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_uninitialized.h:290:11:
  290 |           if (__n > 0) [[__likely__]]
      |           ^~
      |           |
      |           (1) when the condition is evaluated to false
  ‘void vector_func_2(std::vector<int>&)’: event 2
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:1110:9:
 1110 |         if (__dif < 0)
      |         ^~
      |         |
      |         (2) when the condition is evaluated to false
  ‘void vector_func_2(std::vector<int>&)’: event 3
p.cxx:15:43:
   15 |     if (vect_copy.front() < vect_copy.back()) {
      |                             ~~~~~~~~~~~~~~^~
      |                                           |
      |                                           (3) warning happens here
In file included from
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
                 from
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/allocator.h:46,
                 from
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/vector:65,
                 from p.cxx:1:
In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, const
void*) [with _Tp = int]’,
    inlined from ‘static _Tp* std::allocator_traits<std::allocator<_Tp1>
>::allocate(allocator_type&, size_type) [with _Tp = int]’ at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/alloc_traits.h:614:28,
    inlined from ‘std::_Vector_base<_Tp, _Alloc>::pointer
std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = int;
_Alloc = std::allocator<int>]’ at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:389:33,
    inlined from ‘void std::_Vector_base<_Tp,
_Alloc>::_M_create_storage(std::size_t) [with _Tp = int; _Alloc =
std::allocator<int>]’ at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:407:44,
    inlined from ‘std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t,
const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>]’ at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:341:26,
    inlined from ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp,
_Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]’ at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:623:61,
    inlined from ‘void vector_func_2(std::vector<int>&)’ at p.cxx:14:34:
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/new_allocator.h:151:73:
note: at offset -4 into object of size [4, 9223372036854775804] allocated by
‘operator new’
  151 |         return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
      |                                                                        
^
```

Reply via email to