[cfe-dev] ArrayType and qualifiers
Abramo Bagnara
abramo.bagnara at gmail.com
Thu Jan 27 15:33:48 PST 2011
Il 27/01/2011 22:18, John McCall ha scritto:
> On Jan 27, 2011, at 10:03 AM, Abramo Bagnara wrote:
>> In recent clang versions while syntactically parsed ArrayTypes have
>> qualifiers in element type (congruently with the standard), canonical
>> ArrayTypes have qualifers *only* on array type.
>
> Syntactically parsed array types can have qualifiers at any level due to
> typedefs, just like always.
Sorry, I should have explained better myself: I meant qualifier on
syntactically expressed ArrayTypes, not typedefs that when desugared are
array types.
>> 1) why element qualifiers are *moved* to ArrayType instead of to be
>> *propagated* to ArrayType? (i.e. qualifiers would be in both ArrayType
>> and element type)
>
> Because it's still quite expensive to canonicalize a type in that representation,
> and it becomes very awkward to manipulate qualifiers on even canonical
> types.
I'm not sure to follow you: canonicalization would not become more CPU
expensive with that representation, we've tried the patch and it is trivial.
OTOH the patch lead to some failure with tests similar to this:
void f() {
const int (*x)[1] = 0;
int (*y)[1] = 0;
x = y;
}
probably due to the fact that type convertibility check currently does
not expect to find a difference also on int qualifiers.
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++).
I've not verified if this behaviour is a regression introduced by recent
changes.
>> 2) considered that now calling getElementType() on a canonical ArrayType
>> 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.
Note also that to increase further the confusion, the API has also
QualType ASTContext::getBaseElementType(const ArrayType *VAT) const...
it's a mystery for me how this might work correctly. I'd hope it is
never called ;-)
More information about the cfe-dev
mailing list