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/Sema/SemaDeclCXX.cpp | |
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/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b0e18d865c..56381e76f8 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -587,7 +587,7 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, for (unsigned idx = 0; idx < NumBases; ++idx) { QualType NewBaseType = Context.getCanonicalType(Bases[idx]->getType()); - NewBaseType = NewBaseType.getUnqualifiedType(); + NewBaseType = NewBaseType.getLocalUnqualifiedType(); if (KnownBaseTypes[NewBaseType]) { // C++ [class.mi]p3: @@ -1140,8 +1140,7 @@ Sema::BuildBaseInitializer(QualType BaseType, Expr **Args, const CXXBaseSpecifier *DirectBaseSpec = 0; for (CXXRecordDecl::base_class_const_iterator Base = ClassDecl->bases_begin(); Base != ClassDecl->bases_end(); ++Base) { - if (Context.getCanonicalType(BaseType).getUnqualifiedType() == - Context.getCanonicalType(Base->getType()).getUnqualifiedType()) { + if (Context.hasSameUnqualifiedType(BaseType, Base->getType())) { // We found a direct base of this type. That's what we're // initializing. DirectBaseSpec = &*Base; @@ -3649,8 +3648,8 @@ Sema::CompareReferenceRelationship(SourceLocation Loc, QualType T1 = Context.getCanonicalType(OrigT1); QualType T2 = Context.getCanonicalType(OrigT2); - QualType UnqualT1 = T1.getUnqualifiedType(); - QualType UnqualT2 = T2.getUnqualifiedType(); + QualType UnqualT1 = T1.getLocalUnqualifiedType(); + QualType UnqualT2 = T2.getLocalUnqualifiedType(); // C++ [dcl.init.ref]p4: // Given types "cv1 T1" and "cv2 T2," "cv1 T1" is @@ -4756,7 +4755,7 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, QualType COldTy = Context.getCanonicalType(OldTy); if (CNewTy == COldTy && - CNewTy.getCVRQualifiers() == COldTy.getCVRQualifiers()) + CNewTy.getLocalCVRQualifiers() == COldTy.getLocalCVRQualifiers()) return false; // Check if the return types are covariant @@ -4785,7 +4784,7 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, return true; } - if (NewClassTy.getUnqualifiedType() != OldClassTy.getUnqualifiedType()) { + if (!Context.hasSameUnqualifiedType(NewClassTy, OldClassTy)) { // Check if the new class derives from the old class. if (!IsDerivedFrom(NewClassTy, OldClassTy)) { Diag(New->getLocation(), @@ -4807,7 +4806,7 @@ bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New, } // The qualifiers of the return types must be the same. - if (CNewTy.getCVRQualifiers() != COldTy.getCVRQualifiers()) { + if (CNewTy.getLocalCVRQualifiers() != COldTy.getLocalCVRQualifiers()) { Diag(New->getLocation(), diag::err_covariant_return_type_different_qualifications) << New->getDeclName() << NewTy << OldTy; |