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

            Bug ID: 114775
           Summary: on mingw __attribute__ ((__format__ (__printf__,
                    ...))) doesn't recognize C99 specifiers
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nok.raven at gmail dot com
  Target Milestone: ---
            Target: *-w64-mingw32

#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)

void _bfd_error_handler (const char *fmt, ...) ATTRIBUTE_PRINTF_1;

void foo(void) { _bfd_error_handler("%zu\n", sizeof(0)); }

$ gcc -Wall -c bug.c -std=c99
bug.c: In function 'foo':
bug.c:6:39: warning: unknown conversion type character 'z' in format
[-Wformat=]
    6 | void foo(void) { _bfd_error_handler("%zu\n", sizeof(0)); }
      |                                       ^
bug.c:6:37: warning: too many arguments for format [-Wformat-extra-args]
    6 | void foo(void) { _bfd_error_handler("%zu\n", sizeof(0)); }
      |                                     ^~~~~~~


>From my understanding the warning should not happen when
`__USE_MINGW_ANSI_STDIO=1`, the difficulty is that it's set in `_mingw.h`, not
in GCC itself, and could be set by a user or by other headers.

Possible solutions:
1) Lookup real `printf` declaration, but it won't be there if the code doesn't
include `stdio.h`. False positives.
2) Query `__USE_MINGW_ANSI_STDIO` and fall back to the used C mode. Code that
sets `__USE_MINGW_ANSI_STDIO` different from default value could get false
positives on C89 and false negatives on C99, the logic for default value of
`__USE_MINGW_ANSI_STDIO` in `_mingw.h` is more complicated than just current C
mode.
3) Make GCC always be fine with C99 specifiers for now.

Any of the solutions above would be better than `-Wno-format`.

Reply via email to