https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84555
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Status|UNCONFIRMED |NEW Last reconfirmed| |2018-02-26 CC| |msebor at gcc dot gnu.org Summary|strncpy warnings (and |middle-end warnings are not |friends) are not ignorable |ignorable with pragmas when |with pragmas when inlined |inlined Ever confirmed|0 |1 --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- I can confirm this doesn't work as you would expect. Unfortunately, the problem isn't limited to just -Wstringop-truncation but affects many if not all middle-end warnings. Here's another example with -Wformat-truncation. -Wnonnull has the same problem. $ cat b.c && gcc -O2 -S -Wall b.c void g (char *d, unsigned n, const char *s, int i) { __builtin_snprintf (d, n, "%s-%i", s, i); } char a[8], b[8]; void h (int i) { #pragma GCC diagnostic ignored "-Wformat-truncation" g (a, sizeof a, b, i); } b.c: In function ‘h’: b.c:3:33: warning: ‘%i’ directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 7 [-Wformat-truncation=] __builtin_snprintf (d, n, "%s-%i", s, i); ^~ b.c:3:3: note: ‘__builtin_snprintf’ output between 3 and 20 bytes into a destination of size 8 __builtin_snprintf (d, n, "%s-%i", s, i); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~