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

Alexander Zinenko ftynse at gmail.com
Wed Jan 23 13:33:19 PST 2013


Thanks for feedback! Here is an updated version. It warns by default in
case of virtual base or in case of nonzero offset. Other up/downcasts lead
to a warning with -Wreinterpret-updown-extra, ignored by default.


On 23 January 2013 04:31, Jordan Rose <jordan_rose at apple.com> wrote:

>
> On Jan 22, 2013, at 16:08 , John McCall <rjmccall at apple.com> wrote:
>
> On Jan 22, 2013, at 2:58 PM, Alexander Zinenko <ftynse at gmail.com> wrote:
>
> The attached patch addresses http://llvm.org/bugs/show_bug.cgi?id=13824.
> It emits a warning if reinterpret_cast is actually used to perform an
> upcast or a downcast which might lead to segfault in some cases.
>
>
> In most cases, this is actually safe, and I don't feel comfortable saying
> it's unreasonable for code to rely on that.  This warning should only fire
> when the base subobject is in a virtual base or at a nonzero static offset.
>
> You can use a CXXBasePaths object with Sema::IsDerivedFrom in order to
> determine the subobject access path.
>
>
> I think I would still have a warning, since reinterpret_cast is harder to
> check statically and therefore is less future-proof. But I could see that
> warning being controlled by a separate flag.
>
> Jordan
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130123/0d7f9f54/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 13824.patch
Type: application/octet-stream
Size: 27200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130123/0d7f9f54/attachment.obj>


More information about the cfe-commits mailing list