For me, this is really a bug in gcc 5 .
gcc documentation says
-Wwrite-string
When compiling C, give the string constants a type const char [length], so copying the address of one to a non-const char * pointer raises a warning.
So with this declaration:
typeof(*"FOO") x[4];
then &x is of type const char (*)[4] when -Wwrite-strings present. In the standard, C &x is of type char (*)[4] .
This little function:
void foo(void) { typeof(*"FOO") x[4]; printf("%d\n", __builtin_types_compatible_p(typeof(&x), const char (*)[4])); printf("%d\n", __builtin_types_compatible_p(typeof(&x), char (*)[4])); }
prints:
1 0
with gcc 5.3 and -Wwrite-strings . Thus, we can see that gcc 5.3 correctly identifies &x by type const char (*)[4] with -Wwrite-strings .
gcc must accept the &x argument when calling a function with the const char (*)[4] parameter const char (*)[4] . The incompatible type warning is IMHO, and then an error in gcc .
(This error probably did not appear in previous versions of gcc simply because gcc failed (another error) to identify &x as const char (*)[4] with -Wwrite-strings in previous versions of gcc . I'm with gcc 4.9.2 and gcc-6-20151206 .)
source share