[cfe-commits] [PATCH] -Wcast-qual

Igor Minin i.minin.llvm at gmail.com
Fri Jun 22 03:46:23 PDT 2012


Hello Dmitri!

Thank you for response.

Diagnostic message is correct, may be just unclear. For example of
unsafeness see the following code:

const char constObj = 'c';

char* nonConstPointer;

char** nonConstPointerToPointer = &nonConstPointer;

const char** pointerToConstPointer = (const
char**)nonConstPointerToPointer; // (1)

*pointerToConstPointer = &constObj; // nonConstPointer now point to
constObj, implies that (1) discards constness from &constObj, so the
warning is correct

*nonConstPointer = 'C'; // BANG! Modification of const object.

May be to make warning more clear I should include more info about types in
my warning.

On Wed, Jun 20, 2012 at 10:23 PM, Dmitri Gribenko <gribozavr at gmail.com>wrote:

> On Wed, Jun 20, 2012 at 2:53 AM, Igor Minin <i.minin.llvm at gmail.com>
> wrote:
> > Hello.
> >
> > The attached patch adds support for a clang -Wcast-qual option. Semantic
> is
> > compatible with the gcc one.
>
> Hello Igor,
>
> Thank you for working on this!
>
> +  char** x = 0;
> +  const char** y = (const char**)x; // expected-warning {{cast
> discards qualifiers from pointer target type}}
>
> I think the diagnostic message is a bit incorrect in this case.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120622/b3598d99/attachment.html>


More information about the cfe-commits mailing list