[PATCH] D33102: [clang] Implement -Wcast-qual for C++

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 12 10:16:27 PDT 2017


On Mon, Jun 12, 2017 at 10:10 AM Roman Lebedev via Phabricator <
reviews at reviews.llvm.org> wrote:

> lebedev.ri added a comment.
>
> So i'm trying to analyze that stage2 warning.
>

Could you link to the buildbot failure to see the original LLVM project
code triggering this situation?


> The testcase //seems// to be: (autogenerated all the variants)
>
>   void test_nop() {
>     unsigned char **ptr1 = 0;
>     void **ptr2 = (void **)ptr1;
>   }
>   void test_bad() {
>     unsigned char **ptr1 = 0;
>     const void **ptr2 = (const void **)ptr1; // expected-warning {{cast
> from 'unsigned char **' to 'const void **' must have all intermediate
> pointers const qualified to be safe}}
>   }
>   void test_good0() {
>     unsigned char **ptr1 = 0;
>     void *const *ptr2 = (void *const *)ptr1;
>   }
>   void test_good1() {
>     unsigned char **ptr1 = 0;
>     const void *const *ptr2 = (const void *const *)ptr1;
>   }
>   void test_good2() {
>     unsigned char *const *ptr1 = 0;
>     void *const *ptr2 = (void *const *)ptr1;
>   }
>   void test_good3() {
>     unsigned char *const *ptr1 = 0;
>     const void *const *ptr2 = (const void *const *)ptr1;
>   }
>   void test_good4() {
>     const unsigned char **ptr1 = 0;
>     const void **ptr2 = (const void **)ptr1;
>   }
>   void test_good5() {
>     const unsigned char **ptr1 = 0;
>     const void *const *ptr2 = (const void *const *)ptr1;
>   }
>   void test_good6() {
>     const unsigned char *const *ptr1 = 0;
>     const void *const *ptr2 = (const void *const *)ptr1;
>   }
>
> GCC does not warn about such code at all, clang in C mode does warn about
> only one combination:
>
>   $ gcc -c /tmp/test.c -Wcast-qual
>   $ echo $?
>   0
>   $ clang -c /tmp/test.c -Wcast-qual
>   /tmp/test.c:7:38: warning: cast from 'unsigned char **' to 'const void
> **' must have all intermediate pointers const qualified to be safe
> [-Wcast-qual]
>     const void **ptr2 = (const void **)ptr1; // expected-warning {{cast
> from 'unsigned char **' to 'const void **' must have all intermediate
> pointers const qualified to be safe}}
>                                        ^
>   1 warning generated.
>
> David, you reviewed the original `-Wcast-qual` patch, does all that ^ make
> sense?
>

That seems like a reasonable warning, do you agree?

But maybe it's best to put it under another flag name so it doesn't collide
with GCC.

But really - *shrug* I'd probably leave it under the same flag, fix the
LLVM project code that causes it, and carry on.


>
> F3429854: gen.cpp <https://reviews.llvm.org/F3429854>
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D33102
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170612/be6306ce/attachment.html>


More information about the cfe-commits mailing list