[cfe-commits] r85813 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/property-category-4.m

Fariborz Jahanian fjahanian at apple.com
Mon Nov 2 10:45:37 PST 2009


Author: fjahanian
Date: Mon Nov  2 12:45:36 2009
New Revision: 85813

URL: http://llvm.org/viewvc/llvm-project?rev=85813&view=rev
Log:
Diagnose implementation of a property declared in a category
in its class implementation instead of crashing. Fixes radar 7350345.


Added:
    cfe/trunk/test/SemaObjC/property-category-4.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=85813&r1=85812&r2=85813&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Nov  2 12:45:36 2009
@@ -271,6 +271,11 @@
   "missing context for property implementation declaration">;
 def error_bad_property_decl : Error<
   "property implementation must have its declaration in interface %0">;
+def error_category_property : Error<
+  "property declared in category %0 cannot be implemented in "
+  "class implementation">;
+def note_category_property : Note<
+  "property declared here">;
 def error_synthesize_category_decl : Error<
   "@synthesize not allowed in a category's implementation">;
 def error_missing_property_interface : Error<

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=85813&r1=85812&r2=85813&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Nov  2 12:45:36 2009
@@ -2047,6 +2047,14 @@
       Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName();
       return DeclPtrTy();
     }
+    if (const ObjCCategoryDecl *CD = 
+        dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
+      if (CD->getIdentifier()) {
+        Diag(PropertyLoc, diag::error_category_property) << CD->getDeclName();
+        Diag(property->getLocation(), diag::note_category_property);
+        return DeclPtrTy();
+      }
+    }
   } else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
     if (Synthesize) {
       Diag(AtLoc, diag::error_synthesize_category_decl);

Added: cfe/trunk/test/SemaObjC/property-category-4.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-category-4.m?rev=85813&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/property-category-4.m (added)
+++ cfe/trunk/test/SemaObjC/property-category-4.m Mon Nov  2 12:45:36 2009
@@ -0,0 +1,18 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+ at interface IDELogNavigator
+{
+  id selectedObjects;
+}
+ at end
+
+ at interface IDELogNavigator (CAT)
+  @property (readwrite, retain) id selectedObjects; // expected-note {{property declared here}}
+  @property (readwrite, retain) id d_selectedObjects; // expected-note {{property declared here}}
+ at end
+
+ at implementation IDELogNavigator 
+ at synthesize selectedObjects = _selectedObjects; // expected-error {{property declared in category 'CAT' cannot be implemented in class implementation}}
+ at dynamic d_selectedObjects; // expected-error {{property declared in category 'CAT' cannot be implemented in class implementation}}
+ at end
+





More information about the cfe-commits mailing list