diff mbox

[objc] Warnings when -fobjc-exception is not used

Message ID 1283969619.625114205@192.168.2.229
State New
Headers show

Commit Message

Nicola Pero Sept. 8, 2010, 6:13 p.m. UTC
>> 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

Comments

Mike Stump Sept. 8, 2010, 10:08 p.m. UTC | #1
On Sep 8, 2010, at 11:13 AM, Nicola Pero wrote:
> I reworked the patch to use an error intead of a warning,

> Ok to apply ?

Ok.
diff mbox

Patch

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;
+}