When compiled with gcc 3.4.6 with -m32 on x86_64 Linux the compiler flags lines 7, 10, and 13 as expected. But when compiled with gcc 4.3.1, only line 7 is diagnosed.
$ cat -n t.cpp && g++ -dumpversion && g++ -Wformat -m32 -c t.cpp 1 #include <stdio.h> 2 3 void foo (size_t n) 4 { 5 char buf [32]; 6 7 sprintf (buf, "%" "l" "u", n); 8 9 static const char fmt0[] = "%" "l" "u"; 10 sprintf (buf, fmt0, n); 11 12 const char fmt1[] = "%" "l" "u"; 13 sprintf (buf, fmt1, n); 14 15 static char fmt2[] = "%" "l" "u"; 16 sprintf (buf, fmt2, n); 17 18 char fmt3[] = "%" "l" "u"; 19 sprintf (buf, fmt3, n); 20 } 3.4.6 t.cpp: In function `void foo(size_t)': t.cpp:7: warning: long unsigned int format, size_t arg (arg 3) t.cpp:10: warning: long unsigned int format, size_t arg (arg 3) t.cpp:13: warning: long unsigned int format, size_t arg (arg 3) $ $ g++ -dumpversion && g++ -Wformat -m32 -c t.cpp 4.3.1 t.cpp: In function 'void foo(size_t)': t.cpp:7: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'size_t' $ -- Summary: missing -Wformat warning on const char format string Product: gcc Version: 4.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sebor at roguewave dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38980