diff options
author | Chris Lattner <sabre@nondot.org> | 2009-10-25 22:09:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-10-25 22:09:09 +0000 |
commit | a64ef0ab5cb6ac9cfb7d40661a9152c4aa488386 (patch) | |
tree | be3aef3e54bad6b57d314ac336a4188b89845d58 | |
parent | e37b3e6d7ed495fdec4067ccc1117a79d2afd450 (diff) |
move calls to DiagnoseUseOfDecl (which warns about deprecated/unavailable
types) out of Sema::getTypeName into ConvertDeclSpecToType. getTypeName
is sometimes used as a predicate in the parser, so it could cause redundant
diags to be emitted. This is also needed by two upcoming enhancements.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85070 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 30 |
2 files changed, 24 insertions, 15 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index d18ac61b71..08d7235665 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -95,7 +95,7 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, case LookupResult::FoundOverloaded: return 0; - case LookupResult::Ambiguous: { + case LookupResult::Ambiguous: // Recover from type-hiding ambiguities by hiding the type. We'll // do the lookup again when looking for an object, and we can // diagnose the error then. If we don't do this, then the error @@ -131,7 +131,6 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, // perform the name lookup again. DiagnoseAmbiguousLookup(Result, DeclarationName(&II), NameLoc); break; - } case LookupResult::Found: IIDecl = Result.getFoundDecl(); @@ -142,9 +141,6 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, QualType T; if (TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) { - // Check whether we can use this type. - (void)DiagnoseUseOfDecl(IIDecl, NameLoc); - // C++ [temp.local]p2: // Within the scope of a class template specialization or // partial specialization, when the injected-class-name is @@ -164,9 +160,6 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, T = getQualifiedNameType(*SS, T); } else if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl)) { - // Check whether we can use this interface. - (void)DiagnoseUseOfDecl(IIDecl, NameLoc); - T = Context.getObjCInterfaceType(IDecl); } else return 0; diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 50f1be2800..01490fc69f 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -58,11 +58,11 @@ static bool isOmittedBlockReturnType(const Declarator &D) { return false; if (D.getNumTypeObjects() == 0) - return true; + return true; // ^{ ... } if (D.getNumTypeObjects() == 1 && D.getTypeObject(0).Kind == DeclaratorChunk::Function) - return true; + return true; // ^(int X, float Y) { ... } return false; } @@ -228,7 +228,7 @@ static QualType ConvertDeclSpecToType(Declarator &TheDeclarator, Sema &TheSema){ case DeclSpec::TST_enum: case DeclSpec::TST_union: case DeclSpec::TST_struct: { - Decl *D = static_cast<Decl *>(DS.getTypeRep()); + TypeDecl *D = cast_or_null<TypeDecl>(static_cast<Decl *>(DS.getTypeRep())); if (!D) { // This can happen in C++ with ambiguous lookups. Result = Context.IntTy; @@ -236,11 +236,14 @@ static QualType ConvertDeclSpecToType(Declarator &TheDeclarator, Sema &TheSema){ break; } + // If the type is deprecated or unavailable, diagnose it. + TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc()); + assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && - DS.getTypeSpecSign() == 0 && - "Can't handle qualifiers on typedef names yet!"); + DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!"); + // TypeQuals handled by caller. - Result = Context.getTypeDeclType(cast<TypeDecl>(D)); + Result = Context.getTypeDeclType(D); // In C++, make an ElaboratedType. if (TheSema.getLangOptions().CPlusPlus) { @@ -290,9 +293,22 @@ static QualType ConvertDeclSpecToType(Declarator &TheDeclarator, Sema &TheSema){ } // If this is a reference to an invalid typedef, propagate the invalidity. - if (TypedefType *TDT = dyn_cast<TypedefType>(Result)) + if (TypedefType *TDT = dyn_cast<TypedefType>(Result)) { if (TDT->getDecl()->isInvalidDecl()) TheDeclarator.setInvalidType(true); + + // If the type is deprecated or unavailable, diagnose it. + TheSema.DiagnoseUseOfDecl(TDT->getDecl(), DS.getTypeSpecTypeLoc()); + } else if (ObjCInterfaceType *OIT = dyn_cast<ObjCInterfaceType>(Result)) { + // If the type is deprecated or unavailable, diagnose it. + TheSema.DiagnoseUseOfDecl(OIT->getDecl(), DS.getTypeSpecTypeLoc()); + } else if (ObjCObjectPointerType *DPT = + dyn_cast<ObjCObjectPointerType>(Result)) { + // If the type is deprecated or unavailable, diagnose it. + if (ObjCInterfaceDecl *D = DPT->getInterfaceDecl()) + TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc()); + } + // TypeQuals handled by caller. break; |