public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114775] New: on mingw __attribute__ ((__format__ (__printf__, ...))) doesn't recognize C99 specifiers
@ 2024-04-18 20:48 nok.raven at gmail dot com
  2024-04-18 20:57 ` [Bug target/114775] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: nok.raven at gmail dot com @ 2024-04-18 20:48 UTC (permalink / raw)
  To: gcc-bugs

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`.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-04-19  3:15 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-18 20:48 [Bug target/114775] New: on mingw __attribute__ ((__format__ (__printf__, ...))) doesn't recognize C99 specifiers nok.raven at gmail dot com
2024-04-18 20:57 ` [Bug target/114775] " pinskia at gcc dot gnu.org
2024-04-18 21:05 ` pinskia at gcc dot gnu.org
2024-04-18 21:05 ` pinskia at gcc dot gnu.org
2024-04-18 21:13 ` pinskia at gcc dot gnu.org
2024-04-18 21:15 ` nok.raven at gmail dot com
2024-04-18 21:19 ` pinskia at gcc dot gnu.org
2024-04-18 21:35 ` nok.raven at gmail dot com
2024-04-18 21:37 ` pinskia at gcc dot gnu.org
2024-04-18 22:31 ` nok.raven at gmail dot com
2024-04-18 22:36 ` pinskia at gcc dot gnu.org
2024-04-19  2:43 ` nok.raven at gmail dot com
2024-04-19  2:51 ` pinskia at gcc dot gnu.org
2024-04-19  3:15 ` nok.raven at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).