This is the mail archive of the
mailing list for the GCC project.
Re: PATCH RFA: Improve -Wcast-qual warning for C
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 29 May 2009 20:37:52 +0000 (UTC)
- Subject: Re: PATCH RFA: Improve -Wcast-qual warning for C
- References: <firstname.lastname@example.org>
On Mon, 25 May 2009, Ian Lance Taylor wrote:
> 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.
I do not believe this is implementing the correct semantics.
The requirement for safety in multi-level casts is not that the final
qualifier appears at the intermediate levels, it is that "const" appears
at all levels before any level at which a qualifier is added; that is, if
the C++ rules would permit a qualification conversion with that sequence
of qualifiers. The example
f5 (char ***bar)
volatile char * const * const * p19 = bar;
is accepted by the C++ front end as this is a safe implicit conversion, as
is the version with a cast when using -Wcast-qual.
I think you should also add a C++ testcase that is essentially identical
to the C one to verify that the same semantics are being followed for the
option by both front ends.
Joseph S. Myers