Author: kremenek
Date: Thu Oct 21 13:49:42 2010
New Revision: 117045

URL: http://llvm.org/viewvc/llvm-project?rev=117045&view=rev
Log:
Tweak diagnostics for redeclaration of a @property in a class extension where 
the redelcaration and original
declaration have the 'readwrite' attribute.  This is a common case, and we can 
issue a more lucid diagnostic.

Fixes <rdar://problem/7629420>.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/continuation-class-err.m
    cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=117045&r1=117044&r2=117045&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct 21 13:49:42 
2010
@@ -365,8 +365,12 @@
   "writable atomic property %0 cannot pair a synthesized setter/getter "
   "with a user defined setter/getter">;
 def err_use_continuation_class : Error<
-  "illegal declaration of property in continuation class %0"
-  ": attribute must be readwrite, while its primary must be readonly">;
+  "illegal redeclaration of property in continuation class %0"
+  " (attribute must be 'readwrite', while its primary must be 'readonly')">;
+def err_use_continuation_class_redeclaration_readwrite : Error<
+  "illegal redeclaration of 'readwrite' property in continuation class %0"
+  " (perhaps you intended this to be a 'readwrite' redeclaration of a "
+  "'readonly' public property?)">;
 def err_continuation_class : Error<"continuation class has no primary class">;
 def err_property_type : Error<"property cannot have array or function type 
%0">;
 def error_missing_property_context : Error<

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=117045&r1=117044&r2=117045&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Thu Oct 21 13:49:42 2010
@@ -187,7 +187,16 @@
       PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
     PIDecl->setSetterName(SetterSel);
   } else {
-    Diag(AtLoc, diag::err_use_continuation_class)
+    // Tailor the diagnostics for the common case where a readwrite
+    // property is declared both in the @interface and the continuation.
+    // This is a common error where the user often intended the original
+    // declaration to be readonly.
+    unsigned diag =
+      (Attributes & ObjCDeclSpec::DQ_PR_readwrite) &&
+      (PIkind & ObjCPropertyDecl::OBJC_PR_readwrite)
+      ? diag::err_use_continuation_class_redeclaration_readwrite
+      : diag::err_use_continuation_class;
+    Diag(AtLoc, diag)
       << CCPrimary->getDeclName();
     Diag(PIDecl->getLocation(), diag::note_property_declare);
   }

Modified: cfe/trunk/test/SemaObjC/continuation-class-err.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/continuation-class-err.m?rev=117045&r1=117044&r2=117045&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/continuation-class-err.m (original)
+++ cfe/trunk/test/SemaObjC/continuation-class-err.m Thu Oct 21 13:49:42 2010
@@ -12,7 +12,7 @@
 
 @interface ReadOnly ()
 @property(readwrite, copy) id object;  // expected-warning {{property 
attribute in continuation class does not match the primary class}}
-...@property(readonly) id object1; // expected-error {{illegal declaration of 
property in continuation class 'ReadOnly': attribute must be}}
+...@property(readonly) id object1; // expected-error {{illegal redeclaration 
of property in continuation class 'ReadOnly' (attribute must be 'readwrite', 
while its primary must be 'readonly')}}
 @property (readwrite, assign) int indentLevel; // OK. assign the the default 
in any case.
 @end
 
@@ -31,8 +31,8 @@
 @end
 
 @interface Bar ()
-...@property (copy) id foo;    // expected-error {{illegal declaration of 
property in continuation class 'Bar': attribute must be}}
-...@property (copy) id fee;    // expected-error {{illegal declaration of 
property in continuation class 'Bar': attribute must be}}
+...@property (copy) id foo; // expected-error {{illegal redeclaration of 
property in continuation class 'Bar' (attribute must be 'readwrite', while its 
primary must be 'readonly')}}
+...@property (copy) id fee; // expected-error {{illegal redeclaration of 
property in continuation class 'Bar' (attribute must be 'readwrite', while its 
primary must be 'readonly')}}
 @end
 
 @implementation Bar

Modified: cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m?rev=117045&r1=117044&r2=117045&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m (original)
+++ cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m Thu Oct 21 
13:49:42 2010
@@ -2,20 +2,22 @@
 
 @interface Foo 
 @property (readonly) char foo; // expected-note {{property declared here}}
+...@property (readwrite) char bar; // expected-note {{property declared here}}
 @end
 
 @interface Foo ()
 @property (readwrite) char foo; // OK 
 @property (readwrite) char NewProperty; // expected-note 2 {{property declared 
here}} 
+...@property (readwrite) char bar; // expected-error{{illegal redeclaration of 
'readwrite' property in continuation class 'Foo' (perhaps you intended this to 
be a 'readwrite' redeclaration of a 'readonly' public property?)}}
 @end
 
 @interface Foo ()
 @property (readwrite) char foo;        //  OK again, make primary property 
readwrite for 2nd time!
-...@property (readwrite) char NewProperty; // expected-error {{illegal 
declaration of property in continuation class 'Foo': attribute must be 
readwrite, while its primary must be readonly}}
+...@property (readwrite) char NewProperty; // expected-error {{redeclaration 
of property in continuation class 'Foo' (attribute must be 'readwrite', while 
its primary must be 'readonly')}}
 @end
 
 @interface Foo ()
-...@property (readonly) char foo;      // expected-error {{illegal declaration 
of property in continuation class 'Foo': attribute must be readwrite, while its 
primary must be readonly}}
-...@property (readwrite) char NewProperty; // expected-error {{illegal 
declaration of property in continuation class 'Foo': attribute must be 
readwrite, while its primary must be readonly}}
+...@property (readonly) char foo; // expected-error {{redeclaration of 
property in continuation class 'Foo' (attribute must be 'readwrite', while its 
primary must be 'readonly')}}
+...@property (readwrite) char NewProperty; // expected-error {{redeclaration 
of property in continuation class 'Foo' (attribute must be 'readwrite', while 
its primary must be 'readonly')}}
 @end
 


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

Reply via email to