From: Chris Lattner Date: Sun, 25 Oct 2009 22:31:57 +0000 (+0000) Subject: Implement rdar://6756623 - use of deprecated type in deprecated typedef should not... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=523382640e9b099dd64ba0875a60a9356845b068;p=clang Implement rdar://6756623 - use of deprecated type in deprecated typedef should not warn git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85073 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index cb840efe15..fa10dead6e 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1583,7 +1583,8 @@ public: //===--------------------------------------------------------------------===// // Expression Parsing Callbacks: SemaExpr.cpp. - bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc); + bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, + bool IgnoreDeprecated = false); bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, ObjCMethodDecl *Getter, SourceLocation Loc); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index f263e73970..78647e392f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -37,20 +37,24 @@ using namespace clang; /// used, or produce an error (and return true) if a C++0x deleted /// function is being used. /// +/// If IgnoreDeprecated is set to true, this should not want about deprecated +/// decls. +/// /// \returns true if there was an error (this declaration cannot be /// referenced), false otherwise. -bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { +/// +bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, + bool IgnoreDeprecated) { // See if the decl is deprecated. if (D->getAttr()) { // Implementing deprecated stuff requires referencing deprecated - // stuff. Don't warn if we are implementing a deprecated - // construct. - bool isSilenced = false; + // stuff. Don't warn if we are implementing a deprecated construct. + bool isSilenced = IgnoreDeprecated; if (NamedDecl *ND = getCurFunctionOrMethodDecl()) { // If this reference happens *in* a deprecated function or method, don't // warn. - isSilenced = ND->getAttr(); + isSilenced |= ND->getAttr() != 0; // If this is an Objective-C method implementation, check to see if the // method was deprecated on the declaration, not the definition. diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 01490fc69f..029aecc045 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -67,6 +67,16 @@ static bool isOmittedBlockReturnType(const Declarator &D) { return false; } +/// isDeclaratorDeprecated - Return true if the declarator is deprecated. +/// We do not want to warn about use of deprecated types (e.g. typedefs) when +/// defining a declaration that is itself deprecated. +static bool isDeclaratorDeprecated(const Declarator &D) { + for (const AttributeList *AL = D.getAttributes(); AL; AL = AL->getNext()) + if (AL->getKind() == AttributeList::AT_deprecated) + return true; + return false; +} + /// \brief Convert the specified declspec to the appropriate type /// object. /// \param D the declarator containing the declaration specifier. @@ -237,7 +247,8 @@ static QualType ConvertDeclSpecToType(Declarator &TheDeclarator, Sema &TheSema){ } // If the type is deprecated or unavailable, diagnose it. - TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc()); + TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc(), + isDeclaratorDeprecated(TheDeclarator)); assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!"); @@ -298,15 +309,18 @@ static QualType ConvertDeclSpecToType(Declarator &TheDeclarator, Sema &TheSema){ TheDeclarator.setInvalidType(true); // If the type is deprecated or unavailable, diagnose it. - TheSema.DiagnoseUseOfDecl(TDT->getDecl(), DS.getTypeSpecTypeLoc()); + TheSema.DiagnoseUseOfDecl(TDT->getDecl(), DS.getTypeSpecTypeLoc(), + isDeclaratorDeprecated(TheDeclarator)); } else if (ObjCInterfaceType *OIT = dyn_cast(Result)) { // If the type is deprecated or unavailable, diagnose it. - TheSema.DiagnoseUseOfDecl(OIT->getDecl(), DS.getTypeSpecTypeLoc()); + TheSema.DiagnoseUseOfDecl(OIT->getDecl(), DS.getTypeSpecTypeLoc(), + isDeclaratorDeprecated(TheDeclarator)); } else if (ObjCObjectPointerType *DPT = dyn_cast(Result)) { // If the type is deprecated or unavailable, diagnose it. if (ObjCInterfaceDecl *D = DPT->getInterfaceDecl()) - TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc()); + TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc(), + isDeclaratorDeprecated(TheDeclarator)); } diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index 45c5dd0676..527f0106d4 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -49,3 +49,9 @@ struct bar_dep __attribute__((deprecated, struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}} + +// These should not warn because the actually declaration itself is deprecated. +// rdar://6756623 +foo_dep *test4 __attribute__((deprecated)); +struct bar_dep *test5 __attribute__((deprecated)); +