From 35bce82a804f8637741ebb6fac3fe452131c987d Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Tue, 28 Dec 2010 12:39:29 +0000 Subject: [PATCH] In gcc/objc/: 2010-12-28 Nicola Pero In gcc/objc/: 2010-12-28 Nicola Pero * 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 * objc.dg/class-extension-4.m: New. * obj-c++.dg/class-extension-4.mm: New. From-SVN: r168294 --- gcc/objc/ChangeLog | 5 +++++ gcc/objc/objc-act.c | 17 +++++++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/obj-c++.dg/class-extension-4.mm | 19 +++++++++++++++++++ gcc/testsuite/objc.dg/class-extension-4.m | 19 +++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 gcc/testsuite/obj-c++.dg/class-extension-4.mm create mode 100644 gcc/testsuite/objc.dg/class-extension-4.m diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 16b774d5512..c7efb54cb93 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,8 @@ +2010-12-28 Nicola Pero + + * 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 PR objc/47073 diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index ba6c8108814..1117967e71d 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 563fc03d048..ac141bd73e9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-12-28 Nicola Pero + + * objc.dg/class-extension-4.m: New. + * obj-c++.dg/class-extension-4.mm: New. + 2010-12-28 Nicola Pero 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 index 00000000000..9e19aa70d3b --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/class-extension-4.mm @@ -0,0 +1,19 @@ +/* Contributed by Nicola Pero , December 2010. */ +/* { dg-do compile } */ + +/* This test tests you can not declare a class extension after the class @implementation. */ + +#include + +@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 00000000000..692a0fcbd0a --- /dev/null +++ b/gcc/testsuite/objc.dg/class-extension-4.m @@ -0,0 +1,19 @@ +/* Contributed by Nicola Pero , December 2010. */ +/* { dg-do compile } */ + +/* This test tests you can not declare a class extension after the class @implementation. */ + +#include + +@interface MyObject +{ + Class isa; +} +@end + +@implementation MyObject +@end + +@interface MyObject () +- (void) test; /* { dg-error "class extension for class .MyObject. declared after its ..implementation." } */ +@end -- 2.30.2