In gcc/objc/: 2010-12-28 Nicola Pero <nicola.pero@meta-innovation.com>
authorNicola Pero <nicola.pero@meta-innovation.com>
Tue, 28 Dec 2010 12:39:29 +0000 (12:39 +0000)
committerNicola Pero <nicola@gcc.gnu.org>
Tue, 28 Dec 2010 12:39:29 +0000 (12:39 +0000)
In gcc/objc/:
2010-12-28  Nicola Pero  <nicola.pero@meta-innovation.com>

* objc-act.c (objc_start_category_interface): Produce an error if
a class extension is found after the class @implementation.

In gcc/testsuite/:
2010-12-28  Nicola Pero  <nicola.pero@meta-innovation.com>

* objc.dg/class-extension-4.m: New.
* obj-c++.dg/class-extension-4.mm: New.

From-SVN: r168294

gcc/objc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/obj-c++.dg/class-extension-4.mm [new file with mode: 0644]
gcc/testsuite/objc.dg/class-extension-4.m [new file with mode: 0644]

index 16b774d551260190d469d523df9a59f65b646379..c7efb54cb9395d5813cf2323417a5a84375426d2 100644 (file)
@@ -1,3 +1,8 @@
+2010-12-28  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * objc-act.c (objc_start_category_interface): Produce an error if
+       a class extension is found after the class @implementation.
+
 2010-12-28  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        PR objc/47073
index ba6c8108814ce158e83e169a9f4ae46fe6084938..1117967e71df81240b49dc7c791802881cf96e03 100644 (file)
@@ -763,6 +763,23 @@ objc_start_category_interface (tree klass, tree categ,
     {
       if (flag_objc1_only)
        error_at (input_location, "class extensions are not available in Objective-C 1.0");
+      else
+       {
+         /* Iterate over all the classes and categories implemented
+            up to now in this compilation unit.  */
+         struct imp_entry *t;
+
+         for (t = imp_list; t; t = t->next)
+           {
+             /* If we find a class @implementation with the same name
+                as the one we are extending, produce an error.  */
+           if (TREE_CODE (t->imp_context) == CLASS_IMPLEMENTATION_TYPE
+               && IDENTIFIER_POINTER (CLASS_NAME (t->imp_context)) == IDENTIFIER_POINTER (klass))
+             error_at (input_location, 
+                       "class extension for class %qE declared after its %<@implementation%>",
+                       klass);
+           }
+       }
     }
   objc_interface_context
     = start_class (CATEGORY_INTERFACE_TYPE, klass, categ, protos, NULL_TREE);
index 563fc03d04861c5336dbac9105e59c421ad9459b..ac141bd73e9eda4f5db5b739ae397286d257441f 100644 (file)
@@ -1,3 +1,8 @@
+2010-12-28  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * objc.dg/class-extension-4.m: New.
+       * obj-c++.dg/class-extension-4.mm: New.
+
 2010-12-28  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        PR objc/47073
diff --git a/gcc/testsuite/obj-c++.dg/class-extension-4.mm b/gcc/testsuite/obj-c++.dg/class-extension-4.mm
new file mode 100644 (file)
index 0000000..9e19aa7
--- /dev/null
@@ -0,0 +1,19 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010.  */
+/* { dg-do compile } */
+
+/* This test tests you can not declare a class extension after the class @implementation.  */
+
+#include <objc/objc.h>
+
+@interface MyObject
+{
+  Class isa;
+}
+@end
+
+@implementation MyObject
+@end
+
+@interface MyObject () /* { dg-error "class extension for class .MyObject. declared after its ..implementation." } */
+- (void) test;
+@end
diff --git a/gcc/testsuite/objc.dg/class-extension-4.m b/gcc/testsuite/objc.dg/class-extension-4.m
new file mode 100644 (file)
index 0000000..692a0fc
--- /dev/null
@@ -0,0 +1,19 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010.  */
+/* { dg-do compile } */
+
+/* This test tests you can not declare a class extension after the class @implementation.  */
+
+#include <objc/objc.h>
+
+@interface MyObject
+{
+  Class isa;
+}
+@end
+
+@implementation MyObject
+@end
+
+@interface MyObject ()
+- (void) test; /* { dg-error "class extension for class .MyObject. declared after its ..implementation." } */
+@end