diff options
author | Anders Carlsson <andersca@mac.com> | 2009-02-14 19:08:58 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-02-14 19:08:58 +0000 |
commit | 59843ad8835d497cd3c17ff91aa039e31d607791 (patch) | |
tree | df9b3a7c77ff4746fa02ea3ab994775b20835076 | |
parent | 3c385e5f8d9008fff18597ca302be19fa86e51f6 (diff) |
Add support for deprecated Obj-C methods. The semantics mostly match what gcc has.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64562 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 12 | ||||
-rw-r--r-- | test/SemaObjC/attr-deprecated.m | 65 |
2 files changed, 77 insertions, 0 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 6e110506eb..91e7a185b0 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -268,6 +268,9 @@ Sema::ExprResult Sema::ActOnClassMessage( if (!Method) Method = ClassDecl->lookupInstanceMethod(Sel); + if (Method && Method->getAttr<DeprecatedAttr>()) + Diag(receiverLoc, diag::warn_deprecated) << Method->getDeclName(); + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, true, lbrac, rbrac, returnType)) return true; @@ -313,6 +316,9 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, Method = SuperDecl->lookupInstanceMethod(Sel); } + if (Method && Method->getAttr<DeprecatedAttr>()) + Diag(receiverLoc, diag::warn_deprecated) << Method->getDeclName(); + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; @@ -343,6 +349,9 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (ObjCImplementationDecl *ImpDecl = ObjCImplementations[ClassDecl->getIdentifier()]) Method = ImpDecl->getClassMethod(Sel); + + if (Method && Method->getAttr<DeprecatedAttr>()) + Diag(receiverLoc, diag::warn_deprecated) << Method->getDeclName(); } if (!Method) Method = FactoryMethodPool[Sel].Method; @@ -393,6 +402,9 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (!Method && !OCIReceiver->qual_empty()) Diag(lbrac, diag::warn_method_not_found_in_protocol) << Sel << SourceRange(lbrac, rbrac); + + if (Method && Method->getAttr<DeprecatedAttr>()) + Diag(receiverLoc, diag::warn_deprecated) << Method->getDeclName(); } else { Diag(lbrac, diag::error_bad_receiver_type) << RExpr->getType() << RExpr->getSourceRange(); diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m new file mode 100644 index 0000000000..9577e60b7d --- /dev/null +++ b/test/SemaObjC/attr-deprecated.m @@ -0,0 +1,65 @@ +// RUN: clang %s -fsyntax-only -verify + +@interface A ++ (void)F __attribute__((deprecated)); +- (void)f __attribute__((deprecated)); +@end + +@implementation A ++ (void)F __attribute__((deprecated)) +{ + [self F]; // expected-warning{{'F' is deprecated}} +} + +- (void)g +{ + [self f]; // expected-warning{{'f' is deprecated}} +} + +- (void)f +{ + [self f]; // expected-warning{{'f' is deprecated}} +} +@end + +@interface B: A +@end + +@implementation B ++ (void)G +{ + [super F]; // expected-warning{{'F' is deprecated}} +} + +- (void)g +{ + [super f]; // // expected-warning{{'f' is deprecated}} +} +@end + +@protocol P +- (void)p __attribute__((deprecated)); +@end + +void t1(A *a) +{ + [A F]; // expected-warning{{'F' is deprecated}} + [a f]; // expected-warning{{'f' is deprecated}} +} + +void t2(id a) +{ + [a f]; +} + +void t3(A<P>* a) +{ + [a f]; // expected-warning{{'f' is deprecated}} + [a p]; // expected-warning{{'p' is deprecated}} +} + +void t4(Class c) +{ + [c F]; +} + |