[cfe-commits] [PATCH] PR13824 warn if reinterpret_cast used for up/downcast

Jordan Rose jordan_rose at apple.com
Tue Mar 12 10:01:55 PDT 2013


Pinging this myself, adding Richard Smith as another reviewer. I don't quite feel qualified to give the final word on it, but I'm fixing an analyzer bug that's basically "don't crash when the user does this in exactly the right wrong way", and it'd be nice to have a warning so that they fix their code.

Reattaching Alexander's patch.

Jordan


On Feb 11, 2013, at 8:14 , Alexander Zinenko <ftynse at gmail.com> wrote:

> Ping?
> 
> 
> On 28 January 2013 23:03, Alexander Zinenko <ftynse at gmail.com> wrote:
> Hello!
> 
> If this patch is good enough, could someone commit it, please?
> 
> 
> On 24 January 2013 21:55, Alexander Zinenko <ftynse at gmail.com> wrote:
> On 24 January 2013 04:33, Jordan Rose <jordan_rose at apple.com> wrote:
> 
> On Jan 23, 2013, at 14:53 , Dmitri Gribenko <gribozavr at gmail.com> wrote:
> > I think the only reasonable false positive source for zero adjustment
> > case is templates:
> >
> > template<typename T, typename U>
> > void foo(T *t) {
> >  ... reinterpret_cast<U*>(t);
> > }
> >
> > Where T and U have some subtyping relationship.
> 
> Warning could be disabled for dependent types. 
> Trivial case warning adds an extra note where the template was instantiated, though. As for me it's worth still having it enabled.
>  
> template.cpp:15:10: warning: 'reinterpret_cast' is used as an upcast from type 'B *' to its base type 'A *' [-Wreinterpret-updown-zero-adjustment]
>   (void)*reinterpret_cast<U *>(t);
>          ^~~~~~~~~~~~~~~~~~~~~~~~
> template.cpp:20:3: note: in instantiation of function template specialization 'foo<B, A>' requested here
>   foo<B, A>(&b);
>  


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130312/75fb0d9f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 13824.patch
Type: application/octet-stream
Size: 28368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130312/75fb0d9f/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130312/75fb0d9f/attachment-0001.html>


More information about the cfe-commits mailing list