Author: kremenek
Date: Tue Mar 23 14:02:22 2010
New Revision: 99312

URL: http://llvm.org/viewvc/llvm-project?rev=99312&view=rev
Log:
Improve diagnostic for @property/ivar type mismatch by including the types of 
the
ivar and @property respectively.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/property-ivar-mismatch.m
    cfe/trunk/test/SemaObjC/property.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=99312&r1=99311&r2=99312&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 23 14:02:22 
2010
@@ -348,7 +348,7 @@
   " (need to declare %0 explicitly)">;
 
 def error_property_ivar_type : Error<
-  "type of property %0 does not match type of ivar %1">;
+  "type of property %0 (%1) does not match type of ivar %2 (%3)">;
 def error_ivar_in_superclass_use : Error<
   "property %0 attempting to use ivar %1 declared in super class %2">;
 def error_weak_property : Error<
@@ -530,6 +530,7 @@
   "of type %1">;
 
 def note_field_decl : Note<"member is declared here">;
+def note_ivar_decl : Note<"ivar is declared here">;
 def note_bitfield_decl : Note<"bit-field is declared here">;
 def note_previous_decl : Note<"%0 declared here">;
 def note_member_synthesized_at : Note<

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=99312&r1=99311&r2=99312&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue Mar 23 14:02:22 2010
@@ -383,7 +383,9 @@
     if (PropType != IvarType) {
       if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) {
         Diag(PropertyLoc, diag::error_property_ivar_type)
-        << property->getDeclName() << Ivar->getDeclName();
+          << property->getDeclName() << PropType
+          << Ivar->getDeclName() << IvarType;
+        Diag(Ivar->getLocation(), diag::note_ivar_decl);
         // Note! I deliberately want it to fall thru so, we have a
         // a property implementation and to avoid future warnings.
       }
@@ -396,7 +398,9 @@
       if (lhsType != rhsType &&
           lhsType->isArithmeticType()) {
         Diag(PropertyLoc, diag::error_property_ivar_type)
-        << property->getDeclName() << Ivar->getDeclName();
+          << property->getDeclName() << PropType
+          << Ivar->getDeclName() << IvarType;
+        Diag(Ivar->getLocation(), diag::note_ivar_decl);
         // Fall thru - see previous comment
       }
       // __weak is explicit. So it works on Canonical type.

Modified: cfe/trunk/test/SemaObjC/property-ivar-mismatch.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-ivar-mismatch.m?rev=99312&r1=99311&r2=99312&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-ivar-mismatch.m (original)
+++ cfe/trunk/test/SemaObjC/property-ivar-mismatch.m Tue Mar 23 14:02:22 2010
@@ -3,12 +3,12 @@
 
 @interface Test4 
 {
-   char ivar;
+   char ivar; // expected-note{{ivar is declared here}}
 }
 @property int prop;
 @end
 
 @implementation Test4
-...@synthesize prop = ivar;  // expected-error {{type of property 'prop' does 
not match type of ivar 'ivar'}}
+...@synthesize prop = ivar;  // expected-error {{type of property 'prop' 
('int') does not match type of ivar 'ivar' ('char')}}
 @end
 

Modified: cfe/trunk/test/SemaObjC/property.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property.m?rev=99312&r1=99311&r2=99312&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property.m (original)
+++ cfe/trunk/test/SemaObjC/property.m Tue Mar 23 14:02:22 2010
@@ -2,7 +2,7 @@
 
 @interface I 
 {
-       int IVAR;
+       int IVAR; // expected-note{{ivar is declared here}}
        int name;
 }
 @property int d1;
@@ -19,7 +19,7 @@
 @synthesize d1;                // expected-error {{synthesized property 'd1' 
must either be named the same as}}
 @dynamic    bad;       // expected-error {{property implementation must have 
its declaration in interface 'I'}}
 @synthesize prop_id;   // expected-error {{synthesized property 'prop_id' must 
either be named the same}}  // expected-note {{previous declaration is here}}
-...@synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' 
does not match type of ivar 'IVAR'}} // expected-error {{property 'prop_id' is 
already implemented}}
+...@synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' 
('id') does not match type of ivar 'IVAR' ('int')}} // expected-error 
{{property 'prop_id' is already implemented}}
 @synthesize name;      // OK! property with same name as an accessible ivar of 
same name
 @end
 


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to