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

            Bug ID: 107004
           Summary: GCC12 warning in OOB access: array subscript is partly
                    outside array bounds
           Product: gcc
           Version: 12.2.0
               URL: https://godbolt.org/z/aoYh66EYb
            Status: UNCONFIRMED
          Keywords: TREE
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rogerio.souza at gmail dot com
  Target Milestone: ---

The code below triggers the warning:

/opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_construct.h:119:7:
warning: array subscript 'int*[0]' is partly outside array bounds of 'unsigned
char [8]' [-Warray-bounds]
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Source code:

#include <vector>
#include <cassert>

void foo(std::vector<int*>& v)
{
    assert(v.size() >= 1);
    v.resize(1);
}

Build command line:
g++ -std=c++20 -Wall -Wextra -pedantic -O3

Using -O2 prevents the warning, also if we use "-Wno-array-bounds". This issue
is not reproducible on GCC 11.3 or older.

Would this issue be a duplicate from
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105348?

The issue could be reproduced on Compiler Explorer:
https://godbolt.org/z/aoYh66EYb

Regards,
Rogerio

Reply via email to