[PATCH]: Implementation of -Wcast-qual

Roman Divacky rdivacky at vlakno.cz
Thu Nov 13 10:51:36 PST 2014


Seems like gcc (5.0) agrees with you and only emits one warning. I modified
the patch to only report the inner most cast.

New patch attached.

On Wed, Nov 12, 2014 at 12:39:20PM -0800, David Blaikie wrote:
> [+Richard for oversight]
> 
> char **y1 = (char **)ptrptr; // expected-warning {{cast from 'const char
> *const *' to 'char **' drops const qualifier}} expected-warning {{cast from
> 'const char *const' to 'char *' drops const qualifier}}
> 
> I think if we're going to warn on multiple layers (I'm not sure that's
> ideal - is that consistent with GCC's warning? Does GCC warn on mismatched
> types too - "const T*" -> "U*"? - do we warn there too, or only when
> there's a valid implicit conversion like the void* example?) then we should
> probably drop the top level const, "const char *const" -> "char*" - the top
> level const on the first type is confusing/misleading, it's only relevant
> to show "const char*" and "char*".
> 
> 
> On Wed, Nov 12, 2014 at 10:41 AM, Roman Divacky <rdivacky at vlakno.cz> wrote:
> 
> > I expanded the testcase and fixed the grammar in the actual warning.
> >
> > New patch attached.
> >
> > On Tue, Nov 11, 2014 at 05:03:33PM -0800, David Blaikie wrote:
> > > (it's a bit easier if you include the test in the same patch file - also
> > > you can use Phabricator if you like - some reviewers perefer it)
> > >
> > > Since you've got the loop there for seeing through multiple levels of
> > > pointer, should you have a test case that exercises that on a > 1 level
> > of
> > > depth? Demonstrate that we warn on both levels (if that's the right thing
> > > to do?)?
> > >
> > > Optionally (probably in a separate follow-up patch) you could add a note
> > > with a fixit to include the missing consts.
> > >
> > > On Tue, Nov 11, 2014 at 10:58 AM, Roman Divacky <rdivacky at vlakno.cz>
> > wrote:
> > >
> > > > Hi,
> > > >
> > > > I implemented -Wcast-qual. The patch is actually quite short (attached
> > + a
> > > > test
> > > > case).
> > > >
> > > > This fixes #13772 and also note that -Wcast-qual is used in llvm build
> > > > itself.
> > > >
> > > > Is this ok to be commited? Thanks
> > > >
> > > > Roman
> > > >
> > > >
> > > > _______________________________________________
> > > > cfe-commits mailing list
> > > > cfe-commits at cs.uiuc.edu
> > > > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> > > >
> > > >
> >
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-cast-qual.patch
Type: text/x-diff
Size: 3279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141113/876cc3e6/attachment.patch>


More information about the cfe-commits mailing list