http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58959

            Bug ID: 58959
           Summary: Add warning when format specifiers refers to wrong
                    signess
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lotharlutz at gmx dot de

When using a format specifier that refers to a different sign (signed vs
unsigned) as to corresponding variable has, a warning should be emitted.

Version:
gcc version 4.8.2 20131017 (Red Hat 4.8.2-1) (GCC)

Example:
-----
#include <stdio.h>

int main()
{
    short i = -1;

    //correct usage
    printf("%hd\n",i);

    //should yield a warning, but does not
    printf("%hu\n",i);

    //correctly yields a warning
    printf("%ld\n",i);

return 0;
}
----
gcc -Wall -Wextra test.c
test.c: In function ‘main’:
test.c:14:5: warning: format ‘%ld’ expects argument of type ‘long int’, but
argument 2 has type ‘int’ [-Wformat=]
     printf("%ld\n",i);

gcc warns when the variable has the wrong size (line 14), but not on the wrong
size (line 11)

Reply via email to