r222568 - Implement -Wcast-qual, fixing #13772.

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Sat Nov 22 12:38:33 PST 2014

On Sat, Nov 22, 2014 at 12:24 AM, Roman Divacky <rdivacky at vlakno.cz> wrote:
>> > +def warn_cast_qual2 : Warning<"cast from %0 to %1 must have all
>> > intermediate "
>> > +  "pointers const qualified to be safe">, InGroup<CastQual>,
>> > DefaultIgnore;
>> I think this is overstating the point; there are safe casts that do not
>> have 'const' added in all intermediate points. It's a bit awkward, but we
>> could use something like this:
>> "cast from pointer to %0 to pointer to non-const type %1 is not
>> const-correct; storing a value through the resulting pointer may make the
>> original pointer point to an object that is not of type %0"
> Well, I modelled the warning on gcc, which warns like this:
> warning: to be safe all intermediate pointers in cast from 'int **' to 'const
> int **' must be 'const' qualified [-Wcast-qual]
> What you suggest is a bit too long and I personally think that most people
> will have to google what it means anyway.

Why not simply
  "cast from pointer to %0 to pointer to %1 unsafely %{drops|adds}
type qualifiers"
  "cast from pointer to %0 to pointer to %1 is not const-correct"

Richard's fixed wording is certainly superior in one respect, which is
that it correctly identifies the types involved. A cast that looks
like '(char **)' isn't casting anything to 'char*'; it's casting to
'char**'; equivalently 'pointer to char*'.

Also, watch out that whatever wording you decide on is also correct
with respect to 'volatile'.  Adding 'const' to every level of a cast
that looks like '(char *volatile **)' won't fix anything.

my $.02,

More information about the cfe-commits mailing list