[Sema][ObjC] Do not DiagnoseUseOfDecl in LookupMemberExpr

Summary:
Remove the call to DiagnoseUseOfDecl in LookupMemberExpr because:
1. LookupMemberExpr eagerly lookup both getter and setter, reguardless
if they are used or not. It causes wrong diagnostics if you are only
using getter.
2. LookupMemberExpr only diagnoses getter, but not setter.
3. ObjCPropertyOpBuilder already DiagnoseUseOfDecl when building getter
and setter. Doing it again in LookupMemberExpr causes duplicated
diagnostics.

rdar://problem/38479756

Reviewers: erik.pilkington, arphaman, doug.gregor

Reviewed By: arphaman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D47280

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333148 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Steven Wu 2018-05-24 01:01:43 +00:00
parent 38a4b05cf0
commit 177caf42f2
2 changed files with 11 additions and 3 deletions

View File

@ -1490,9 +1490,6 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
}
if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(PMDecl)) {
// Check the use of this method.
if (S.DiagnoseUseOfDecl(OMD, MemberLoc))
return ExprError();
Selector SetterSel =
SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(),
S.PP.getSelectorTable(),

View File

@ -167,3 +167,14 @@ void testUserAccessorAttributes(Foo *foo) {
foo.x = foo.x; // expected-error {{property access is using 'x' method which is unavailable}} \
// expected-warning {{property access is using 'setX:' method which is deprecated}}
}
// test implicit property does not emit duplicated warning.
@protocol Foo
- (int)size __attribute__((availability(ios,deprecated=3.0))); // expected-note {{'size' has been explicitly marked deprecated here}}
- (void)setSize: (int)x __attribute__((availability(ios,deprecated=2.0))); // expected-note {{'setSize:' has been explicitly marked deprecated here}}
@end
void testImplicitProperty(id<Foo> object) {
object.size = object.size; // expected-warning {{'size' is deprecated: first deprecated in iOS 3.0}} \
// expected-warning {{'setSize:' is deprecated: first deprecated in iOS 2.0}}
}