[cfe-commits] Patch: Add warning for undefined reinterpret_cast behavior

Richard Trieu rtrieu at google.com
Wed Apr 27 16:18:23 PDT 2011


Added a new check so that casting between tag types doesn't give the
warning.  Casting to/from chars and voids won't throw the warning either.
 Anything else needed?

On Mon, Apr 11, 2011 at 10:13 AM, John McCall <rjmccall at apple.com> wrote:

> On Apr 11, 2011, at 9:44 AM, Chandler Carruth wrote:
> > I share John and Doug's concern over false positive rates. However, I'd
> like to evaluate that by getting a conservative version of this in, trying
> it on some code, and evaluating the fallout. If this isn't useful we can
> drop it.
>
> As long as it's off by default and enabled by some extremely specific
> flag like -Wpedantic-aliasing.  I am not willing to consider a diagnostic
> that's on by default unless it's policing the relaxed aliasing rules that
> Clang uses, where l-values that "obviously" alias are allowed to alias
> regardless of type.
>
> > However, I think we could do a couple of things more to avoid
> false-positives:
> >
> > 1) Only warn on reference reinterpret casts when the result is in an
> lvalue-to-rvalue cast to avoid this false positive:
> >
> > float f = 0.0f;
> > int *x = &reinterpret_cast<int&>(f);
>
> That's probably reasonable.  I'd actually be okay with warning on this
> in general if you can come up with a small set of "universal-ish" types
> that
> you think it's reasonable to cast something through, like maybe void& and
> void*.
>
> Oh, and of course you can't warn about reinterpret_casts to/from
> references/pointers to char types.
>
> > 2) Don't warn for reinterpret casts of tag types.
>
> Probably a good first iteration.
>
> John.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110427/085df0cc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: undefined-reinterpret-cast2.patch
Type: text/x-patch
Size: 7371 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110427/085df0cc/attachment.bin>


More information about the cfe-commits mailing list