PATCH RFA: Improve -Wcast-qual warning for C

Ian Lance Taylor iant@google.com
Tue May 26 05:46:00 GMT 2009


As discussed at http://gcc.gnu.org/ml/gcc/2009-05/msg00533.html , the
C++ compiler issues more warnings for -Wcast-qual than the C compiler
does.  After a bit of further discussion on IRC, I think the general
consensus is that the C compiler should issue warnings about unsafe
casts much as the C++ compiler does.  Recall that this is only when
using -Wcast-qual, and that -Wcast-qual is not part of -Wall.

The first patch in this message implements the appropriate warnings.
This patch requires approval from the C frontend maintainers.

The second patch in this message fixes gcc to bootstrap given the
changes in the first patch.  I believe that these changes count as
obvious.

Bootstrapped and tested on i686-pc-linux-gnu.

OK for mainline?

Ian


First patch:

gcc/ChangeLog:

2009-05-25  Ian Lance Taylor  <iant@google.com>

	* c-typeck.c (handle_warn_cast_qual): New static function,
	partially broken out of build_c_cast.
	(build_c_cast): Call handle_warn_cast_qual.
	* doc/invoke.texi (Warning Options): Document new effect of
	-Wcast-qual.

gcc/testsuite/ChangeLog:

2009-05-25  Ian Lance Taylor  <iant@google.com>

	* gcc.dg/cast-qual-3.c: New testcase.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo1.patch
Type: text/x-patch
Size: 14226 bytes
Desc: -Wcast-qual warns about unsafe casts
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090526/dbca42fc/attachment.bin>
-------------- next part --------------


==================================================


Second patch:

gcc/ChangeLog:

2009-05-25  Ian Lance Taylor  <iant@google.com>

	* attribs.c (register_attribute): Use CONST_CAST.
	* collect2.c (main): Use CONST_CAST2.
	(scan_prog_file): Likewise.
	* gcc.c (process_command, main): Likewise.
	* toplev.c (toplev_main): Likewise.

gcc/java/ChangeLog:

2009-05-25  Ian Lance Taylor  <iant@google.com>

	* jcf-io.c (find_class): Use CONST_CAST.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-patch
Size: 6250 bytes
Desc: Use CONST_CAST
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090526/dbca42fc/attachment-0001.bin>


More information about the Gcc-patches mailing list