]> granicus.if.org Git - clang/commitdiff
Warn on weak properties declared in protocols as well.
authorJordan Rose <jordan_rose@apple.com>
Thu, 28 Jun 2012 16:39:28 +0000 (16:39 +0000)
committerJordan Rose <jordan_rose@apple.com>
Thu, 28 Jun 2012 16:39:28 +0000 (16:39 +0000)
Previously this caused a crash, since protocols are not interfaces.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159357 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprObjC.cpp
test/SemaObjC/weak-receiver-warn.m

index 598ad0b27ae390116dcd7b8c150f0972eafc9d41..a3fe7d3bbefe34a54702bf247083904cff63b883 100644 (file)
@@ -1379,10 +1379,12 @@ static void DiagnoseARCUseOfWeakReceiver(Sema &S, Expr *Receiver) {
     ObjCMethodDecl *Method = ME->getMethodDecl();
     if (Method && Method->isSynthesized()) {
       Selector Sel = Method->getSelector();
-      if (Sel.getNumArgs() == 0)
+      if (Sel.getNumArgs() == 0) {
+        const DeclContext *Container = Method->getDeclContext();
         PDecl = 
-          S.LookupPropertyDecl(Method->getClassInterface(), 
+          S.LookupPropertyDecl(cast<ObjCContainerDecl>(Container),
                                Sel.getIdentifierInfoForSlot(0));
+      }
       if (PDecl)
         T = PDecl->getType();
     }
index 56d9bc10f9797699dd28f9924a739c1c4aa730e0..e6f8eaba8c5068ef3c19867b03db1414f52f720f 100644 (file)
@@ -66,3 +66,15 @@ void test0(Test0 *x) {
 }
 
 @end
+
+
+// Weak properties on protocols can be synthesized by an adopting class.
+@protocol MyProtocol
+@property (weak) id object; // expected-note 2 {{property declared here}}
+@end
+
+void testProtocol(id <MyProtocol> input) {
+  [[input object] Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
+  [input.object Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
+}
+