char *strncpy (char *, const char *, __SIZE_TYPE__); struct S { char arr[64]; }; int foo (struct S *p1, const char *a) { if (a) goto err; strncpy (p1->arr, a, sizeof p1->arr); p1->arr[3] = '\0'; err: return 0; } $ ./cc1 -quiet t.c -Wstringop-truncation -O2 -g t.c: In function ‘foo’: t.c:12:3: warning: ‘strncpy’ specified bound 64 equals destination size [-Wstringop-truncation] strncpy (p1->arr, a, sizeof p1->arr); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ the warning is gone without -g.
I have a fix.
Author: mpolacek Date: Tue Feb 6 13:25:54 2018 New Revision: 257411 URL: https://gcc.gnu.org/viewcvs?rev=257411&root=gcc&view=rev Log: PR tree-optimization/84228 * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Skip debug statements. * c-c++-common/Wstringop-truncation-3.c: New test. Added: trunk/gcc/testsuite/c-c++-common/Wstringop-truncation-3.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-strlen.c
Fixed.