[Bug c++/68052] No printf format warnings in C++ code for macro in system headers

xyzzy at speakeasy dot org gcc-bugzilla@gcc.gnu.org
Fri Oct 6 21:21:00 GMT 2017


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

Trent Piepho <xyzzy at speakeasy dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xyzzy at speakeasy dot org

--- Comment #6 from Trent Piepho <xyzzy at speakeasy dot org> ---
It appears the same underlying problem can disable printf warnings via another
pattern:

$ mkdir -p syshdr_dir
$ cat <<EOF > syshdr_dir/myprintf.h
#define SD_ERR "<3>"
EOF

$ cat <<EOF > test-format-printf.c
#include <stdio.h>
int main(void) {
    printf(SD_ERR "%s", 3);
    return 0;
}
EOF

The printf format error in the pasted string "<3>%s" appears to be attributed
to the macro SD_ERR, as it forms the start of the pasted string.  Since that
macro is from a system header, the printf format error is attributed to the
system header, and no diagnostic is generated.  Changing the call to printf(""
SD_ERR "%s", 3) will attributed the printf format error to the line containing
the printf() call and allow a diagnostic to be generated.


More information about the Gcc-bugs mailing list