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

--- Comment #28 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If I revert r12-5874-gf8463b0e3ec2438b (which suppressed all these warnings
from std::char_traits) then I get a -Warray-bounds warning from the comment 0
code instead of -Wstringop-overread:

    inlined from 'void c(int) [with int a = 1]' at mcf.cc:4:8:
/home/jwakely/gcc/14/include/c++/14.2.1/bits/char_traits.h:427:56: warning:
'void* __builtin_memcpy(void*, const void*, long unsigned int)' forming offset
1 is out of the bounds [0, 1] of object 'buffer' with type 'char [1]'
[-Warray-bounds=]
  427 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2,
__n));
      |                                       
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
mcf.cc: In function 'void c(int) [with int a = 1]':
mcf.cc:3:8: note: 'buffer' declared here
    3 |   char buffer[a] = {};
      |        ^~~~~~

And contrary to comment 3, this happens even at -O3 so it's not a lack of
inlining that prevents the compiler seeing the actual size read from the
buffer.

Reply via email to