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

            Bug ID: 84555
           Summary: strncpy warnings (and friends) are not ignorable with
                    pragmas when inlined
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.geissler at amadeus dot com
  Target Milestone: ---

Hi,

I have hit this case today. Let's consider that for any reason, you have a
wrapper around strncpy (and friends). Then it looks like that #pragma diagnotic
that are used around the call site of the wrapper are ignored in -O2 when gcc
does some inlining.

Example (built with -Wall -Werror -Wextra -O2):

<<EOF
char* strncpy_wrapper(char* dest, const char* source, int size) 
{
    return __builtin_strncpy(dest, source, size);
}           

void f()
{
    char buff[3];

#   pragma GCC diagnostic push 
#   pragma GCC diagnostic ignored "-Wstringop-truncation"
    strncpy_wrapper(buff, "123", 3);
#   pragma GCC diagnostic pop
}
EOF

Of course, here this is a degenerate example. But in real code, this kind of
cases might happen, you know what you want to do, and want to ignore gcc errors
just for specific cases, but you can't.

Cheers,
Romain

Reply via email to