Hide Forgot
Description of problem: Compile this code snippet with -Werror=-Wformat-security; #include <stdio.h> int main() { const char text[] = "hallo world\n"; const char *ptr1 = &text[0]; fprintf( stdout, ptr1); fprintf( stdout, &text[0] ); return 1; } gcc complains about the 1st fprintf, but doesn't complain about the 2nd one: # gcc -Wall -Werror=format-security -o foo.o -c foo.c foo.c: In function ‘main’: foo.c:8:3: error: format not a string literal and no format arguments [-Werror=format-security] fprintf( stdout, ptr1); ^ cc1: some warnings being treated as errors Version-Release number of selected component (if applicable): gcc-4.8.2-1.fc19.x86_64 How reproducible: Always. Expected results: I would expect GCC to either warn on both use case or on none. The current situation seems bogus to me.
This is not a bug. The warning is emitted by the C/C++ frontends, so there are no optimizations (and at -O0 there wouldn't be any anyway) that would fold ptr1 into &text[0], ptr1 is not a string literal, it is a variable that in some other testcase could be changed to something completely different.