[Bug c++/89688] New: -Wstringop-overflow confused by 2D array of char

redbeard0531 at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Mar 12 19:04:00 GMT 2019


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

            Bug ID: 89688
           Summary: -Wstringop-overflow confused by 2D array of char
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redbeard0531 at gmail dot com
  Target Milestone: ---

Also, for some reason it repeats the warning 3 times.

https://godbolt.org/z/SStUsl

// Fine
extern const char a[2] = {'1'};
auto z = __builtin_strlen(a);

// Warns
extern const char aa[1][2] = {{'2'}};
auto zz = __builtin_strlen(aa[0]);



> ~/opensource/gcc/prefix/bin/g++ -Wall str.cpp  -fsyntax-only
str.cpp:7:27: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
    7 | auto zz = __builtin_strlen(aa[0]);
      |           ~~~~~~~~~~~~~~~~^~~~~~~
str.cpp:6:19: note: referenced argument declared here
    6 | extern const char aa[1][2] = {{'2'}};
      |                   ^~
str.cpp:7:27: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
    7 | auto zz = __builtin_strlen(aa[0]);
      |           ~~~~~~~~~~~~~~~~^~~~~~~
str.cpp:6:19: note: referenced argument declared here
    6 | extern const char aa[1][2] = {{'2'}};
      |                   ^~
str.cpp:7:32: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
    7 | auto zz = __builtin_strlen(aa[0]);
      |                            ~~~~^
str.cpp:6:19: note: referenced argument declared here
    6 | extern const char aa[1][2] = {{'2'}};
      |                   ^~


Reduced example from real code at:
https://github.com/boostorg/date_time/blob/b0437e2999a65668dc4178dbb817a89a382ece94/include/boost/date_time/special_values_formatter.hpp#L89-L92
+
https://github.com/boostorg/date_time/blob/b0437e2999a65668dc4178dbb817a89a382ece94/include/boost/date_time/special_values_formatter.hpp#L43-L45


More information about the Gcc-bugs mailing list