diff options
-rw-r--r-- | gcc/objc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/class-extension-4.mm | 19 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/class-extension-4.m | 19 |
5 files changed, 65 insertions, 0 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 16b774d..c7efb54 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,5 +1,10 @@ 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 * objc-act.c (encode_method_prototype): Fixed both location and format string of error "type %qT does not have a known size". diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index ba6c810..1117967 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 563fc03..ac141bd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 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 * objc.dg/incomplete-type-1.m: New test. 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 index 0000000..9e19aa7 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/class-extension-4.mm @@ -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 index 0000000..692a0fc --- /dev/null +++ b/gcc/testsuite/objc.dg/class-extension-4.m @@ -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 |