[cfe-dev] ArrayType and qualifiers

Abramo Bagnara abramo.bagnara at gmail.com
Fri Jan 28 00:39:17 PST 2011


Il 28/01/2011 04:06, John McCall ha scritto:
>> Note that however also with current svn trunk we have a problem with
>> this test: the assignment x = y should be compiled without warning in
>> C++ *but* it's an assignment between incompatible pointers in C (clang
>> currently does not emit any warning on both C and C++).
> 
> It's not an assignment between incompatible pointers in C.  y is a T*, where T = int[1];  converting that to the type of x (const T*) is a 6.3.2.3p2 pointer conversion.

It seems you're definitely right.

The weird thing is that three independent implementation (GNU, Intel and
Comeau) get the same *wrong* result in C... I'm astonished, I wonder how
this might be happened.

>>>> returns the wrong result, how is possible to get the right element type
>>>> e.g. using TypeVisitor?
>>>
>>> I hadn't really considered the effects this would have on people using
>>> TypeVisitor on a canonical type.  Mostly, I wasn't aware that that was at all
>>> common.  If it is, maybe we should change TypeVisitor.
>>
>> I don't understand how this might be feasible: we enter
>> TypeVisitor::Visit with a Type* and as a consequence in the ArrayType
>> dispatcher we have already lost any info about qualifier that should be
>> applied to element type. The fact is that currently a canonical
>> ArrayType has not enough info to know the qualifiers of its element, I
>> believe this is an unfortunate situation.
> 
> This would obviously have to be done at the level of TypeVisitor::Visit(QualType).
> 
> That brings up a good point, actually — Visit(const Type*) is already stripping qualifiers off of every other type, so I'm not sure why I'm supposed to be particularly bothered that it strips the qualifiers off array types.

I believe the case is different here: for every other type the
qualifiers stripping is local and has no effect on inner types, for
arrays the qualifier stripping in array alter the interpretation of
inner nodes (I think that RecursiveASTVisitor will suffer of this).

However I think that we will proceed changing our visitors to save the
array qualifiers for later reapplication to element type.



More information about the cfe-dev mailing list