When compiling code with GCC that involves passing an unqualified object to a function that advertises certain qualification guarantees, unsuppressible warnings are generated about passing "incompatible types."
That these types are formally incompatible under the standard is not in question. It is, however, irrelevant. While I do not possess the ISO document (C++ is my native tongue, and G++ does not exhibit this flaw), I was able to download draft n843 from the Internet, and it explicitly states: "For any qualifier q, a pointer to a non-q-qualified type may be converted to a pointer to the q-qualified version of the type; the values stored in the original and converted pointers shall compare equal." [section 6.3.2.3, paragraph 2] The intention of this provision is quite clear: functions should be able to advertise qualification guarantees that are more strict than the actual qualifications of any call parameters supplied to the function when it is called. By generating unsuppressible warnings for explicitly-permitted qualifier promotions, GCC makes it impossible to avoid warnings when compiling code that is completely in compliance with the standard. This greatly complicates the maintenance of warnings-free code in complex development environments and critically reduces the utility of the const keyword. Test case: ---------------------- void safe_function(const char *const *s) { } int main(void) { char *mystrings[2] = { "First string", "Second string" }; // This call warns, but should not: safe_function(mystrings); } ---------------------- Compiler output: Using built-in specs. Configured with: ./configure --prefix=/usr --host=i386-just-dragonflybsd Thread model: posix gcc version 3.4.3 [DragonFly] (propolice, visibility) /usr/libexec/gcc34/cc1 -E -quiet -v -iprefix /usr/libexec/gcc34/../gcc34//3.4.1/ bug2.c -march=pentium3 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-uninitialized -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -O -o bug2.i ignoring nonexistent directory "/usr/libexec/gcc34/../gcc34//3.4.1/include" ignoring nonexistent directory "/usr/libexec/gcc34/../gcc34//3.4.1/libdata/gcc34" #include "..." search starts here: #include <...> search starts here: /usr/include /usr/libdata/gcc34 End of search list. /usr/libexec/gcc34/cc1 -fpreprocessed bug2.i -quiet -dumpbase bug2.c -march=pentium3 -auxbase bug2 -O -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-uninitialized -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -version -o bug2.s GNU C version 3.4.3 (i386-just-dragonflybsd) compiled by GNU C version 2.95.4 20020320 [DragonFly]. GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 bug2.c:2: warning: no previous prototype for 'safe_function' bug2.c:2: warning: unused parameter 's' bug2.c: In function `main': bug2.c:6: warning: initialization discards qualifiers from pointer target type bug2.c:6: warning: initialization discards qualifiers from pointer target type bug2.c:9: warning: passing arg 1 of `safe_function' from incompatible pointer type bug2.c:11: warning: control reaches end of non-void function as -o bug2.o bug2.s ld -V -dynamic-linker /usr/libexec/ld-elf.so.1 -o bug2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib/gcc34 bug2.o -lgcc -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o GNU ld version 2.15 [DragonFly] 2004-05-17 Supported emulations: elf_i386 -- Summary: GCC generates non-compliant warnings for qualifier promotion Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kmk at ssl dot org CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20230