From patchwork Wed Sep 8 18:13:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 64191 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 69678B6EF0 for ; Thu, 9 Sep 2010 04:13:55 +1000 (EST) Received: (qmail 15131 invoked by alias); 8 Sep 2010 18:13:52 -0000 Received: (qmail 15102 invoked by uid 22791); 8 Sep 2010 18:13:51 -0000 X-SWARE-Spam-Status: No, hits=-1.0 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; Wed, 08 Sep 2010 18:13:43 +0000 Received: from eggs.gnu.org ([140.186.70.92]:45890) by fencepost.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OtP9Q-00011o-9M for gcc-patches@gnu.org; Wed, 08 Sep 2010 14:13:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OtP9Q-0007hx-42 for gcc-patches@gnu.org; Wed, 08 Sep 2010 14:13:41 -0400 Received: from smtp121.iad.emailsrvr.com ([207.97.245.121]:56803) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OtP9Q-0007hr-0h for gcc-patches@gnu.org; Wed, 08 Sep 2010 14:13:40 -0400 Received: from relay22.relay.iad.mlsrvr.com (localhost [127.0.0.1]) by relay22.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id B15521B5453; Wed, 8 Sep 2010 14:13:39 -0400 (EDT) Received: from dynamic10.wm-web.iad.mlsrvr.com (dynamic10.wm-web.iad.mlsrvr.com [192.168.2.217]) by relay22.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id A95911B544F; Wed, 8 Sep 2010 14:13:39 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic10.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 99445478807F; Wed, 8 Sep 2010 14:13:39 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Wed, 8 Sep 2010 20:13:39 +0200 (CEST) Date: Wed, 8 Sep 2010 20:13:39 +0200 (CEST) Subject: Re: [objc] Warnings when -fobjc-exception is not used From: "Nicola Pero" To: "Mike Stump" Cc: gcc-patches@gnu.org MIME-Version: 1.0 X-Type: plain In-Reply-To: <236DEEED-7B30-4DDA-AF28-A6C3937A7DFD@comcast.net> References: <1283633317.686914439@192.168.2.229> <236DEEED-7B30-4DDA-AF28-A6C3937A7DFD@comcast.net> Message-ID: <1283969619.625114205@192.168.2.229> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 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 >> Now that the GNU runtime supports @try/@catch/@throw (and @synchronized soon), it is important to warn if -fobjc-exceptions is not passed on the command-line when using one of them. >> >> The attached patch does it. Ok to apply ? > > Ok. Thanks Mike! :-) I reworked the patch to use an error intead of a warning, as suggested by Steven Bosscher (it makes sense since trying to use Objective-C exceptions without -fobjc-exceptions produces non-working stuff), and added a testcase. Ok to apply ? Thanks Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 164014) +++ objc/objc-act.c (working copy) @@ -3822,13 +3822,16 @@ c->end_try_locus = input_location; cur_try_context = c; - if (flag_objc_sjlj_exceptions) + /* -fobjc-exceptions is required to enable Objective-C exceptions. + For example, on Darwin, ObjC exceptions require a sufficiently + recent version of the runtime, so the user must ask for them + explicitly. On other platforms, at the moment -fobjc-exceptions + triggers -fexceptions which again is required for exceptions to + work. + */ + if (!flag_objc_exceptions) { - /* On Darwin, ObjC exceptions require a sufficiently recent - version of the runtime, so the user must ask for them explicitly. */ - if (!flag_objc_exceptions) - warning (0, "use %<-fobjc-exceptions%> to enable Objective-C " - "exception syntax"); + error_at (try_locus, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax"); } if (flag_objc_sjlj_exceptions) @@ -3979,13 +3982,9 @@ { tree args; - if (flag_objc_sjlj_exceptions) + if (!flag_objc_exceptions) { - /* On Darwin, ObjC exceptions require a sufficiently recent - version of the runtime, so the user must ask for them explicitly. */ - if (!flag_objc_exceptions) - warning (0, "use %<-fobjc-exceptions%> to enable Objective-C " - "exception syntax"); + error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax"); } if (throw_expr == NULL) Index: testsuite/objc.dg/fobjc-exceptions-1.m =================================================================== --- testsuite/objc.dg/fobjc-exceptions-1.m (revision 0) +++ testsuite/objc.dg/fobjc-exceptions-1.m (revision 0) @@ -0,0 +1,28 @@ +/* Test that Objective-C exceptions cause an error with -fobjc-exceptions. */ +/* { dg-do compile } */ + +@class Object; + +int dummy (int number, Object *o) +{ + @try { /* { dg-error "fobjc-exceptions" "is required to enable Objective-C exception syntax" } */ + number++; + @throw o; /* { dg-error "fobjc-exceptions" "is required to enable Objective-C exception syntax" } */ + } + @catch (id object) + { + number++; + @throw; /* { dg-error "fobjc-exceptions" "is required to enable Objective-C exception syntax" } */ + } + @finally + { + number++; + } + + @synchronized (o) /* { dg-error "fobjc-exceptions" "is required to enable Objective-C exception syntax" } */ + { + number++; + } + + return number; +}