r216753 - Objective-C. Tweak diagnosing properties that are not auto-synthesized.

Fariborz Jahanian fjahanian at apple.com
Fri Aug 29 11:31:17 PDT 2014


Author: fjahanian
Date: Fri Aug 29 13:31:16 2014
New Revision: 216753

URL: http://llvm.org/viewvc/llvm-project?rev=216753&view=rev
Log:
Objective-C. Tweak diagnosing properties that are not auto-synthesized.
Do not warn when property declared in class's protocol will be auto-synthesized
by its uper class implementation because super class has also declared this
property while this class has not. Continue to warn if current class
has declared the property also (because this declaration will not result
in a 2nd synthesis).
rdar://18152478

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/Analysis/objc_invalidation.m
    cfe/trunk/test/SemaObjC/attr-deprecated.m
    cfe/trunk/test/SemaObjC/default-synthesize-1.m
    cfe/trunk/test/SemaObjC/default-synthesize.m
    cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m
    cfe/trunk/test/SemaObjC/super-property-notation.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=216753&r1=216752&r2=216753&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug 29 13:31:16 2014
@@ -787,7 +787,8 @@ def warn_no_autosynthesis_property : War
   InGroup<ObjCNoPropertyAutoSynthesis>;
 def warn_autosynthesis_property_in_superclass : Warning<
   "auto property synthesis will not synthesize property "
-  "%0 because it will be implemented by its superclass">,
+  "%0; it will be implemented by its superclass, use @dynamic to "
+  "acknowledge intention">,
   InGroup<ObjCNoPropertyAutoSynthesis>;
 def warn_autosynthesis_property_ivar_match :Warning<
   "autosynthesized property %0 will use %select{|synthesized}1 instance variable "

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=216753&r1=216752&r2=216753&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Fri Aug 29 13:31:16 2014
@@ -1547,25 +1547,6 @@ void Sema::DefaultSynthesizeProperties(S
       if (IMPDecl->getInstanceMethod(Prop->getSetterName()))
         continue;
     }
-    // If property to be implemented in the super class, ignore.
-    if (SuperPropMap[Prop->getIdentifier()]) {
-      ObjCPropertyDecl *PropInSuperClass = SuperPropMap[Prop->getIdentifier()];
-      if ((Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) &&
-          (PropInSuperClass->getPropertyAttributes() &
-           ObjCPropertyDecl::OBJC_PR_readonly) &&
-          !IMPDecl->getInstanceMethod(Prop->getSetterName()) &&
-          !IDecl->HasUserDeclaredSetterMethod(Prop)) {
-        Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
-          << Prop->getIdentifier();
-        Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
-      }
-      else {
-        Diag(Prop->getLocation(), diag::warn_autosynthesis_property_in_superclass)
-          << Prop->getIdentifier();
-        Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
-      }
-      continue;
-    }
     if (ObjCPropertyImplDecl *PID =
         IMPDecl->FindPropertyImplIvarDecl(Prop->getIdentifier())) {
       Diag(Prop->getLocation(), diag::warn_no_autosynthesis_shared_ivar_property)
@@ -1587,7 +1568,25 @@ void Sema::DefaultSynthesizeProperties(S
       }
       continue;
     }
-
+    // If property to be implemented in the super class, ignore.
+    if (ObjCPropertyDecl *PropInSuperClass =
+          SuperPropMap[Prop->getIdentifier()]) {
+      if ((Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) &&
+          (PropInSuperClass->getPropertyAttributes() &
+           ObjCPropertyDecl::OBJC_PR_readonly) &&
+          !IMPDecl->getInstanceMethod(Prop->getSetterName()) &&
+          !IDecl->HasUserDeclaredSetterMethod(Prop)) {
+        Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
+        << Prop->getIdentifier();
+        Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
+      }
+      else {
+        Diag(Prop->getLocation(), diag::warn_autosynthesis_property_in_superclass)
+        << Prop->getIdentifier();
+        Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
+      }
+      continue;
+    }
     // We use invalid SourceLocations for the synthesized ivars since they
     // aren't really synthesized at a particular location; they just exist.
     // Saying that they are located at the @implementation isn't really going

Modified: cfe/trunk/test/Analysis/objc_invalidation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/objc_invalidation.m?rev=216753&r1=216752&r2=216753&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/objc_invalidation.m (original)
+++ cfe/trunk/test/Analysis/objc_invalidation.m Fri Aug 29 13:31:16 2014
@@ -199,7 +199,7 @@ extern void NSLog(NSString *format, ...)
 // synthesized in the parent, let the parent invalidate it.
 
 @protocol IDEBuildable <NSObject>
- at property (readonly, strong) id <Invalidation2> ObjB; // expected-warning {{auto property synthesis will not synthesize property 'ObjB'}}
+ at property (readonly, strong) id <Invalidation2> ObjB; // expected-note {{property declared here}}
 @end
 
 @interface Parent : NSObject <IDEBuildable, Invalidation2> {
@@ -231,7 +231,7 @@ extern void NSLog(NSString *format, ...)
 }
 @end
 
- at implementation Child // expected-note {{detected while default synthesizing properties in class implementation}}
+ at implementation Child // expected-warning {{auto property synthesis will not synthesize property 'ObjB' declared in protocol 'IDEBuildable'}}
 - (void)invalidate{ 
   // no-warning
 } 

