]> granicus.if.org Git - clang/commitdiff
Implicitly assume that a ObjC category to an unavailable interface is also unavailable;
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 6 Oct 2011 23:23:27 +0000 (23:23 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 6 Oct 2011 23:23:27 +0000 (23:23 +0000)
only give an 'unavailable' error on the @implementation of the category. rdar://10234078

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141335 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclAttr.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExpr.cpp
test/SemaObjC/attr-deprecated.m
test/SemaObjC/class-unavail-warning.m
test/SemaObjC/warn-deprecated-implementations.m

index 6aee5900e2d6b577289d1d202f759d1b5fce6f0c..7c86a15c2d636608d263b5dbe745c3f37f973d02 100644 (file)
@@ -6165,6 +6165,8 @@ public:
   DeclContext *getCurLexicalContext() const {
     return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
   }
+
+  AvailabilityResult getCurContextAvailability() const;
 };
 
 /// \brief RAII object that enters a new expression evaluation context.
index 4a4862bec4ce4e5fddf4a424f6a0ce82c8220e78..3692f447b317840fe65006206f30771f14c5c605 100644 (file)
@@ -9663,3 +9663,12 @@ void Sema::ActOnPragmaWeakAlias(IdentifierInfo* Name,
 Decl *Sema::getObjCDeclContext() const {
   return (dyn_cast_or_null<ObjCContainerDecl>(CurContext));
 }
+
+AvailabilityResult Sema::getCurContextAvailability() const {
+  const Decl *D = cast<Decl>(getCurLexicalContext());
+  // A category implicitly has the availability of the interface.
+  if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(D))
+    D = CatD->getClassInterface();
+  
+  return D->getAvailability();
+}
index e5ea1610ad587a70cd3360cad066bb71a5a60708..93efac0651b897614accd765a1eccc2b4ba5846b 100644 (file)
@@ -4002,6 +4002,9 @@ static bool isDeclDeprecated(Decl *D) {
   do {
     if (D->isDeprecated())
       return true;
+    // A category implicitly has the availability of the interface.
+    if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(D))
+      return CatD->getClassInterface()->isDeprecated();
   } while ((D = cast_or_null<Decl>(D->getDeclContext())));
   return false;
 }
index 1a1ac2eccf134b9d869ecbf288f2159c8ab26b2d..af2eb1287b3ca10b19dca5279dc27adc0ad6104b 100644 (file)
@@ -770,9 +770,6 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
   // FIXME: PushOnScopeChains?
   CurContext->addDecl(CDecl);
 
-  // If the interface is deprecated, warn about it.
-  (void)DiagnoseUseOfDecl(IDecl, ClassLoc);
-
   if (NumProtoRefs) {
     CDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs, 
                            ProtoLocs, Context);
@@ -818,6 +815,10 @@ Decl *Sema::ActOnStartCategoryImplementation(
   // FIXME: PushOnScopeChains?
   CurContext->addDecl(CDecl);
 
+  // If the interface is deprecated/unavailable, warn/error about it.
+  if (IDecl)
+    DiagnoseUseOfDecl(IDecl, ClassLoc);
+
   /// Check that CatName, category name, is not used in another implementation.
   if (CatIDecl) {
     if (CatIDecl->getImplementation()) {
index 05b0bb7efc7fa247dd524a7ef7fb163460ba6e3f..96af0e4c8ea054c6ee19c7191f68ef4a4c82142f 100644 (file)
@@ -72,8 +72,7 @@ static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S,
       break;
             
     case AR_Unavailable:
-      if (cast<Decl>(S.getCurLexicalContext())->getAvailability() !=
-            AR_Unavailable) {
+      if (S.getCurContextAvailability() != AR_Unavailable) {
         if (Message.empty()) {
           if (!UnknownObjCClass)
             S.Diag(Loc, diag::err_unavailable) << D->getDeclName();
index be6c51f8c415105bf929638cf14541cd268a9208..ca267599288e8c45f7b2b30047202ccf9c889816 100644 (file)
@@ -92,7 +92,14 @@ __attribute ((deprecated))
 @property  int prop; 
 @end
 
-@interface DEPRECATED (Category) // expected-warning {{warning: 'DEPRECATED' is deprecated}}
+@interface DEPRECATED (Category) // no warning.
+- (DEPRECATED *) meth2; // no warning.
+@end
+
+@interface DEPRECATED (Category2) // no warning.
+@end
+
+@implementation DEPRECATED (Category2) // expected-warning {{warning: 'DEPRECATED' is deprecated}}
 @end
 
 @interface NS : DEPRECATED  // expected-warning {{warning: 'DEPRECATED' is deprecated}}
index a0c2d5588e676d06dbb3fffbc0d5d50f7a9e92d8..b2bd38831101c444b26a1e01ec0755d39f237990 100644 (file)
@@ -2,7 +2,7 @@
 // rdar://9092208
 
 __attribute__((unavailable("not available")))
-@interface MyClass { // expected-note 7 {{declaration has been explicitly marked unavailable here}}
+@interface MyClass { // expected-note 8 {{declaration has been explicitly marked unavailable here}}
 @public
     void *_test;
     MyClass *ivar; // no error.
@@ -21,6 +21,16 @@ __attribute__((unavailable("not available")))
 - (MyClass *)meth; // expected-error {{unavailable}}
 @end
 
+@interface MyClass (Cat1)
+- (MyClass *)meth; // no error.
+@end
+
+@interface MyClass (Cat2) // no error.
+@end
+
+@implementation MyClass (Cat2) // expected-error {{unavailable}}
+@end
+
 int main() {
  [MyClass new]; // expected-error {{'MyClass' is unavailable: not available}}
  [MyClass self]; // expected-error {{'MyClass' is unavailable: not available}}
index 7bcd10cc3e061e4fbaf05c48bd9c64712edc00f2..60da7b0c41dc71a6403b01cb5d8b7407c21760c1 100644 (file)
@@ -26,7 +26,8 @@ __attribute__((deprecated))
 @implementation CL // expected-warning {{Implementing deprecated class}}
 @end
 
-@implementation CL ( SomeCategory ) // expected-warning {{Implementing deprecated category}}
+@implementation CL ( SomeCategory ) // expected-warning {{'CL' is deprecated}} \
+                                    // expected-warning {{Implementing deprecated category}}
 @end
 
 @interface CL_SUB : CL // expected-warning {{'CL' is deprecated}}