]> granicus.if.org Git - clang/commitdiff
Implement rdar://6756623 - use of deprecated type in deprecated typedef should not...
authorChris Lattner <sabre@nondot.org>
Sun, 25 Oct 2009 22:31:57 +0000 (22:31 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 25 Oct 2009 22:31:57 +0000 (22:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85073 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp
lib/Sema/SemaType.cpp
test/Sema/attr-deprecated.c

index cb840efe15fc57373264154231b573bbf4b69109..fa10dead6e3c46aaa8af7569b4201e33cdb45be3 100644 (file)
@@ -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);
index f263e73970e595e71f6dfacfa5bb10644a44ac1f..78647e392fb5283fcc86a84b7fc6858af83b5899 100644 (file)
@@ -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<DeprecatedAttr>()) {
     // 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<DeprecatedAttr>();
+      isSilenced |= ND->getAttr<DeprecatedAttr>() != 0;
 
       // If this is an Objective-C method implementation, check to see if the
       // method was deprecated on the declaration, not the definition.
index 01490fc69f7e7ba46fbefe27bf930919f2504a64..029aecc0456b9a733d96fc4f3ce9c2f553c80d35 100644 (file)
@@ -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<ObjCInterfaceType>(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<ObjCObjectPointerType>(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));
     }
 
 
index 45c5dd0676b533a02e1ed390c3bca6c229738703..527f0106d46854367431ce0852b15db4dfd5189f 100644 (file)
@@ -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));
+