[cfe-commits] r92289 - in /cfe/trunk: include/clang/AST/Type.h lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/deduction.cpp

Chandler Carruth chandlerc at google.com
Tue Dec 29 22:24:14 PST 2009

On Tue, Dec 29, 2009 at 9:58 PM, Chris Lattner <clattner at apple.com> wrote:
> On Dec 29, 2009, at 8:53 PM, John McCall wrote:
>> On Dec 29, 2009, at 8:10 PM, Chandler Carruth wrote:
>>> +/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this
>>> +/// type, returns them. Otherwise, if this is an array type, recurses
>>> +/// on the element type until some qualifiers have been found or a non-array
>>> +/// type reached.
>>> +inline unsigned QualType::getCVRQualifiersThroughArrayTypes() const {
>>> +  if (unsigned Quals = getCVRQualifiers())
>>> +    return Quals;
>>> +  QualType CT = getTypePtr()->getCanonicalTypeInternal();
>>> +  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
>>> +    return AT->getElementType().getCVRQualifiersThroughArrayTypes();
>>> +  return 0;
>>> +}
>> The CVR qualifiers on an array type are the union of the CVR qualifiers on every level of the type.  You can't just stop at the first level that defines CVR qualifiers (well, unless it defines all the qualifiers, but that's not worth checking for).
>> Also I'm suspicious of adding a new accessor for this;  I think QualType::getCVRQualifiers(), isConstQualified(), etc. just need to look through array types the same way getAddressSpace() does.  If that's prohibitively expensive, we should solve that problem separately, probably by duplicating qualifiers at all levels in the canonical types for arrays.
> This should just be looking at the CVR qualifiers of the canonical type for the array.  If those CVR qualifiers aren't right, that should be fixed.  It shouldn't be fixed by adding new stuff like this.

The canonical type for the array places the CVR qualifiers exclusively
on the element type, which seems in keeping with the wording of the
standard. My reading of the standard here (second half of
[basic.type.qualifier] p5) is that CVR qualifiers should not by
default include those of the element type. If anything, it might
assert that they are always empty for array types. It only seems valid
to drop to the element type's CVR qualifiers when determining if the
type is more or less qualified than another. That is what motivated
the different accessor, and then having the comparison methods use it.

John, what was your motivation for having this occur by default when
querying the qualification of an array type? I suppose you could read
that paragraph to say that the array and its element type must always
have one and the same qualification rather than the array type is
without qualification. If that's you're stance, then it would fall out
naturally to merely query the canonical type's CVR qualifiers.

> -Chris
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

More information about the cfe-commits mailing list