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

            Bug ID: 60296
           Summary: Confusing -Wformat warning on invalid format string
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chengniansun at gmail dot com

Gcc emits two warnings on "printf("%.%*d\n", 9)", of which the format string is
invalid. IMHO, the two warning messages are contradictory somehow. The first
message says a conversion type is missing in the format string(if I understand
it correctly), but the second says that we need to add a data argument to
printf to match a "%d"? 

One more question, in the second message, does "‘%d’" refer to "%*d" in the
format string, or just a hard-coded string in the gcc code? 

Lastly, the compiled executable just treats the format string as a string
"%*d". Is this the way how gcc treats this invalid string? If yes, it might be
better to warn on it in the same way, that is, extra data argument not used by
the format string.  




$: cat s.c 
#include <stdio.h>
int main() {
  printf("%.%*d\n", 9);
  return 0;
}
$: gcc-trunk -Wformat=2 s.c 
s.c: In function ‘main’:
s.c:3:3: warning: conversion lacks type at end of format [-Wformat=]
   printf("%.%*d\n", 9);
   ^
s.c:3:3: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
$: ./a.out 
%*d
$: clang-trunk -Wformat=2 s.c 
s.c:3:21: warning: data argument not used by format string
[-Wformat-extra-args]
  printf("%.%*d\n", 9);
         ~~~~~~~~~  ^
1 warning generated.

Reply via email to