From patchwork Sat Nov 27 11:25:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 73273 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 79560B70E0 for ; Sat, 27 Nov 2010 22:25:42 +1100 (EST) Received: (qmail 4815 invoked by alias); 27 Nov 2010 11:25:40 -0000 Received: (qmail 4754 invoked by uid 22791); 27 Nov 2010 11:25:39 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, 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; Sat, 27 Nov 2010 11:25:34 +0000 Received: from eggs.gnu.org ([140.186.70.92]:33317) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PMIuI-0002sz-S4 for gcc-patches@gnu.org; Sat, 27 Nov 2010 06:25:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PMIuJ-0003KH-NF for gcc-patches@gnu.org; Sat, 27 Nov 2010 06:25:32 -0500 Received: from smtp181.iad.emailsrvr.com ([207.97.245.181]:55717) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PMIuJ-0003KD-Km for gcc-patches@gnu.org; Sat, 27 Nov 2010 06:25:31 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp48.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 1F6611687B7 for ; Sat, 27 Nov 2010 06:25:31 -0500 (EST) Received: from dynamic3.wm-web.iad.mlsrvr.com (dynamic3.wm-web.iad1a.rsapps.net [192.168.2.152]) by smtp48.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 0C0241687F7 for ; Sat, 27 Nov 2010 06:25:30 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic3.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id DDC20332006E for ; Sat, 27 Nov 2010 06:25:30 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sat, 27 Nov 2010 12:25:30 +0100 (CET) Date: Sat, 27 Nov 2010 12:25:30 +0100 (CET) Subject: ObjC++: fix for objc++/46222 From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1290857130.906113251@192.168.2.228> 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 objc++/46222. It's an ICE triggered by pathologically invalid ObjC++ code where someone is using a function declaration as a property declaration. The fix simply replaces the assert that causes the ICE with a check that prints an error message and returns error_mark_node. I tried to use an error message that would make sense in C++ as well if that check is ever hit in C++. Even in C++, if the check/assert is ever triggered it would be much better to print an error message and continue than to suddenly ICE. Ok to commit ? Thanks Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 167197) +++ testsuite/ChangeLog (working copy) @@ -1,5 +1,10 @@ 2010-11-27 Nicola Pero + PR objc++/46222 + * obj-c++.dg/property/at-property-2.mm: Uncommented testcase. + +2010-11-27 Nicola Pero + * objc.dg/property/at-property-24.m: New. * objc.dg/property/at-property-25.m: New. * obj-c++.dg/property/at-property-24.mm: New. Index: testsuite/obj-c++.dg/property/at-property-2.mm =================================================================== --- testsuite/obj-c++.dg/property/at-property-2.mm (revision 167195) +++ testsuite/obj-c++.dg/property/at-property-2.mm (working copy) @@ -8,7 +8,6 @@ } @property int name __attribute__((deprecated)); @property int table __attribute__((xxx)); /* { dg-warning ".xxx. attribute directive ignored" } */ -/* FIXME: the test below should not ICE. -@property void function (void); { dg-error "can.t make .function. into a method" } */ +@property void function (void); /* { dg-error "declaration of function .function. in invalid context" } */ @property typedef int j; /* { dg-error "invalid type for property" } */ @end Index: cp/decl.c =================================================================== --- cp/decl.c (revision 167195) +++ cp/decl.c (working copy) @@ -9531,7 +9531,21 @@ grokdeclarator (const cp_declarator *declarator, if (friendp == 0) { - gcc_assert (ctype); + /* This should never happen in pure C++ (the check + could be an assert). It could happen in + Objective-C++ if someone writes invalid code that + uses a function declaration for an instance + variable or property (instance variables and + properties are parsed as FIELD_DECLs, but they are + part of an Objective-C class, not a C++ class). + That code is invalid and is caught by this + check. */ + if (!ctype) + { + error ("declaration of function %qD in invalid context", + unqualified_id); + return error_mark_node; + } /* ``A union may [ ... ] not [ have ] virtual functions.'' ARM 9.5 */ Index: cp/ChangeLog =================================================================== --- cp/ChangeLog (revision 167195) +++ cp/ChangeLog (working copy) @@ -1,3 +1,11 @@ +2010-11-27 Nicola Pero + + PR objc++/46222 + * decl.c (grokdeclarator): Replaced an assert (for a case that can + never happen in C++, but could happen in ObjC++ for invalid code) + with a check that prints an error message and returns + error_mark_node. + 2010-11-23 Jeffrey Yasskin PR c++/46527