[cfe-commits] r64679 - in /cfe/trunk: lib/Parse/ParseDeclCXX.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp test/Sema/attr-deprecated.c

Chris Lattner sabre at nondot.org
Mon Feb 16 14:07:16 PST 2009


Author: lattner
Date: Mon Feb 16 16:07:16 2009
New Revision: 64679

URL: http://llvm.org/viewvc/llvm-project?rev=64679&view=rev
Log:
diagnose uses of deprecated typenames and tags.
We now pass all the deprecation tests in the objc.dg suite.


Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/Sema/attr-deprecated.c

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=64679&r1=64678&r2=64679&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Feb 16 16:07:16 2009
@@ -358,9 +358,8 @@
                                      NameLoc, Attr);
 
   // Parse the optional base clause (C++ only).
-  if (getLang().CPlusPlus && Tok.is(tok::colon)) {
+  if (getLang().CPlusPlus && Tok.is(tok::colon))
     ParseBaseClause(TagOrTempDecl);
-  }
 
   // If there is a body, parse it and inform the actions module.
   if (Tok.is(tok::l_brace))

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=64679&r1=64678&r2=64679&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Feb 16 16:07:16 2009
@@ -43,30 +43,41 @@
 /// and then return NULL.
 Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
                                 Scope *S, const CXXScopeSpec *SS) {
-  Decl *IIDecl = 0;
+  NamedDecl *IIDecl = 0;
   LookupResult Result = LookupParsedName(S, SS, &II, LookupOrdinaryName, 
                                          false, false);
   switch (Result.getKind()) {
-    case LookupResult::NotFound:
-    case LookupResult::FoundOverloaded:
-      return 0;
+  case LookupResult::NotFound:
+  case LookupResult::FoundOverloaded:
+    return 0;
 
-    case LookupResult::AmbiguousBaseSubobjectTypes:
-    case LookupResult::AmbiguousBaseSubobjects:
-    case LookupResult::AmbiguousReference:
-      DiagnoseAmbiguousLookup(Result, DeclarationName(&II), NameLoc);
-      return 0;
+  case LookupResult::AmbiguousBaseSubobjectTypes:
+  case LookupResult::AmbiguousBaseSubobjects:
+  case LookupResult::AmbiguousReference:
+    DiagnoseAmbiguousLookup(Result, DeclarationName(&II), NameLoc);
+    return 0;
 
-    case LookupResult::Found:
-      IIDecl = Result.getAsDecl();
-      break;
+  case LookupResult::Found:
+    IIDecl = Result.getAsDecl();
+    break;
   }
 
   if (IIDecl) {
-    if (TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl))
+    if (TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
+      // If this typename is deprecated, emit a warning.
+      DiagnoseUseOfDeprecatedDecl(IIDecl, NameLoc);
+      
       return Context.getTypeDeclType(TD).getAsOpaquePtr();
-    else if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl))
+    }
+    
+    if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl)) {
+      // If this typename is deprecated, emit a warning.
+      DiagnoseUseOfDeprecatedDecl(IIDecl, NameLoc);
+      
       return Context.getObjCInterfaceType(IDecl).getAsOpaquePtr();
+    }
+
+    // Otherwise, could be a variable, function etc.
   }
   return 0;
 }
@@ -3091,7 +3102,10 @@
     PrevDecl = 0;
   }
 
-  if (PrevDecl) {    
+  if (PrevDecl) {
+    // If the previous declaration was deprecated, emit a warning.
+    DiagnoseUseOfDeprecatedDecl(PrevDecl, NameLoc);
+    
     if (TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) {
       // If this is a use of a previous tag, or if the tag is already declared
       // in the same scope (so that the definition/declaration completes or

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=64679&r1=64678&r2=64679&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Feb 16 16:07:16 2009
@@ -111,7 +111,7 @@
 
     // Diagnose classes that inherit from deprecated classes.
     if (SuperClassDecl)
-      DiagnoseUseOfDeprecatedDeclImpl(SuperClassDecl, SuperLoc);
+      DiagnoseUseOfDeprecatedDecl(SuperClassDecl, SuperLoc);
     
     if (PrevDecl && SuperClassDecl == 0) {
       // The previous declaration was not a class decl. Check if we have a
@@ -270,7 +270,7 @@
       continue;
     }
     
-    DiagnoseUseOfDeprecatedDeclImpl(PDecl, ProtocolId[i].second);
+    DiagnoseUseOfDeprecatedDecl(PDecl, ProtocolId[i].second);
 
     // If this is a forward declaration and we are supposed to warn in this
     // case, do it.
@@ -493,7 +493,7 @@
   CDecl->setClassInterface(IDecl);
   
   // If the interface is deprecated, warn about it.
-  DiagnoseUseOfDeprecatedDeclImpl(IDecl, ClassLoc);
+  DiagnoseUseOfDeprecatedDecl(IDecl, ClassLoc);
 
   /// Check for duplicate interface declaration for this category
   ObjCCategoryDecl *CDeclChain;

Modified: cfe/trunk/test/Sema/attr-deprecated.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-deprecated.c?rev=64679&r1=64678&r2=64679&view=diff

==============================================================================
--- cfe/trunk/test/Sema/attr-deprecated.c (original)
+++ cfe/trunk/test/Sema/attr-deprecated.c Mon Feb 16 16:07:16 2009
@@ -41,3 +41,5 @@
   ++F->x;  // expected-warning {{'x' is deprecated}}
 }
 
+typedef struct foo foo_dep __attribute__((deprecated));
+foo_dep *test2;    // expected-warning {{'foo_dep' is deprecated}}





More information about the cfe-commits mailing list