https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91890
--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> --- 333 Warray-bounds 334 LangEnabledBy(C ObjC C++ LTO ObjC++) 335 ; in common.opt This seems wrong, the second argument ", Wall" is missing. Moreover, this probably should be an Alias for some -Warray-bounds= option. Nevertheless, there is indeed something weird going on with the locations of the #pragma: char one[50]; char two[50]; void test_strncat (void) { #pragma GCC diagnostic error "-Warray-bounds" (void) __builtin_strncat (one, two, 99); (void) __builtin_strcpy (one, "gh"); #pragma GCC diagnostic warning "-Warray-bounds" (void) __builtin_strcpy (two, "ef"); (void) __builtin_strncat (one, two, 99); } // -O2 -Warray-bounds gives 2 errors. It seems that if the #pragma is at the start of the function, it has effect, otherwise it doesn't.