public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/20230] New: GCC generates non-compliant warnings for qualifier promotion
@ 2005-02-27 16:17 kmk at ssl dot org
  2005-02-27 16:19 ` [Bug debug/20230] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: kmk at ssl dot org @ 2005-02-27 16:17 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-02-27 23:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-27 16:17 [Bug debug/20230] New: GCC generates non-compliant warnings for qualifier promotion kmk at ssl dot org
2005-02-27 16:19 ` [Bug debug/20230] " pinskia at gcc dot gnu dot org
2005-02-27 16:32 ` [Bug c/20230] " pinskia at gcc dot gnu dot org
2005-02-27 16:33 ` pinskia at gcc dot gnu dot org
2005-02-27 17:14 ` kmk at ssl dot org
2005-02-27 18:16 ` falk at debian dot org
2005-02-27 18:32 ` kmk at ssl dot org
2005-02-27 18:47 ` joseph at codesourcery dot com
2005-02-27 18:57 ` falk at debian dot org
2005-02-28  6:35 ` kmk at ssl dot org
2005-02-28  8:27 ` kmk at ssl dot org
2005-02-28 10:00 ` joseph at codesourcery dot com
2005-02-28 10:27 ` kmk at ssl dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).