From: nicola Date: Mon, 29 Nov 2010 20:45:49 +0000 (+0000) Subject: In gcc/objc/: X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1cd5e6abf0d15e1dc0ab214eae2dcc3f83275334;p=thirdparty%2Fgcc.git In gcc/objc/: 2010-11-29 Nicola Pero * objc-act.c (start_class): When a class is reimplemented, generate an error and avoid adding the class to the list of implemented classes again, but do not return error_mark_node. In gcc/testsuite/: 2010-11-29 Nicola Pero * objc.dg/duplicate-class-1.m: New. * obj-c++.dg/duplicate-class-1.mm: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167270 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 636bf85de1bf..47c896a7073f 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,9 @@ +2010-11-29 Nicola Pero + + * objc-act.c (start_class): When a class is reimplemented, + generate an error and avoid adding the class to the list of + implemented classes again, but do not return error_mark_node. + 2010-11-29 Nicola Pero * objc-act.c (objc_maybe_build_component_ref): Removed TODO. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 2382da4fd4d4..8de8e255e240 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -9537,10 +9537,13 @@ start_class (enum tree_code code, tree class_name, tree super_name, { error ("reimplementation of class %qE", class_name); - return error_mark_node; + /* TODO: error message saying where it was previously + implemented. */ + break; } - implemented_classes = tree_cons (NULL_TREE, class_name, - implemented_classes); + if (chain == NULL_TREE) + implemented_classes = tree_cons (NULL_TREE, class_name, + implemented_classes); } /* Reset for multiple classes per file. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0a154e003a53..5792e66d131b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-11-29 Nicola Pero + + * objc.dg/duplicate-class-1.m: New. + * obj-c++.dg/duplicate-class-1.mm: New. + 2010-11-29 Nicola Pero * objc.dg/property/dotsyntax-21.m diff --git a/gcc/testsuite/obj-c++.dg/duplicate-class-1.mm b/gcc/testsuite/obj-c++.dg/duplicate-class-1.mm new file mode 100644 index 000000000000..9476533d1eac --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/duplicate-class-1.mm @@ -0,0 +1,31 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ + +/* Test that a duplicated @implementation for the same class does not + crash the compiler. */ + +@interface Test +{ + Class isa; +} +- (int) test; +@end + +@implementation Test +- (int) test +{ + return 4; +} +@end + +/* The most likely cause is that the programmer meant this to be a + category, so check what happens if we have some different methods + in there. */ +@implementation Test /* { dg-error "reimplementation of class .Test." } */ +- (int) test2 +{ + return [self test]; +} +@end +/* { dg-warning "incomplete implementation" "" { target *-*-* } 29 } */ +/* { dg-warning "not found" "" { target *-*-* } 29 } */ diff --git a/gcc/testsuite/objc.dg/duplicate-class-1.m b/gcc/testsuite/objc.dg/duplicate-class-1.m new file mode 100644 index 000000000000..f86159211b38 --- /dev/null +++ b/gcc/testsuite/objc.dg/duplicate-class-1.m @@ -0,0 +1,31 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ + +/* Test that a duplicated @implementation for the same class does not + crash the compiler. */ + +@interface Test +{ + Class isa; +} +- (int) test; +@end + +@implementation Test +- (int) test +{ + return 4; +} +@end + +/* The most likely cause is that the programmer meant this to be a + category, so check what happens if we have some different methods + in there. */ +@implementation Test +- (int) test2 /* { dg-error "reimplementation of class .Test." } */ +{ + return [self test]; +} +@end +/* { dg-warning "incomplete implementation" "" { target *-*-* } 29 } */ +/* { dg-warning "not found" "" { target *-*-* } 29 } */