[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

llvm-svn: 333148
This commit is contained in:
Steven Wu 2018-05-24 01:01:43 +00:00
parent b0b67b07f5
commit 49d7c2f597
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}}
}