[cfe-commits] r59232 - /cfe/trunk/lib/Analysis/GRExprEngine.cpp

Ted Kremenek kremenek at apple.com
Mon Nov 17 19:42:55 PST 2008


On Nov 17, 2008, at 5:44 PM, Zhongxing Xu wrote:

>> The template argument const T& need a const type. But const  
>> MemRegion* is not a const type,
>> but a non-const pointer to const MemRegion. So T must match the  
>> entire 'const MemRegion*'.
>>
>> If T only matches 'MemRegion*', then the substituted type would be  
>> 'MemRegion* const', that is a const pointer to non-const MemRegion.
>>
>> So if we write
>>
>> template <typename T>
>> inline void Add(T const & x) { FoldingSetTrait<T>::Profile(x,  
>> *this); }
>>
>> that would be less confusing.
>
> The problem is that we want a 'const MemRegion*' so that Profile()  
> operators on constant objects.  If we had:
>
>   const MemRegion* R = ..
>   FoldingSetNodeID& ID;
>   ID.Add(R);
>
> then (I don't believe) that this wouldn't work if we change Add() to  
> take a "T const& x" because it would require that the const  
> qualifier in 'const MemRegion*' to be cast way.
>
> You probably misunderstand me. In fact, 'T const& x' is the same as  
> 'const T& x'. It's just less confusing, as suggested in Vandevoorde  
> & Josuttis's C++ Templates, page 4.

Ahh, I think I follow you now.   This sounds like a good approach to me!



More information about the cfe-commits mailing list