On Sat, Jun 10, 2017 at 3:33 AM Roman Lebedev via Phabricator < revi...@reviews.llvm.org> wrote:
> lebedev.ri planned changes to this revision. > lebedev.ri added a comment. > > In https://reviews.llvm.org/D33102#773296, @dblaikie wrote: > > > But sure. Could you also (manually, I guess) confirm that this matches > GCC's cast-qual behavior (insofar as the warning fires in the same > situations). If there are any deviations, let's chat about them. > > > Great, you were right :) > Found a false-negative: > > $ cat /tmp/tst.c > int main() { > void* p1 = (void*)"txt"; > char* p2 = (char*)"txt"; > } > $ gcc -x c -Wcast-qual /tmp/tst.c > $ gcc -x c++ -Wcast-qual /tmp/tst.c > /tmp/tst.c: In function ‘int main()’: > /tmp/tst.c:2:21: warning: cast from type ‘const char*’ to type ‘void*’ > casts away qualifiers [-Wcast-qual] > void* p1 = (void*)"txt"; > ^~~~~ > /tmp/tst.c:3:21: warning: cast from type ‘const char*’ to type ‘char*’ > casts away qualifiers [-Wcast-qual] > char* p2 = (char*)"txt"; > ^~~~~ > > $ ./bin/clang -x c -Wcast-qual /tmp/tst.c > $ ./bin/clang -x c++ -Wcast-qual /tmp/tst.c > /tmp/tst.c:3:21: warning: cast from 'const char *' to 'char *' drops > const qualifier [-Wcast-qual] > char* p2 = (char*)"txt"; > ^ > 1 warning generated. > > So at least, in C++ mode, it should warn on both lines. > Seems reasonable that it should, yes. (aside: You're still welcome to commit this patch as-is, and provide patches for improvements as follow-up (mostly false positives would be more of a concern to address before commit)) > I'm not sure, should that really not produce a warning in C? > (gcc version 6.3.0 20170516 (Debian 6.3.0-18) ) > Probably not, no - string literals have some weird mutability in C (& in older versions of C++, even). - Dave > > > Repository: > rL LLVM > > https://reviews.llvm.org/D33102 > > > >
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits