diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-10-06 23:23:27 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-10-06 23:23:27 +0000 |
commit | c076e37e2223cfe998fa5e657dece30da78fcdc4 (patch) | |
tree | 85391761a23e7d9965646c6cd3c89e43543ffc08 | |
parent | 3a387441ae339363ee5b254658f295e97bd9e913 (diff) |
Implicitly assume that a ObjC category to an unavailable interface is also unavailable;
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
-rw-r--r-- | include/clang/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 3 | ||||
-rw-r--r-- | test/SemaObjC/attr-deprecated.m | 9 | ||||
-rw-r--r-- | test/SemaObjC/class-unavail-warning.m | 12 | ||||
-rw-r--r-- | test/SemaObjC/warn-deprecated-implementations.m | 3 |
8 files changed, 40 insertions, 8 deletions
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 6aee5900e2..7c86a15c2d 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -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. diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 4a4862bec4..3692f447b3 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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(); +} diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index e5ea1610ad..93efac0651 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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; } diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 1a1ac2eccf..af2eb1287b 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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()) { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 05b0bb7efc..96af0e4c8e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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(); diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m index be6c51f8c4..ca26759928 100644 --- a/test/SemaObjC/attr-deprecated.m +++ b/test/SemaObjC/attr-deprecated.m @@ -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}} diff --git a/test/SemaObjC/class-unavail-warning.m b/test/SemaObjC/class-unavail-warning.m index a0c2d5588e..b2bd388311 100644 --- a/test/SemaObjC/class-unavail-warning.m +++ b/test/SemaObjC/class-unavail-warning.m @@ -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}} diff --git a/test/SemaObjC/warn-deprecated-implementations.m b/test/SemaObjC/warn-deprecated-implementations.m index 7bcd10cc3e..60da7b0c41 100644 --- a/test/SemaObjC/warn-deprecated-implementations.m +++ b/test/SemaObjC/warn-deprecated-implementations.m @@ -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}} |