diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-16 21:35:15 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-16 21:35:15 +0000 |
commit | a4923eb7c4b04d360cb2747641a5e92818edf804 (patch) | |
tree | 573c9d43fd0b6daf0f1d5ee02ebbffd7e3e84cfd /lib/AST | |
parent | ad35a83102683b00a7e28707eee7f2d8c994b742 (diff) |
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST')
-rw-r--r-- | lib/AST/ASTContext.cpp | 8 | ||||
-rw-r--r-- | lib/AST/CXXInheritance.cpp | 4 | ||||
-rw-r--r-- | lib/AST/DeclCXX.cpp | 4 | ||||
-rw-r--r-- | lib/AST/TypePrinter.cpp | 5 |
4 files changed, 11 insertions, 10 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 9850ad6f53..1b3e09291d 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1186,7 +1186,7 @@ QualType ASTContext::getNoReturnType(QualType T) { } } - return getQualifiedType(ResultType, T.getQualifiers()); + return getQualifiedType(ResultType, T.getLocalQualifiers()); } /// getComplexType - Return the uniqued reference to the type for a complex @@ -2435,7 +2435,7 @@ ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) { const ArrayType *ASTContext::getAsArrayType(QualType T) { // Handle the non-qualified case efficiently. - if (!T.hasQualifiers()) { + if (!T.hasLocalQualifiers()) { // Handle the common positive case fast. if (const ArrayType *AT = dyn_cast<ArrayType>(T)) return AT; @@ -4204,8 +4204,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { return LHS; // If the qualifiers are different, the types aren't compatible... mostly. - Qualifiers LQuals = LHSCan.getQualifiers(); - Qualifiers RQuals = RHSCan.getQualifiers(); + Qualifiers LQuals = LHSCan.getLocalQualifiers(); + Qualifiers RQuals = RHSCan.getLocalQualifiers(); if (LQuals != RQuals) { // If any of these qualifiers are different, we have a type // mismatch. diff --git a/lib/AST/CXXInheritance.cpp b/lib/AST/CXXInheritance.cpp index d4f6e87173..023bca4363 100644 --- a/lib/AST/CXXInheritance.cpp +++ b/lib/AST/CXXInheritance.cpp @@ -99,8 +99,8 @@ bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches, for (base_class_const_iterator BaseSpec = bases_begin(), BaseSpecEnd = bases_end(); BaseSpec != BaseSpecEnd; ++BaseSpec) { // Find the record of the base class subobjects for this type. - QualType BaseType = Context.getCanonicalType(BaseSpec->getType()); - BaseType = BaseType.getUnqualifiedType(); + QualType BaseType = Context.getCanonicalType(BaseSpec->getType()) + .getUnqualifiedType(); // C++ [temp.dep]p3: // In the definition of a class template or a member of a class template, diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 9867e5a880..bfa338b365 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -211,7 +211,7 @@ bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context, if (!ArgType.isConstQualified()) AcceptsConst = false; } - if (Context.getCanonicalType(ArgType).getUnqualifiedType() != ClassType) + if (!Context.hasSameUnqualifiedType(ArgType, ClassType)) continue; MD = Method; // We have a single argument of type cv X or cv X&, i.e. we've found the @@ -276,7 +276,7 @@ void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context, QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( const_cast<CXXRecordDecl*>(this))); - if (ClassType != Context.getCanonicalType(ArgType)) + if (!Context.hasSameUnqualifiedType(ClassType, ArgType)) return; // This is a copy assignment operator. diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index 234d38a59f..a482333782 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -63,7 +63,7 @@ void TypePrinter::Print(QualType T, std::string &S) { return; // Print qualifiers as appropriate. - Qualifiers Quals = T.getQualifiers(); + Qualifiers Quals = T.getLocalQualifiers(); if (!Quals.empty()) { std::string TQS; Quals.getAsStringInternal(TQS, Policy); @@ -550,7 +550,8 @@ void TypePrinter::PrintObjCObjectPointer(const ObjCObjectPointerType *T, ObjCQIString += '>'; } - T->getPointeeType().getQualifiers().getAsStringInternal(ObjCQIString, Policy); + T->getPointeeType().getLocalQualifiers().getAsStringInternal(ObjCQIString, + Policy); if (!T->isObjCIdType() && !T->isObjCQualifiedIdType()) ObjCQIString += " *"; // Don't forget the implicit pointer. |