[PATCH] D33102: [clang] Implement -Wcast-qual for C++
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 12 10:10:48 PDT 2017
lebedev.ri added a comment.
So i'm trying to analyze that stage2 warning.
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?
F3429854: gen.cpp <https://reviews.llvm.org/F3429854>
Repository:
rL LLVM
https://reviews.llvm.org/D33102
More information about the cfe-commits
mailing list