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

            Bug ID: 87183
           Summary: -Wformat: format-extra-args fails to catch ex:
                    printf(PRIu32, 1)
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: noah.pendleton at gmail dot com
  Target Milestone: ---

Created attachment 44644
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44644&action=edit
preprocessed file

>>Description:
Using <inttypes.h> format specifiers but omitting the `%` prefix causes the
`-Werror=format-extra-args` error to not be omitted:

```c
    #include <inttypes.h>

    printf(PRIu32, 2);     // doesn't warn
    printf(PRIu32 "", 2);  // doesn't warn
    printf("u", 2);        // warns
    printf("" PRIu32, 2);  // warns
```

Interestingly, defining PRIu32 in the test file and not using <inttypes.h>
yields the expected behavior, eg:

```c
    #define PRIu32 "u"

    printf(PRIu32, 2);     // warns
    printf(PRIu32 "", 2);  // warns
    printf("u", 2);        // warns
    printf("" PRIu32, 2);  // warns
```

>>Info:
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran
--disable-multilib --disable-bootstrap --build=x86_64-linux-gnu
Thread model: posix
gcc version 9.0.0 20180831 (experimental) (GCC)

>>Complete Command Line:
gcc -Wall -Werror test.c

>>Complete Compiler Output:
test.c: In function 'main':
test.c:7:12: error: too many arguments for format [-Werror=format-extra-args]
7 |     printf("u", 2);        // fails
  |            ^~~
test.c:8:12: error: too many arguments for format [-Werror=format-extra-args]
8 |     printf("" PRIu32, 2);  // fails
  |            ^~
cc1: all warnings being treated as errors

>>Preprocessed file attached.

Reply via email to