[cfe-dev] Creating New Types

Chris Lattner clattner at apple.com
Tue Aug 7 14:34:41 PDT 2007


On Aug 7, 2007, at 1:10 PM, Bill Wendling wrote:

> On 8/7/07, Chris Lattner <clattner at apple.com> wrote:
>>>> (This is related to the description of "casting away constness" in
>>>> the C++ standard [5.2.11p8].)
>>>
>>> How so?  const_cast should never change the underlying type (e.g.
>>> from float to char).  In fact, my understanding of const cast is  
>>> that
>>> it isn't a "recursive" process, it just looks at the top-level
>>> qualifiers and pointer/reference.
>>
>> Actually, const_cast has to *compare* the src and dest type
>> recursively, but I still don't think it has to *reconstruct* a mix of
>> the two.
>>
> It seemed to say that if one pointer type with N pointers could be
> implicitly cast to a "subtype" of another pointer type with M
> pointers, where N < M for some type T, then we aren't casting away
> constness. That's what I was doing with my example. I was going to use
> the implicit cast checking stuff to make sure that this is valid. I
> suppose it's possible to compare it recursively, if I can make sure
> that the checking is valid for each step.

I'm not certain I know what you mean, but I don't think that is  
valid.  Can you give me an example C++ function that does this for  
concreteness?

-Chris



More information about the cfe-dev mailing list