[cfe-dev] ArrayType and qualifiers
rjmccall at apple.com
Fri Jan 28 01:26:32 PST 2011
On Jan 28, 2011, at 12:39 AM, Abramo Bagnara wrote:
> 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; converting that to the type of x (const T*) is a 188.8.131.52p2 pointer conversion.
> It seems you're definitely right.
Hmm. Actually, I think I'm wrong. :) In C, array types are never qualified, only their element types; so while my argument is sound in principle, it's not actually following the specification.
That said, this is quite arguably a flaw in the specification, and it's been so argued in quite a few places, as mentioned and linked from here:
so we should probably add a -pedantic warning for this at least. I've file http://llvm.org/bugs/show_bug.cgi?id=9082 to track this.
> 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.
FWIW, Intel and Comeau aren't independent implementations; they're both EDG-based.
>>>>> 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.
Thank you. I'm sorry to keep changing the AST out from under you; we really do think this is the right technical design.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev