Is there a way that Clang can check if the warning is turned off and skip
the expensive checking?
And did you mean the list in [basic.lval]p15?  [basic.lval]p10 doesn't have
a list.

On Wed, Apr 27, 2011 at 4:32 PM, John McCall <[email protected]> wrote:

> On Apr 27, 2011, at 4:18 PM, Richard Trieu wrote:
> > 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?
>
> +// Returns false if the reinterpret_cast has undefined behavior.
> +// SrcType = A, DestType = B
> +// *reinterpret_cast<B*>(&A)
> +// reinterpret_cast<&B>(A)
> +bool Sema::CompatibleReinterpretCast(QualType SrcType,
>
> You have punctuation backwards in the comment.  Also, this is a predicate
> and should be named like one, e.g. "isCompatibleReinterpretCast".
>
> If the intent of this warning is to warn about violations of the aliasing
> rules
> in [basic.lval]p10, you really need to white-list all those cases.  That's
> going
> to be kindof expensive to check on every reinterpret_cast for a warning
> that's disabled by default.
>
> +  if (S.getLangOptions().CPlusPlus && isa<CXXReinterpretCastExpr>(Op)) {
> +    QualType OpOrigType = Op->IgnoreParenCasts()->getType();
> +    if (OpOrigType->isPointerType() && OpTy->isPointerType()) {
>
> Unconditionally checking for CXXReinterpretCastExpr is very likely
> faster than checking for the language option.
>
> Also, you should use getAs<PointerType>() instead of
> isPointerType() / getPointeeType().
>
> John.
>
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to