From patchwork Tue Dec 28 05:07:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 76815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 09BE7B708B for ; Tue, 28 Dec 2010 16:07:58 +1100 (EST) Received: (qmail 19431 invoked by alias); 28 Dec 2010 05:07:55 -0000 Received: (qmail 19423 invoked by uid 22791); 28 Dec 2010 05:07:53 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 28 Dec 2010 05:07:49 +0000 Received: from eggs.gnu.org ([140.186.70.92]:47584) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PXRmi-000209-Eh for gcc-patches@gnu.org; Tue, 28 Dec 2010 00:07:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PXRmk-0001dO-Az for gcc-patches@gnu.org; Tue, 28 Dec 2010 00:07:47 -0500 Received: from smtp181.iad.emailsrvr.com ([207.97.245.181]:40024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PXRmk-0001dI-7F for gcc-patches@gnu.org; Tue, 28 Dec 2010 00:07:46 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp48.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id C67161691E5 for ; Tue, 28 Dec 2010 00:07:45 -0500 (EST) Received: by smtp48.relay.iad1a.emailsrvr.com (Authenticated sender: nicola.pero-AT-meta-innovation.com) with ESMTPA id 46BD51691DE for ; Tue, 28 Dec 2010 00:07:45 -0500 (EST) Message-Id: <28E30061-901F-432A-B9FA-E53E9EE315D1@meta-innovation.com> From: Nicola Pero To: gcc-patches@gnu.org Mime-Version: 1.0 (Apple Message framework v936) Subject: ObjC/ObjC++: Fix missing check that a class extension is declared before the class implementation Date: Tue, 28 Dec 2010 06:07:40 +0100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch fixes the ObjC/ObjC++ compiler so that it detects when a class extension is declared after the class implementation, and produces the appropriate error. Ok to commit to trunk ? Thanks class .MyObject. declared after its ..implementation." } */ +- (void) test; +@end Index: gcc/objc/objc-act.c =================================================================== --- gcc/objc/objc-act.c (revision 168285) +++ gcc/objc/objc-act.c (working copy) @@ -763,6 +763,23 @@ objc_start_category_interface (tree klas { 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: objc/ChangeLog =================================================================== --- objc/ChangeLog (revision 168285) +++ objc/ChangeLog (working copy) @@ -1,5 +1,10 @@ 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 * objc-act.c (encode_method_prototype): Fixed both location and format string of error "type %qT does not have a known size". Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 168285) +++ testsuite/ChangeLog (working copy) @@ -1,5 +1,10 @@ 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 * objc.dg/incomplete-type-1.m: New test. Index: testsuite/objc.dg/class-extension-4.m =================================================================== --- testsuite/objc.dg/class-extension-4.m (revision 0) +++ testsuite/objc.dg/class-extension-4.m (revision 0) @@ -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 Index: testsuite/obj-c++.dg/class-extension-4.mm =================================================================== --- testsuite/obj-c++.dg/class-extension-4.mm (revision 0) +++ testsuite/obj-c++.dg/class-extension-4.mm (revision 0) @@ -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