Consider #include <stdio.h> void foo(int i) { printf("Hello World %d!\n", i); printf(&"Hello World %d!\n"[0], i); printf(&"Hello World %d!\n"[6], i); } > g++-3.3 -c c-format.C -Wformat=2 > g++-3.4 -c c-format.C -Wformat=2 c-format.C: In function `void foo(int)': c-format.C:6: warning: format not a string literal, argument types not checked > g++-4.0 -c c-format.C -Wformat=2 c-format.C: In function 'void foo(int)': c-format.C:6: warning: format not a string literal, argument types not checked c-format.C:7: warning: format not a string literal, argument types not checked > g++-4.1 -c c-format.C -Wformat=2 c-format.C: In function 'void foo(int)': c-format.C:6: warning: format not a string literal, argument types not checked c-format.C:7: warning: format not a string literal, argument types not checked so we're getting worse here. The problem is that c-format.c:check_format_arg does not handle string literals of the form ADDR_EXPR (ARRAY_REF ( ... )). This blocks changing the C frontend to emit &a[0] for array-to-pointer decay.
Confirmed.
Patch posted here: <http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00978.html>.
Fixed on mainline.
Moving to 4.0.2 pre Mark.
Works in GCC-4.1.x and higher. won't fix in GCC-4.0.x