Hello.<br><br><div>The attached patch adds support for a clang -Wcast-qual option. Semantic is compatible with the gcc one.<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Warn whenever a pointer is cast so as to remove a type qualifier from the target<br>type. For example, warn if a "const char*" is cast to an ordinary "char*".<br>Also warn when making a cast that introduces a type qualifier in an unsafe way.<br>
For example, casting "char**" to "const char**" is unsafe, as in this example:<br>/* p is char ** value. */<br>const char **q = (const char **) p;<br>/* Assignment of readonly string to const char * is OK. */<br>
*q = "string";<br>/* Now char** pointer points to read-only memory. */<br>**p = ’b’;</blockquote>(Gcc manual).<br><br>What is "introducing in an unsafe way" precisely described in [conv.qual] item of C++ standard. <div>
<br>So, the proposed patch is very similar to the code that checks assign constrains. Differences are: </div><div><br> * This patch generates only warnings, not errors, which helps to have cleaner implementation.<br> * It is called only for C-style casting and functional-style casting (because only three casts can remove qualifiers: C-sytle, functional-style and const_cast. But const_cast in gcc is not generated warnings, so I preserved this behaviour in clang). Other cases filtered by checks in appropriate casts.</div>
<div><br>Please, review.</div></div>