GCC-7.3 and later apply wrong -Wformat attributes for snprintf() and vsnprintf() functions
There is, in fact, a defect in the MinGW -Wformat handler; it affects the handling of the "%n" conversion specification, when specified with the "hh" length modifier, (i.e. as "%hhn"). Although this combination is fully supported by the underlying pformat.c implementation, the associated -Wformat handler does not recognize this, and consequently emits an entirely bogus, and unhelpful warning, when this is parsed.
Fixing this isn't difficult, but it does require a (tedious) rebuild of GCC, to deploy it.
The -Wformat mishandling of "%hhn" is corrected from release 4-mingw32 of GCC-8.2.0 onwards; at present, I do not plan to back-port to GCC-7.3.0 .
The inappropriate effect of interaction with GCC's built-in snprintf() and vsnprintf() prototypes is corrected by commit #21718ad; this will be included in the next mingwrt/w32api release.
As originally reported by Eli Zaretskii, in this mingw-users mail posting, use of ISO-C99 standard format specifications, such as "%02hhx", (which is not understood by Microsoft's MSVCRT.DLL family of printf() functions), in calls to snprintf() may result in unexpected compile-time warning diagnostics, when compiled with any warning option, such as -Wall, which implicitly (or even explicitly) enables -Wformat.
The issue appears to be caused by GCC's use of an internal prototype, for snprintf(), which seems to arbitrarily assume Microsoft's -Wformat semantics, (even though Microsoft have never provided a snprintf() implementation, in any version of the system-supplied MSVCRT.DLL runtime library, on which every MinGW-GCC compiler build is dependent). The issue does not arise when calls to snprintf() are replaced by its equivalent __mingw_snprintf(), (which is explicitly declared as exhibiting MinGW's -Wformat semantics); nor does it arise when GCC's internal prototype is overridden, (by use of the -fno-builtin-snprintf option), and thus the <stdio.h> prototype, (which also explicitly exhibits MinGW's -Wformat semantics), becomes applicable.
It is anticipated that the vsnprintf() implementation will be similarly affected.