aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-16 18:35:08 +0000
committerChris Lattner <sabre@nondot.org>2009-02-16 18:35:08 +0000
commit7eba82e4be8f437120d9089f4424e2f516c6e060 (patch)
tree755e41314c9ecff2684f3a30d7d0d8d427563799
parent97a588715d6c896158106d6ca732196d3fee857b (diff)
Add support for deprecating ObjC properties. Unlike GCC, we warn that the
property is deprecated, not the getter/setter if the attribute is on the property. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64644 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExpr.cpp35
-rw-r--r--test/SemaObjC/attr-deprecated.m15
2 files changed, 44 insertions, 6 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 49bba1d5b8..07079dbb7d 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1683,16 +1683,24 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
ObjCInterfaceDecl *IFace = IFTy->getDecl();
// Search for a declared property first.
- if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(&Member))
+ if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(&Member)) {
+ // Check if referencing a property with __attribute__((deprecated)).
+ DiagnoseUseOfDeprecatedDecl(PD, MemberLoc);
+
return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
- MemberLoc, BaseExpr));
+ MemberLoc, BaseExpr));
+ }
// Check protocols on qualified interfaces.
for (ObjCInterfaceType::qual_iterator I = IFTy->qual_begin(),
E = IFTy->qual_end(); I != E; ++I)
- if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member))
+ if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member)) {
+ // Check if referencing a property with __attribute__((deprecated)).
+ DiagnoseUseOfDeprecatedDecl(PD, MemberLoc);
+
return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
- MemberLoc, BaseExpr));
+ MemberLoc, BaseExpr));
+ }
// If that failed, look for an "implicit" property by seeing if the nullary
// selector is implemented.
@@ -1719,6 +1727,9 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
}
}
if (Getter) {
+ // Check if referencing a property with __attribute__((deprecated)).
+ DiagnoseUseOfDeprecatedDecl(Getter, MemberLoc);
+
// If we found a getter then this may be a valid dot-reference, we
// will look for the matching setter, in case it is needed.
IdentifierInfo *SetterName = constructSetterName(PP.getIdentifierTable(),
@@ -1742,6 +1753,11 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
}
}
+ if (Setter)
+ // Check if referencing a property with __attribute__((deprecated)).
+ DiagnoseUseOfDeprecatedDecl(Setter, MemberLoc);
+
+
// FIXME: we must check that the setter has property type.
return Owned(new (Context) ObjCKVCRefExpr(Getter, Getter->getResultType(),
Setter, MemberLoc, BaseExpr));
@@ -1756,12 +1772,19 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
// Check protocols on qualified interfaces.
for (ObjCQualifiedIdType::qual_iterator I = QIdTy->qual_begin(),
E = QIdTy->qual_end(); I != E; ++I) {
- if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member))
+ if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member)) {
+ // Check if referencing a property with __attribute__((deprecated)).
+ DiagnoseUseOfDeprecatedDecl(PD, MemberLoc);
+
return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
- MemberLoc, BaseExpr));
+ MemberLoc, BaseExpr));
+ }
// Also must look for a getter name which uses property syntax.
Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
if (ObjCMethodDecl *OMD = (*I)->getInstanceMethod(Sel)) {
+ // Check if referencing a property with __attribute__((deprecated)).
+ DiagnoseUseOfDeprecatedDecl(OMD, MemberLoc);
+
return Owned(new (Context) ObjCMessageExpr(BaseExpr, Sel,
OMD->getResultType(), OMD, OpLoc, MemberLoc, NULL, 0));
}
diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m
index 767206f88b..e9ed3819a7 100644
--- a/test/SemaObjC/attr-deprecated.m
+++ b/test/SemaObjC/attr-deprecated.m
@@ -67,3 +67,18 @@ void t4(Class c)
[c F];
}
+
+
+@interface Bar
+
+@property (assign, setter = MySetter:) int FooBar __attribute__ ((deprecated));
+- (void) MySetter : (int) value;
+@end
+
+int t5() {
+ Bar *f;
+ f.FooBar = 1; // expected-warning {{warning: 'FooBar' is deprecated}}
+ return f.FooBar; // expected-warning {{warning: 'FooBar' is deprecated}}
+}
+
+