This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH RFA: Improve -Wcast-qual warning for C


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

void
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
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]