Modified: cfe/trunk/test/SemaObjC/attr-deprecated.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-deprecated.m?rev=216753&r1=216752&r2=216753&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-deprecated.m (original)
+++ cfe/trunk/test/SemaObjC/attr-deprecated.m Fri Aug 29 13:31:16 2014
@@ -201,7 +201,7 @@ expected-note {{'setObject:' has been ex
 @end
 
 @interface TestDerived : TestBase
- at property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object' because it will be implemented by its superclass}}
+ at property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object'; it will be implemented by its superclass}}
 @end
 
 @interface TestUse @end

Modified: cfe/trunk/test/SemaObjC/default-synthesize-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-1.m?rev=216753&r1=216752&r2=216753&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-1.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize-1.m Fri Aug 29 13:31:16 2014
@@ -132,7 +132,7 @@
 
 @interface ZXCalendarParsedResult : ZXParsedResult
 
- at property (nonatomic, copy, readonly) NSString *description; // expected-warning {{auto property synthesis will not synthesize property 'description' because it will be implemented by its superclass}}
+ at property (nonatomic, copy, readonly) NSString *description; // expected-warning {{auto property synthesis will not synthesize property 'description'; it will be implemented by its superclass}}
 
 @end
 

Modified: cfe/trunk/test/SemaObjC/default-synthesize.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize.m?rev=216753&r1=216752&r2=216753&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize.m Fri Aug 29 13:31:16 2014
@@ -88,7 +88,7 @@
 @end
 
 @protocol TopProtocol
-  @property (readonly) id myString; // expected-warning {{auto property synthesis will not synthesize property 'myString' because it will be implemented by its superclass}}
+  @property (readonly) id myString; // expected-note {{property declared here}}
 @end
 
 @interface TopClass <TopProtocol> 
@@ -100,7 +100,7 @@
 @interface SubClass : TopClass <TopProtocol>
 @end
 
- at implementation SubClass @end  // expected-note {{detected while default synthesizing properties in class implementation}}
+ at implementation SubClass @end // expected-warning {{auto property synthesis will not synthesize property 'myString' declared in protocol 'TopProtocol'}}
 
 // rdar://7920807
 @interface C @end
@@ -138,3 +138,25 @@
  
 @implementation MyClass // expected-warning {{auto property synthesis will not synthesize property 'requiredString' declared in protocol 'MyProtocol'}}
 @end
+
+// rdar://18152478
+ at protocol NSObject @end
+ at protocol TMSourceManagerDelegate<NSObject>
+ at end
+
+ at protocol TMSourceManager <NSObject>
+ at property (nonatomic, assign) id <TMSourceManagerDelegate> delegate;
+ at end
+
+ at interface TMSourceManager
+ at property (nonatomic, assign) id <TMSourceManagerDelegate> delegate;
+ at end
+
+ at protocol TMTimeZoneManager <TMSourceManager>
+ at end
+
+ at interface TimeZoneManager : TMSourceManager <TMTimeZoneManager>
+ at end
+
+ at implementation TimeZoneManager
+ at end

Modified: cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m?rev=216753&r1=216752&r2=216753&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m (original)
+++ cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m Fri Aug 29 13:31:16 2014
@@ -5,8 +5,7 @@
 __attribute__((objc_protocol_requires_explicit_implementation))
 @protocol Protocol
 - (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}}
- at property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} \
-					 // expected-warning 2 {{auto property synthesis will not synthesize property 'theWorstOfTimes'}}
+ at property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} 
 @end
 
 // In this example, ClassA adopts the protocol.  We won't
@@ -21,8 +20,7 @@ __attribute__((objc_protocol_requires_ex
 @interface ClassB : ClassA <Protocol>
 @end
 
- at implementation ClassB // expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}} \
-		      // expected-note {{detected while default synthesizing properties in class implementation}}
+ at implementation ClassB // expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}} 
 @end
 
 @interface ClassB_Good : ClassA <Protocol>
@@ -34,7 +32,7 @@ __attribute__((objc_protocol_requires_ex
 @end
 
 @interface ClassB_AlsoGood : ClassA <Protocol>
- at property (readonly) id theWorstOfTimes; // expected-warning {{auto property synthesis will not synthesize property 'theWorstOfTimes' because it will be implemented by its superclass}}
+ at property (readonly) id theWorstOfTimes; // expected-warning {{auto property synthesis will not synthesize property 'theWorstOfTimes'; it will be implemented by its superclass}}
 @end
 
 // Default synthesis acts as if @dynamic
@@ -42,7 +40,7 @@ __attribute__((objc_protocol_requires_ex
 // it is declared in ClassA.  This is okay, since
 // the author of ClassB_AlsoGood needs explicitly
 // write @property in the @interface.
- at implementation ClassB_AlsoGood  // expected-note 2 {{detected while default synthesizing properties in class implementation}}
+ at implementation ClassB_AlsoGood  // expected-note {{detected while default synthesizing properties in class implementation}}
 - (void) theBestOfTimes {}
 @end
 

Modified: cfe/trunk/test/SemaObjC/super-property-notation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super-property-notation.m?rev=216753&r1=216752&r2=216753&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/super-property-notation.m (original)
+++ cfe/trunk/test/SemaObjC/super-property-notation.m Fri Aug 29 13:31:16 2014
@@ -41,7 +41,7 @@ __attribute__((objc_root_class)) @interf
 @end
 
 @interface ClassDerived : ClassBase 
- at property (nonatomic, retain) ClassDerived * foo; // expected-warning {{auto property synthesis will not synthesize property 'foo' because it will be implemented by its superclass}}
+ at property (nonatomic, retain) ClassDerived * foo; // expected-warning {{auto property synthesis will not synthesize property 'foo'; it will be implemented by its superclass}}
 @end
 
 @implementation ClassDerived // expected-note {{detected while default synthesizing properties in class implementation}}





More information about the cfe-commits mailing list