[cfe-commits] r146626 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaObjCProperty.cpp test/SemaObjC/default-synthesize.m

Fariborz Jahanian fjahanian at apple.com
Wed Dec 14 17:03:19 PST 2011


Author: fjahanian
Date: Wed Dec 14 19:03:18 2011
New Revision: 146626

URL: http://llvm.org/viewvc/llvm-project?rev=146626&view=rev
Log:
objc: do not auto synthesize properties declared in
protocols; with a warning. // rdar://10567333

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/default-synthesize.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=146626&r1=146625&r2=146626&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec 14 19:03:18 2011
@@ -528,6 +528,10 @@
   "property's synthesized getter follows Cocoa naming"
   " convention for returning 'owned' objects">,
   InGroup<DiagGroup<"objc-property-matches-cocoa-ownership-rule">>;
+def warn_auto_synthesizing_protocol_property :Warning<
+  "auto property synthesis will not synthesize property"
+  " declared in a protocol">,
+  InGroup<DiagGroup<"objc-protocol-property-synthesis">>;
 def warn_property_getter_owning_mismatch : Warning<
   "property declared as returning non-retained objects"
   "; getter returning retained objects">;

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=146626&r1=146625&r2=146626&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Wed Dec 14 19:03:18 2011
@@ -1328,7 +1328,13 @@
       if (IMPDecl->getInstanceMethod(Prop->getSetterName()))
         continue;
     }
-
+    if (isa<ObjCProtocolDecl>(Prop->getDeclContext())) {
+      // We won't auto-synthesize properties declared in protocols.
+      Diag(IMPDecl->getLocation(), 
+           diag::warn_auto_synthesizing_protocol_property);
+      Diag(Prop->getLocation(), diag::note_property_declare);
+      continue;
+    }
 
     // We use invalid SourceLocations for the synthesized ivars since they
     // aren't really synthesized at a particular location; they just exist.

Modified: cfe/trunk/test/SemaObjC/default-synthesize.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize.m?rev=146626&r1=146625&r2=146626&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize.m Wed Dec 14 19:03:18 2011
@@ -115,3 +115,16 @@
 @synthesize PROP=IVAR;
 @end
 
+// rdar://10567333
+ at protocol MyProtocol 
+ at property (nonatomic, strong) NSString *requiredString; // expected-note {{property declared here}}
+
+ at optional
+ at property (nonatomic, strong) NSString *optionalString;
+ at end
+ 
+ at interface MyClass <MyProtocol> 
+ at end
+ 
+ at implementation MyClass // expected-warning {{auto property synthesis will not synthesize property declared in a protocol}}
+ at end





More information about the cfe-commits mailing list