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

John McCall rjmccall at apple.com
Wed Mar 20 16:45:18 PDT 2013


On Mar 20, 2013, at 4:26 PM, Alexander Zinenko <ftynse at gmail.com> wrote:
> Thanks for your comments and sorry that it's taking so long to polish my code.
> Please find the updated version attached.
> 
> On 20 March 2013 07:02, John McCall <rjmccall at apple.com> wrote:
> On Mar 14, 2013, at 8:47 AM, Alexander Zinenko <ftynse at gmail.com> wrote:
>> Thanks for review!
>> 
>> I attached a quiet version of a patch that doesn't warn if any of the paths is a non-virtually-derived base at offset zero.  
>> During first iteration, Jordan proposed to make a separate switch to enable a noisy version that warns even if the cast is safe, though. If it is still required, it can be easily added back.
>> Processing multiple base paths made checking a bit heavier, but I see no other approach.
> 
> +  if(!SrcRD || !SrcRD->hasDefinition())
> +    return;
> +
> +  const CXXRecordDecl *DestRD = DestType->getPointeeCXXRecordDecl();
> +
> +  if(!DestRD || !DestRD->hasDefinition())
> +    return;
> 
> Please add a comment saying that we're deliberately not instantiating
> templates here because we're not allowed to.
> Actually, we do not call CheckReinterpretCast if the cast is type-dependent.

I don't see your point.  Whether the cast is type-dependent has nothing to do
with it.  Both arguments could be non-dependent, or we could actually be
in a non-template context, and it'd still be illegal to instantiate the classes.
For example:

template <class T> class A { T val; };
class B {};

B *foo(A<void> *a) {
  return reinterpret_cast<B*>(a);
}

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130320/a6ea8f3f/attachment.html>


More information about the cfe-commits mailing list