<div dir="ltr">Looks all good, please commit whenever you're ready - if you don't have commit access, I (or anyone else with commit access) can commit this for you.</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 6, 2017 at 1:57 PM Roman Lebedev <<a href="mailto:lebedev.ri@gmail.com">lebedev.ri@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Jun 6, 2017 at 8:52 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
> On Tue, Jun 6, 2017 at 3:59 AM Roman Lebedev via Phabricator<br>
> <<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>> wrote:<br>
>><br>
>> lebedev.ri added a comment.<br>
>><br>
>> In <a href="https://reviews.llvm.org/D33102#773296" rel="noreferrer" target="_blank">https://reviews.llvm.org/D33102#773296</a>, @dblaikie wrote:<br>
>><br>
>> > I still feel like that's more testing than would be ideal (does the<br>
>> > context of the cast matter? Wether it's dereferenced, a struct member<br>
>> > access, assigned, initialized, etc - it doesn't look like it from the code,<br>
>> > etc).<br>
>><br>
>><br>
>> Looking at the `CastsAwayConstness()` function in lib/Sema/SemaCast.cpp:<br>
>> <a href="https://github.com/llvm-mirror/clang/blob/432ed0e4a6d58f7dda8992a167aad43bc91f76c6/lib/Sema/SemaCast.cpp#L505-L510" rel="noreferrer" target="_blank">https://github.com/llvm-mirror/clang/blob/432ed0e4a6d58f7dda8992a167aad43bc91f76c6/lib/Sema/SemaCast.cpp#L505-L510</a><br>
>> You can see that it asserts that the pointer is one of three types. So i<br>
>> think it it is best to have maybe slightly overlapping test coverage here,<br>
>> rather than be surprised one day that such trivial cases no longer warn...<br>
>><br>
>> > But sure. Could you also (manually, I guess) confirm that this matches<br>
>> > GCC's cast-qual behavior (insofar as the warning fires in the same<br>
>> > situations). If there are any deviations, let's chat about them.<br>
>><br>
>> Sure.<br>
>><br>
>> 1. Gcc produces the same //count// of the warnings:<br>
>><br>
>> $ pwd<br>
>> llvm/tools/clang/test<br>
>> $ grep -o "expected-warning" Sema/warn-cast-qual.c | wc -l<br>
>> 14<br>
>> $ gcc -x c -fsyntax-only -Wcast-qual -c Sema/warn-cast-qual.c 2>&1 |<br>
>> grep ": warning: " | wc -l<br>
>> 14<br>
>> $ gcc -x c++ -fsyntax-only -Wcast-qual -c Sema/warn-cast-qual.c 2>&1 |<br>
>> grep ": warning: " | wc -l<br>
>> 14<br>
>> $ grep -o "expected-warning" SemaCXX/warn-cast-qual.cpp | wc -l<br>
>> 39<br>
>> $ gcc -x c++ -fsyntax-only -Wcast-qual -c SemaCXX/warn-cast-qual.cpp<br>
>> 2>&1 | grep ": warning: " | wc -l<br>
>> 39<br>
>><br>
>> 2. I'm not quite sure how to non-manually compare the warnings, so i'll<br>
>> just show the gcc output on these three cases. Since the clang warnings are<br>
>> appended as comments at the end of the each line that should warn, visual<br>
>> comparison is possible:<br>
<br>
> Works for the positive cases, not the negative ones. (though if the counts<br>
> are exactly the same, then so long as there are no false positives there<br>
> aren't any false negatives either)<br>
Yes, fair enough, i do not have anything to add here.<br>
<br>
>><br>
>><br>
>> 2.1.<br>
>><br>
>> $ gcc -x c -fsyntax-only -Wcast-qual -c Sema/warn-cast-qual.c<br>
>> Sema/warn-cast-qual.c: In function ‘foo’:<br>
>> Sema/warn-cast-qual.c:9:13: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> char *y = (char *)ptr; // expected-warning {{cast from 'const char *'<br>
>> to 'char *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:10:15: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> char **y1 = (char **)ptrptr; // expected-warning {{cast from 'const<br>
>> char *const' to 'char *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:11:21: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> const char **y2 = (const char **)ptrptr; // expected-warning {{cast<br>
>> from 'const char *const *' to 'const char **' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:14:14: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> char *z1 = (char *)(const void *)ptr; // expected-warning {{cast from<br>
>> 'const void *' to 'char *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:17:16: warning: cast discards ‘volatile’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> char *vol2 = (char *)vol; // expected-warning {{cast from 'volatile<br>
>> char *' to 'char *' drops volatile qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:19:17: warning: cast discards ‘const volatile’<br>
>> qualifier from pointer target type [-Wcast-qual]<br>
>> char *volc2 = (char *)volc; // expected-warning {{cast from 'const<br>
>> volatile char *' to 'char *' drops const and volatile qualifiers}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:22:28: warning: to be safe all intermediate<br>
>> pointers in cast from ‘int **’ to ‘const int **’ must be ‘const’ qualified<br>
>> [-Wcast-qual]<br>
>> const int **intptrptrc = (const int **)intptrptr; // expected-warning<br>
>> {{cast from 'int **' to 'const int **' must have all intermediate pointers<br>
>> const qualified}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:23:31: warning: to be safe all intermediate<br>
>> pointers in cast from ‘int **’ to ‘volatile int **’ must be ‘const’<br>
>> qualified [-Wcast-qual]<br>
>> volatile int **intptrptrv = (volatile int **)intptrptr; //<br>
>> expected-warning {{cast from 'int **' to 'volatile int **' must have all<br>
>> intermediate pointers const qualified}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:29:23: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> char **charptrptr = (char **)charptrptrc; // expected-warning {{cast<br>
>> from 'const char *' to 'char *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:32:19: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> char *charptr = (char *)constcharptr; // expected-warning {{cast from<br>
>> 'const char *' to 'char *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:33:31: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> const char *constcharptr2 = (char *)constcharptr; // expected-warning<br>
>> {{cast from 'const char *' to 'char *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c: In function ‘bar_0’:<br>
>> Sema/warn-cast-qual.c:45:4: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *' to<br>
>> 'int *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:46:4: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> *(int *)(&S.b) = 0; // expected-warning {{cast from 'const int *' to<br>
>> 'int *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c: In function ‘bar_1’:<br>
>> Sema/warn-cast-qual.c:58:4: warning: cast discards ‘const’ qualifier<br>
>> from pointer target type [-Wcast-qual]<br>
>> *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *' to<br>
>> 'int *' drops const qualifier}}<br>
>> ^<br>
>><br>
>> One thing to note:<br>
>><br>
>> Sema/warn-cast-qual.c:23:31: warning: to be safe all intermediate<br>
>> pointers in cast from ‘int **’ to ‘volatile int **’ must be ‘const’<br>
>> qualified [-Wcast-qual]<br>
>> volatile int **intptrptrv = (volatile int **)intptrptr; //<br>
>> expected-warning {{cast from 'int **' to 'volatile int **' must have all<br>
>> intermediate pointers const qualified}}<br>
>> ^<br>
>><br>
>> ^ both compilers talk about `const qualified`, even though the `volatile`<br>
>> is dropped.<br>
><br>
><br>
> Fair enough - 'cv qualified' (or detecting which qualifier was being<br>
> dropped) would probably be more technically correct. (detecting's probably<br>
> better because 'cv qualifeid' might be confusing to the average user that's<br>
> more likely to hit this over const than volatile)<br>
><br>
>><br>
>> 2.2.<br>
>><br>
>> $ gcc -x c++ -fsyntax-only -Wcast-qual -c Sema/warn-cast-qual.c<br>
>> Sema/warn-cast-qual.c: In function ‘void foo()’:<br>
>> Sema/warn-cast-qual.c:9:21: warning: cast from type ‘const char* const’<br>
>> to type ‘char*’ casts away qualifiers [-Wcast-qual]<br>
>> char *y = (char *)ptr; // expected-warning {{cast from 'const char *'<br>
>> to 'char *' drops const qualifier}}<br>
>> ^~~<br>
>> Sema/warn-cast-qual.c:10:24: warning: cast from type ‘const char*<br>
>> const*’ to type ‘char**’ casts away qualifiers [-Wcast-qual]<br>
>> char **y1 = (char **)ptrptr; // expected-warning {{cast from 'const<br>
>> char *const' to 'char *' drops const qualifier}}<br>
>> ^~~~~~<br>
>> Sema/warn-cast-qual.c:11:36: warning: cast from type ‘const char*<br>
>> const*’ to type ‘const char**’ casts away qualifiers [-Wcast-qual]<br>
>> const char **y2 = (const char **)ptrptr; // expected-warning {{cast<br>
>> from 'const char *const *' to 'const char **' drops const qualifier}}<br>
>> ^~~~~~<br>
>> Sema/warn-cast-qual.c:14:36: warning: cast from type ‘const void*’ to<br>
>> type ‘char*’ casts away qualifiers [-Wcast-qual]<br>
>> char *z1 = (char *)(const void *)ptr; // expected-warning {{cast from<br>
>> 'const void *' to 'char *' drops const qualifier}}<br>
>> ^~~<br>
>> Sema/warn-cast-qual.c:17:24: warning: cast from type ‘volatile char*’ to<br>
>> type ‘char*’ casts away qualifiers [-Wcast-qual]<br>
>> char *vol2 = (char *)vol; // expected-warning {{cast from 'volatile<br>
>> char *' to 'char *' drops volatile qualifier}}<br>
>> ^~~<br>
>> Sema/warn-cast-qual.c:19:25: warning: cast from type ‘const volatile<br>
>> char*’ to type ‘char*’ casts away qualifiers [-Wcast-qual]<br>
>> char *volc2 = (char *)volc; // expected-warning {{cast from 'const<br>
>> volatile char *' to 'char *' drops const and volatile qualifiers}}<br>
>> ^~~~<br>
>> Sema/warn-cast-qual.c:22:42: warning: cast from type ‘int**’ to type<br>
>> ‘const int**’ casts away qualifiers [-Wcast-qual]<br>
>> const int **intptrptrc = (const int **)intptrptr; // expected-warning<br>
>> {{cast from 'int **' to 'const int **' must have all intermediate pointers<br>
>> const qualified}}<br>
>> ^~~~~~~~~<br>
>> Sema/warn-cast-qual.c:23:48: warning: cast from type ‘int**’ to type<br>
>> ‘volatile int**’ casts away qualifiers [-Wcast-qual]<br>
>> volatile int **intptrptrv = (volatile int **)intptrptr; //<br>
>> expected-warning {{cast from 'int **' to 'volatile int **' must have all<br>
>> intermediate pointers const qualified}}<br>
>> ^~~~~~~~~<br>
>> Sema/warn-cast-qual.c:29:32: warning: cast from type ‘const char**’ to<br>
>> type ‘char**’ casts away qualifiers [-Wcast-qual]<br>
>> char **charptrptr = (char **)charptrptrc; // expected-warning {{cast<br>
>> from 'const char *' to 'char *' drops const qualifier}}<br>
>> ^~~~~~~~~~~<br>
>> Sema/warn-cast-qual.c:32:27: warning: cast from type ‘const char*’ to<br>
>> type ‘char*’ casts away qualifiers [-Wcast-qual]<br>
>> char *charptr = (char *)constcharptr; // expected-warning {{cast from<br>
>> 'const char *' to 'char *' drops const qualifier}}<br>
>> ^~~~~~~~~~~~<br>
>> Sema/warn-cast-qual.c:33:39: warning: cast from type ‘const char*’ to<br>
>> type ‘char*’ casts away qualifiers [-Wcast-qual]<br>
>> const char *constcharptr2 = (char *)constcharptr; // expected-warning<br>
>> {{cast from 'const char *' to 'char *' drops const qualifier}}<br>
>> ^~~~~~~~~~~~<br>
>> Sema/warn-cast-qual.c: In function ‘void bar_0()’:<br>
>> Sema/warn-cast-qual.c:45:16: warning: cast from type ‘const int*’ to<br>
>> type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *' to<br>
>> 'int *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c:46:16: warning: cast from type ‘const int*’ to<br>
>> type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> *(int *)(&S.b) = 0; // expected-warning {{cast from 'const int *' to<br>
>> 'int *' drops const qualifier}}<br>
>> ^<br>
>> Sema/warn-cast-qual.c: In function ‘void bar_1()’:<br>
>> Sema/warn-cast-qual.c:58:16: warning: cast from type ‘const int*’ to<br>
>> type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *' to<br>
>> 'int *' drops const qualifier}}<br>
>> ^<br>
>><br>
>> 2.3.<br>
>> And here are the C++ reference warnings. As you can see, gcc warnings are<br>
>> rather broken i'd say...<br>
><br>
><br>
> There's a lot to read through - what sort of brokenness were you referring<br>
> to?<br>
<br>
> The fact that the error messages talk about pointers when the code is<br>
> about references? Fair.<br>
Yes, only that<br>
<br>
> Anything else?<br>
Not as far as i can tell.<br>
One thing to note is that for complicated, multi-pointer variables like:<br>
<br>
>> SemaCXX/warn-cast-qual.cpp: In function ‘void bar_0()’:<br>
>> SemaCXX/warn-cast-qual.cpp:67:38: warning: cast from type ‘const int**’<br>
>> to type ‘int**’ casts away qualifiers [-Wcast-qual]<br>
>> int **a0 = (int **)((const int **)a); // expected-warning {{cast from<br>
>> 'const int *' to 'int *' drops const qualifier}}<br>
>> ^<br>
the gcc outputs full types, and clang dissects them, and outputs only<br>
invalid part.<br>
But i'm pretty sure this isn't new.<br>
<br>
>><br>
>><br>
>> $ gcc -x c++ -fsyntax-only -Wcast-qual -c SemaCXX/warn-cast-qual.cpp<br>
>> SemaCXX/warn-cast-qual.cpp: In function ‘void foo_0()’:<br>
>> SemaCXX/warn-cast-qual.cpp:24:20: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a2 = (int &)a; // expected-warning {{cast<br>
>> from 'const int' to 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:25:26: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> const int &a3 = (int &)a; // expected-warning {{cast<br>
>> from 'const int' to 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:26:35: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a4 = (int &)((const int &)a); // expected-warning {{cast<br>
>> from 'const int' to 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:27:28: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a5 = (int &)((int &)a); // expected-warning {{cast<br>
>> from 'const int' to 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:28:34: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> const int &a6 = (int &)((int &)a); // expected-warning {{cast<br>
>> from 'const int' to 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:29:41: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> const int &a7 = (int &)((const int &)a); // expected-warning {{cast<br>
>> from 'const int' to 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:30:40: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> const int &a8 = (const int &)((int &)a); // expected-warning {{cast<br>
>> from 'const int' to 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp: In function ‘void foo_1()’:<br>
>> SemaCXX/warn-cast-qual.cpp:39:20: warning: cast from type ‘volatile<br>
>> int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a2 = (int &)a; // expected-warning<br>
>> {{cast from 'volatile int' to 'int &' drops volatile qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:40:29: warning: cast from type ‘volatile<br>
>> int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> volatile int &a3 = (int &)a; // expected-warning<br>
>> {{cast from 'volatile int' to 'int &' drops volatile qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:41:38: warning: cast from type ‘volatile<br>
>> int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a4 = (int &)((volatile int &)a); // expected-warning<br>
>> {{cast from 'volatile int' to 'int &' drops volatile qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:42:28: warning: cast from type ‘volatile<br>
>> int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a5 = (int &)((int &)a); // expected-warning<br>
>> {{cast from 'volatile int' to 'int &' drops volatile qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:43:37: warning: cast from type ‘volatile<br>
>> int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> volatile int &a6 = (int &)((int &)a); // expected-warning<br>
>> {{cast from 'volatile int' to 'int &' drops volatile qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:44:47: warning: cast from type ‘volatile<br>
>> int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> volatile int &a7 = (int &)((volatile int &)a); // expected-warning<br>
>> {{cast from 'volatile int' to 'int &' drops volatile qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:45:46: warning: cast from type ‘volatile<br>
>> int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> volatile int &a8 = (volatile int &)((int &)a); // expected-warning<br>
>> {{cast from 'volatile int' to 'int &' drops volatile qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp: In function ‘void foo_2()’:<br>
>> SemaCXX/warn-cast-qual.cpp:54:20: warning: cast from type ‘const<br>
>> volatile int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a2 = (int &)a; //<br>
>> expected-warning {{cast from 'const volatile int' to 'int &' drops const and<br>
>> volatile qualifiers}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:55:35: warning: cast from type ‘const<br>
>> volatile int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> const volatile int &a3 = (int &)a; //<br>
>> expected-warning {{cast from 'const volatile int' to 'int &' drops const and<br>
>> volatile qualifiers}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:56:44: warning: cast from type ‘const<br>
>> volatile int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a4 = (int &)((const volatile int &)a); //<br>
>> expected-warning {{cast from 'const volatile int' to 'int &' drops const and<br>
>> volatile qualifiers}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:57:28: warning: cast from type ‘const<br>
>> volatile int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> int &a5 = (int &)((int &)a); //<br>
>> expected-warning {{cast from 'const volatile int' to 'int &' drops const and<br>
>> volatile qualifiers}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:58:43: warning: cast from type ‘const<br>
>> volatile int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> const volatile int &a6 = (int &)((int &)a); //<br>
>> expected-warning {{cast from 'const volatile int' to 'int &' drops const and<br>
>> volatile qualifiers}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:59:59: warning: cast from type ‘const<br>
>> volatile int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> const volatile int &a7 = (int &)((const volatile int &)a); //<br>
>> expected-warning {{cast from 'const volatile int' to 'int &' drops const and<br>
>> volatile qualifiers}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:60:58: warning: cast from type ‘const<br>
>> volatile int*’ to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> const volatile int &a8 = (const volatile int &)((int &)a); //<br>
>> expected-warning {{cast from 'const volatile int' to 'int &' drops const and<br>
>> volatile qualifiers}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp: In function ‘void bar_0()’:<br>
>> SemaCXX/warn-cast-qual.cpp:67:38: warning: cast from type ‘const int**’<br>
>> to type ‘int**’ casts away qualifiers [-Wcast-qual]<br>
>> int **a0 = (int **)((const int **)a); // expected-warning {{cast from<br>
>> 'const int *' to 'int *' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:68:31: warning: cast from type ‘const int**’<br>
>> to type ‘int**’ casts away qualifiers [-Wcast-qual]<br>
>> int **a1 = (int **)((int **)a); // expected-warning {{cast from<br>
>> 'const int *' to 'int *' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:73:43: warning: cast from type ‘const int**’<br>
>> to type ‘int**’ casts away qualifiers [-Wcast-qual]<br>
>> const int **a4 = (const int **)((int **)a); //<br>
>> expected-warning {{cast from 'const int *' to 'int *' drops const<br>
>> qualifier}} expected-warning {{cast from 'int **' to 'const int **' must<br>
>> have all intermediate pointers const qualified to be safe}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:73:44: warning: cast from type ‘int**’ to<br>
>> type ‘const int**’ casts away qualifiers [-Wcast-qual]<br>
>> const int **a4 = (const int **)((int **)a); //<br>
>> expected-warning {{cast from 'const int *' to 'int *' drops const<br>
>> qualifier}} expected-warning {{cast from 'int **' to 'const int **' must<br>
>> have all intermediate pointers const qualified to be safe}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp: In function ‘void bar_1()’:<br>
>> SemaCXX/warn-cast-qual.cpp:81:38: warning: cast from type ‘const int**’<br>
>> to type ‘int**’ casts away qualifiers [-Wcast-qual]<br>
>> int *&a0 = (int *&)((const int *&)a); // expected-warning {{cast from<br>
>> 'const int *' to 'int *' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:82:31: warning: cast from type ‘const int**’<br>
>> to type ‘int**’ casts away qualifiers [-Wcast-qual]<br>
>> int *&a1 = (int *&)((int *&)a); // expected-warning {{cast from<br>
>> 'const int *' to 'int *' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:87:43: warning: cast from type ‘const int**’<br>
>> to type ‘int**’ casts away qualifiers [-Wcast-qual]<br>
>> const int *&a4 = (const int *&)((int *&)a); //<br>
>> expected-warning {{cast from 'const int *' to 'int *' drops const<br>
>> qualifier}} expected-warning {{cast from 'int *' to 'const int *&' must have<br>
>> all intermediate pointers const qualified to be safe}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:87:44: warning: cast from type ‘int**’ to<br>
>> type ‘const int**’ casts away qualifiers [-Wcast-qual]<br>
>> const int *&a4 = (const int *&)((int *&)a); //<br>
>> expected-warning {{cast from 'const int *' to 'int *' drops const<br>
>> qualifier}} expected-warning {{cast from 'int *' to 'const int *&' must have<br>
>> all intermediate pointers const qualified to be safe}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp: In function ‘void baz_0()’:<br>
>> SemaCXX/warn-cast-qual.cpp:100:9: warning: cast from type ‘const<br>
>> baz_0()::C*’ to type ‘baz_0()::C*’ casts away qualifiers [-Wcast-qual]<br>
>> ((C &)S).B(); // expected-warning {{cast from 'const C' to 'C &'<br>
>> drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:101:9: warning: cast from type ‘const<br>
>> baz_0()::C*’ to type ‘baz_0()::C*’ casts away qualifiers [-Wcast-qual]<br>
>> ((C &)S).A(); // expected-warning {{cast from 'const C' to 'C &'<br>
>> drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:103:10: warning: cast from type ‘const<br>
>> baz_0()::C*’ to type ‘baz_0()::C*’ casts away qualifiers [-Wcast-qual]<br>
>> ((C *)&S)->B(); // expected-warning {{cast from 'const C *' to 'C *'<br>
>> drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:104:10: warning: cast from type ‘const<br>
>> baz_0()::C*’ to type ‘baz_0()::C*’ casts away qualifiers [-Wcast-qual]<br>
>> ((C *)&S)->A(); // expected-warning {{cast from 'const C *' to 'C *'<br>
>> drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp: In function ‘void baz_1()’:<br>
>> SemaCXX/warn-cast-qual.cpp:119:16: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> (int &)(S.a) = 0; // expected-warning {{cast from 'const int' to<br>
>> 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:122:18: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *'<br>
>> to 'int *' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:128:16: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> (int &)(S.a) = 0; // expected-warning {{cast from 'const int' to<br>
>> 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:129:16: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> (int &)(S.b) = 0; // expected-warning {{cast from 'const int' to<br>
>> 'int &' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:131:18: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> *(int *)(&S.a) = 0; // expected-warning {{cast from 'const int *'<br>
>> to 'int *' drops const qualifier}}<br>
>> ^<br>
>> SemaCXX/warn-cast-qual.cpp:132:18: warning: cast from type ‘const int*’<br>
>> to type ‘int*’ casts away qualifiers [-Wcast-qual]<br>
>> *(int *)(&S.b) = 0; // expected-warning {{cast from 'const int *'<br>
>> to 'int *' drops const qualifier}}<br>
>> ^<br>
>><br>
>> So to me it seems that for our clang's testcases, both compilers produce<br>
>> the compatible set of warnings...<br>
>><br>
>><br>
>> Repository:<br>
>> rL LLVM<br>
>><br>
>> <a href="https://reviews.llvm.org/D33102" rel="noreferrer" target="_blank">https://reviews.llvm.org/D33102</a><br>
>><br>
>><br>
>><br>
><br>
<br>
Roman.<br>
</blockquote></div>