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

Alexander Zinenko ftynse at gmail.com
Wed Mar 20 17:00:32 PDT 2013


I agree with your point about instantiation. My example is just another
case that should not be checked. And it happens that this is getting done
by the same condition "has no complete definition". I added a comment
covering all of this anyways.

On Thursday, March 21, 2013, John McCall wrote:

> On Mar 20, 2013, at 4:26 PM, Alexander Zinenko <ftynse at gmail.com<javascript:_e({}, 'cvml', '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<javascript:_e({}, 'cvml', 'rjmccall at apple.com');>
> > wrote:
>
>> On Mar 14, 2013, at 8:47 AM, Alexander Zinenko <ftynse at gmail.com<javascript:_e({}, 'cvml', '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/20130321/87b496e4/attachment.html>


More information about the cfe-commits mailing list