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

            Bug ID: 93406
           Summary: No argument checking for wchar_t variants of
                    print-like functions
           Product: gcc
           Version: 7.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jerome.h...@planete-sciences.org
  Target Milestone: ---

Hi,

There is no output of -Wformat for functions using wchar_t format specifiers.
Let the following program:

/////////////////////////////////////////////////////

#include <time.h>
#include <stdio.h>
#include <wchar.h>

int main(void)
{
        wchar_t wbuf[128];
        char    cbuf[128];
        time_t now = time(NULL);
        swprintf(wbuf, sizeof(wbuf)/sizeof(*wbuf), L"%d", now);
        snprintf(cbuf, sizeof(cbuf)/sizeof(*cbuf),  "%d", now);
        printf("wbuf:%S\n", wbuf);
        printf("cbuf:%s\n", cbuf);
        return 0;
}

/////////////////////////////////////////////////////

#####################################################

c++ -Wall -o rapport.elf rapport.cpp 
rapport.cpp: In function ‘int main()’:
rapport.cpp:11:55: warning: format ‘%d’ expects argument of type ‘int’, but
argument 4 has type ‘time_t {aka long int}’ [-Wformat=]
  snprintf(cbuf, sizeof(cbuf)/sizeof(*cbuf),  "%d", now);
                                                       ^
#####################################################

The mismatch between format specifier and argument is only reported for char
functions, not for wchar_t functions.

I have seen this problem on:
c++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
C++ (GCC) 8.2.0

Reply via email to