This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Apparent egcs 19980824 bug with -Wcast-qual
- To: egcs-bugs at cygnus dot com
- Subject: Apparent egcs 19980824 bug with -Wcast-qual
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Date: Fri, 28 Aug 1998 19:07:46 +0100 (BST)
- Reply-To: Joseph Myers <jsm28 at cam dot ac dot uk>
The following source file gives what appears to be an incorrect
warning with -Wcast-qual (egcs snapshot 19980824 on
i586-pc-linux-gnulibc1):
================================ t0.i ================================
void good(const void *bar) { (char *const *)bar; }
void bad(const void *bar) { (const char **)bar; }
================================ t0.i ================================
$ egcc -v -S -Wcast-qual t0.i
Reading specs from /opt/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.55/specs
gcc version egcs-2.91.55 19980824 (gcc2 ss-980609 experimental)
/opt/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.55/cc1 t0.i -quiet -Wcast-qual -version -o t0.s
GNU C version egcs-2.91.55 19980824 (gcc2 ss-980609 experimental) (i586-pc-linux-gnulibc1) compiled by GNU C version egcs-2.91.55 19980824 (gcc2 ss-980609 experimental).
t0.i: In function `good':
t0.i:1: warning: cast discards `const' from pointer target type
$
gcc 2.7.2.1 gets this right, warning in bad() rather than good():
$ gcc -v -S -Wcast-qual t0.i
Reading specs from /usr/lib/gcc-lib/i486-linux/2.7.2.1/specs
gcc version 2.7.2.1
/usr/lib/gcc-lib/i486-linux/2.7.2.1/cc1 t0.i -quiet -Wcast-qual -version -o t0.s
GNU C version 2.7.2.1 (i386 Linux/ELF) compiled by GNU C version 2.7.2.1.
t0.i: In function `bad':
t0.i:2: warning: cast discards `const' from pointer target type
$
In the similar case below, where assignments rather casts are used,
both egcs snapshot 19980824 and gcc 2.7.2.1 give the right warning, in
bad() rather than good().
================================ t1.i ================================
void good(const void *bar) { char *const *foo = bar; }
void bad(const void *bar) { const char **foo = bar; }
================================ t1.i ================================
--
Joseph S. Myers
jsm28@cam.ac.uk