]> granicus.if.org Git - clang/commitdiff
objc: improved diagnostic when property autosynthesis may cause
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 20 Jun 2012 17:18:31 +0000 (17:18 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 20 Jun 2012 17:18:31 +0000 (17:18 +0000)
change in behavior. // rdar://11671080

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/default-synthesize-2.m

index 60b52dfa6b007290235dcfeecb8a040985374143..b2035eaac2b0a1c5b728f32b108b4900f7ddbdb7 100644 (file)
@@ -631,7 +631,8 @@ def warn_auto_synthesizing_protocol_property :Warning<
   " declared in a protocol">,
   InGroup<DiagGroup<"objc-protocol-property-synthesis">>;
 def warn_autosynthesis_property_ivar_match :Warning<
-  "auto autosynthesized property has same name as an existing ivar">,
+  "autosynthesized property %0 will use %select{|synthesized}1 instance variable "
+  "%2, not existing instance variable %3">,
   InGroup<DiagGroup<"objc-autosynthesis-property-ivar-name-match">>;
 def warn_missing_explicit_synthesis : Warning <
   "auto property synthesis is synthesizing property not explicitly synthesized">,
index 71112f7701e741fcab4b55d697c660e6901308fc..95fbde39af0cbbabae6b4d4a74d145bcf19fc21b 100644 (file)
@@ -753,24 +753,26 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
           Context.getObjCGCQualType(PropertyIvarType, Qualifiers::Weak);
       }
     }
-
-    if (!Ivar) {
-      if (AtLoc.isInvalid()) {
-        // Check when default synthesizing a property that there is 
-        // an ivar matching property name and issue warning; since this
-        // is the most common case of not using an ivar used for backing
-        // property in non-default synthesis case.
-        ObjCInterfaceDecl *ClassDeclared=0;
-        ObjCIvarDecl *originalIvar = 
-          IDecl->lookupInstanceVariable(property->getIdentifier(), 
-                                        ClassDeclared);
-        if (originalIvar) {
-          Diag(PropertyDiagLoc, 
-               diag::warn_autosynthesis_property_ivar_match);
-          Diag(property->getLocation(), diag::note_property_declare);
-          Diag(originalIvar->getLocation(), diag::note_ivar_decl);
-        }
+    if (AtLoc.isInvalid()) {
+      // Check when default synthesizing a property that there is 
+      // an ivar matching property name and issue warning; since this
+      // is the most common case of not using an ivar used for backing
+      // property in non-default synthesis case.
+      ObjCInterfaceDecl *ClassDeclared=0;
+      ObjCIvarDecl *originalIvar = 
+      IDecl->lookupInstanceVariable(property->getIdentifier(), 
+                                    ClassDeclared);
+      if (originalIvar) {
+        Diag(PropertyDiagLoc, 
+             diag::warn_autosynthesis_property_ivar_match)
+        << property->getName() << (Ivar == 0) << PropertyIvar->getName() 
+        << originalIvar->getName();
+        Diag(property->getLocation(), diag::note_property_declare);
+        Diag(originalIvar->getLocation(), diag::note_ivar_decl);
       }
+    }
+    
+    if (!Ivar) {
       // In ARC, give the ivar a lifetime qualifier based on the
       // property attributes.
       if (getLangOpts().ObjCAutoRefCount &&
index eeeab5f5c469edb3ddd099a53788a9c89871deda..ec298f5bf5a142c42b7652be198de5afeef5bcaf 100644 (file)
@@ -47,7 +47,7 @@
 @end
 
 // rdar://11671080
-@implementation Test3 // expected-warning {{auto autosynthesized property has same name as an existing ivar}}
+@implementation Test3 // expected-warning {{autosynthesized property uid will use synthesized instance variable _uid, not existing instance variable uid}}
 // Oops, forgot to write @synthesize! will be default synthesized
 - (void) myMethod { 
    self.uid = 0; // Use of the “setter” 
@@ -115,3 +115,15 @@ int* _object;
 } 
 @end
 
+// rdar://11671080
+@interface Test8
+{
+  id _y;
+  id y; // expected-note {{ivar is declared here}}
+}
+@property(copy) id y; // expected-note {{property declared here}}
+@end
+
+
+@implementation Test8 @end // expected-warning {{autosynthesized property y will use  instance variable _y, not existing instance variable y}}
+