]> granicus.if.org Git - clang/commitdiff
Objective-C. Tweak diagnosing properties that are not auto-synthesized.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 29 Aug 2014 18:31:16 +0000 (18:31 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 29 Aug 2014 18:31:16 +0000 (18:31 +0000)
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

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

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

index 8b25adb337732bf11ad7cb2b1b0b19ef2e3fdb58..1cd372b5f6e2aa58a9cfeb4a6832a011fd0717d4 100644 (file)
@@ -787,7 +787,8 @@ def warn_no_autosynthesis_property : Warning<
   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 "
index 0963c1ee3da763fee7d43e49aed539e0d1fad6e2..ba698c1b3c3bd6aa19820ffcfaf3adcc114f47eb 100644 (file)
@@ -1547,25 +1547,6 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl,
       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(Scope *S, ObjCImplDecl* IMPDecl,
       }
       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
index 9ac98284b4eb897ee75466dae4638e34b85a25c1..0d97b2952deebd36bcf472f09d241233f86d707b 100644 (file)
@@ -199,7 +199,7 @@ extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1,
 // synthesized in the parent, let the parent invalidate it.
 
 @protocol IDEBuildable <NSObject>
-@property (readonly, strong) id <Invalidation2> ObjB; // expected-warning {{auto property synthesis will not synthesize property 'ObjB'}}
+@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, ...) __attribute__((format(__NSString__, 1,
 }
 @end
 
-@implementation Child // expected-note {{detected while default synthesizing properties in class implementation}}
+@implementation Child // expected-warning {{auto property synthesis will not synthesize property 'ObjB' declared in protocol 'IDEBuildable'}}
 - (void)invalidate{ 
   // no-warning
 } 
index 9c33b5bade9500e5dfc06c54902cca037b1ce37d..3e9157d0961fa3717610601f6818e61019cabe57 100644 (file)
@@ -201,7 +201,7 @@ expected-note {{'setObject:' has been explicitly marked deprecated here}}
 @end
 
 @interface TestDerived : TestBase
-@property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object' because it will be implemented by its superclass}}
+@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
index 3ca34e027cbb4561144d434ee00389904a9d0309..2a34a65a957e86292adfde7948d9e8fcdb877513 100644 (file)
 
 @interface ZXCalendarParsedResult : ZXParsedResult
 
-@property (nonatomic, copy, readonly) NSString *description; // expected-warning {{auto property synthesis will not synthesize property 'description' because it will be implemented by its superclass}}
+@property (nonatomic, copy, readonly) NSString *description; // expected-warning {{auto property synthesis will not synthesize property 'description'; it will be implemented by its superclass}}
 
 @end
 
index 4865668af38b05d855ee4ae9d7d129d61964d72f..d0d3085ba7049673300436e9bdb438f76bc6ff6c 100644 (file)
@@ -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> 
 @interface SubClass : TopClass <TopProtocol>
 @end
 
-@implementation SubClass @end  // expected-note {{detected while default synthesizing properties in class implementation}}
+@implementation SubClass @end // expected-warning {{auto property synthesis will not synthesize property 'myString' declared in protocol 'TopProtocol'}}
 
 // rdar://7920807
 @interface C @end
  
 @implementation MyClass // expected-warning {{auto property synthesis will not synthesize property 'requiredString' declared in protocol 'MyProtocol'}}
 @end
+
+// rdar://18152478
+@protocol NSObject @end
+@protocol TMSourceManagerDelegate<NSObject>
+@end
+
+@protocol TMSourceManager <NSObject>
+@property (nonatomic, assign) id <TMSourceManagerDelegate> delegate;
+@end
+
+@interface TMSourceManager
+@property (nonatomic, assign) id <TMSourceManagerDelegate> delegate;
+@end
+
+@protocol TMTimeZoneManager <TMSourceManager>
+@end
+
+@interface TimeZoneManager : TMSourceManager <TMTimeZoneManager>
+@end
+
+@implementation TimeZoneManager
+@end
index 855d2e96ef659b47e9e9bcbc5270bd183d8e9c3e..8415154ab1d894c15141372ea45f0c95e7d1ac89 100644 (file)
@@ -5,8 +5,7 @@
 __attribute__((objc_protocol_requires_explicit_implementation))
 @protocol Protocol
 - (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}}
-@property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} \
-                                        // expected-warning 2 {{auto property synthesis will not synthesize property 'theWorstOfTimes'}}
+@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_explicit_implementation))
 @interface ClassB : ClassA <Protocol>
 @end
 
-@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}}
+@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_explicit_implementation))
 @end
 
 @interface ClassB_AlsoGood : ClassA <Protocol>
-@property (readonly) id theWorstOfTimes; // expected-warning {{auto property synthesis will not synthesize property 'theWorstOfTimes' because it will be implemented by its superclass}}
+@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_explicit_implementation))
 // it is declared in ClassA.  This is okay, since
 // the author of ClassB_AlsoGood needs explicitly
 // write @property in the @interface.
-@implementation ClassB_AlsoGood  // expected-note {{detected while default synthesizing properties in class implementation}}
+@implementation ClassB_AlsoGood  // expected-note {{detected while default synthesizing properties in class implementation}}
 - (void) theBestOfTimes {}
 @end
 
index 7cefe09b1e7ae4d7c1ba24b818c488b08064f2dc..62ff93cb2b052287c3198f7b097e275b4e20737e 100644 (file)
@@ -41,7 +41,7 @@ __attribute__((objc_root_class)) @interface ClassBase
 @end
 
 @interface ClassDerived : ClassBase 
-@property (nonatomic, retain) ClassDerived * foo; // expected-warning {{auto property synthesis will not synthesize property 'foo' because it will be implemented by its superclass}}
+@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}}