[cfe-dev] For Review: C++ Casting Patch

Chris Lattner clattner at apple.com
Wed Apr 16 22:11:23 PDT 2008


On Apr 16, 2008, at 10:08 PM, Bill Wendling wrote:

>>
>> +  if (CastTyBase.getTypePtr() == ExprTyBase.getTypePtr())
>> +    return true;
>>
>> This isn't safe, one might be a typedef for the other.  Also, you  
>> should have comments in your methods explaining why you are doing  
>> what you are doing.
>>
> At this point, one of them won't be a pointer type. Essentially,  
> what I want this method to do is go through all of the layers of  
> both pointer types until it gets to the base type. It then checks to  
> see if the base types are equal (the code you quoted above). I take  
> it from your comment that this isn't sufficient to do that. How do I  
> check past the typedefs when the types may not be pointers at all?  
> Should I use "getDesugaredType()"?


For exact equality (including CV qualifiers etc), something like this  
should work:

if (SourceMgr.getCanoncicalType(CastTyBase.getTypePtr()) ==  
SourceMgr.getCanonicalType(ExprTyBase.getTypePtr()))

-Chris



More information about the cfe-dev mailing list