[cfe-commits] [PATCH] -Wcast-qual

Chandler Carruth chandlerc at google.com
Wed Jun 20 04:31:28 PDT 2012


FYI, this in http://llvm.org/PR4802

You might want to drop a note there in case anyone else is looking at this.

On Wed, Jun 20, 2012 at 2:53 AM, Igor Minin <i.minin.llvm at gmail.com> wrote:

> Hello.
>
> The attached patch adds support for a clang -Wcast-qual option. Semantic
> is compatible with the gcc one.
>
> Warn whenever a pointer is cast so as to remove a type qualifier from the
>> target
>> type. For example, warn if a "const char*" is cast to an ordinary "char*".
>> Also warn when making a cast that introduces a type qualifier in an
>> unsafe way.
>> For example, casting "char**" to "const char**" is unsafe, as in this
>> example:
>> /* p is char ** value. */
>> const char **q = (const char **) p;
>> /* Assignment of readonly string to const char * is OK. */
>> *q = "string";
>> /* Now char** pointer points to read-only memory. */
>> **p = ’b’;
>
> (Gcc manual).
>
> What is "introducing in an unsafe way" precisely described in [conv.qual]
> item of C++ standard.
>
> So, the proposed patch is very similar to the code that checks assign
> constrains. Differences are:
>
> * This patch generates only warnings, not errors, which helps to have
> cleaner implementation.
> * 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.
>
> Please, review.
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120620/306b1512/attachment.html>


More information about the cfe-commits mailing list