r216610 - Objective-C. Change to method lookup rules to look
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 27 13:34:29 PDT 2014
Author: fjahanian
Date: Wed Aug 27 15:34:29 2014
New Revision: 216610
URL: http://llvm.org/viewvc/llvm-project?rev=216610&view=rev
Log:
Objective-C. Change to method lookup rules to look
into primary class's named categories before looking
into their protocols. This is because categories are
part of the public interface and , just as primary class,
preference should be given to them before class
(and category) protocols. // rdar://18013929
Added:
cfe/trunk/test/SemaObjC/warn-category-method-deprecated.m
Modified:
cfe/trunk/lib/AST/DeclObjC.cpp
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=216610&r1=216609&r2=216610&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Wed Aug 27 15:34:29 2014
@@ -558,36 +558,39 @@ ObjCMethodDecl *ObjCInterfaceDecl::looku
LoadExternalDefinition();
while (ClassDecl) {
+ // 1. Look through primary class.
if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
return MethodDecl;
-
- // Didn't find one yet - look through protocols.
- for (const auto *I : ClassDecl->protocols())
- if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
- return MethodDecl;
- // Didn't find one yet - now look through categories.
- for (const auto *Cat : ClassDecl->visible_categories()) {
+ // 2. Didn't find one yet - now look through categories.
+ for (const auto *Cat : ClassDecl->visible_categories())
if ((MethodDecl = Cat->getMethod(Sel, isInstance)))
if (C != Cat || !MethodDecl->isImplicit())
return MethodDecl;
- if (!shallowCategoryLookup) {
+ // 3. Didn't find one yet - look through primary class's protocols.
+ for (const auto *I : ClassDecl->protocols())
+ if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
+ return MethodDecl;
+
+ // 4. Didn't find one yet - now look through categories' protocols
+ if (!shallowCategoryLookup)
+ for (const auto *Cat : ClassDecl->visible_categories()) {
// Didn't find one yet - look through protocols.
const ObjCList<ObjCProtocolDecl> &Protocols =
- Cat->getReferencedProtocols();
+ Cat->getReferencedProtocols();
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
E = Protocols.end(); I != E; ++I)
if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
if (C != Cat || !MethodDecl->isImplicit())
return MethodDecl;
}
- }
-
+
+
if (!followSuper)
return nullptr;
- // Get the super class (if any).
+ // 5. Get to the super class (if any).
ClassDecl = ClassDecl->getSuperClass();
}
return nullptr;
Added: cfe/trunk/test/SemaObjC/warn-category-method-deprecated.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-category-method-deprecated.m?rev=216610&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-category-method-deprecated.m (added)
+++ cfe/trunk/test/SemaObjC/warn-category-method-deprecated.m Wed Aug 27 15:34:29 2014
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
+// rdar://18013929
+
+ at protocol P
+- (void)meth;
+ at end
+
+ at interface I <P>
+ at end
+
+ at interface I(cat)
+- (void)meth __attribute__((deprecated)); // expected-note {{'meth' has been explicitly marked deprecated here}}
+ at end
+
+void foo(I *i) {
+ [i meth]; // expected-warning {{'meth' is deprecated}}
+}
More information about the cfe-commits
mailing list