* [objc] Warnings when -fobjc-exception is not used
@ 2010-09-04 21:12 Nicola Pero
2010-09-04 21:33 ` Steven Bosscher
2010-09-07 19:30 ` Mike Stump
0 siblings, 2 replies; 6+ messages in thread
From: Nicola Pero @ 2010-09-04 21:12 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 237 bytes --]
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 ?
Thanks
[-- Attachment #2: objc.patch --]
[-- Type: application/octet-stream, Size: 2010 bytes --]
Index: objc/objc-act.c
===================================================================
--- objc/objc-act.c (revision 163859)
+++ objc/objc-act.c (working copy)
@@ -3822,14 +3822,14 @@
c->end_try_locus = input_location;
cur_try_context = c;
- if (flag_objc_sjlj_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");
- }
+ /* On Darwin, ObjC exceptions require a sufficiently recent version
+ * of the runtime, so the user must ask for them explicitly.
+ * Outside of Darwin, -fobjc-exceptions automatically enables
+ * -fexceptions, without which exceptions don't work.
+ */
+ if (!flag_objc_exceptions)
+ warning (0, "use %<-fobjc-exceptions%> to enable Objective-C "
+ "exception syntax");
if (flag_objc_sjlj_exceptions)
objc_mark_locals_volatile (NULL);
@@ -4016,6 +4016,13 @@
{
tree args, call;
+ /* -fobjc-exceptions automatically enables -fexceptions, without
+ * which exceptions don't work.
+ */
+ if (!flag_objc_exceptions)
+ warning (0, "use %<-fobjc-exceptions%> to enable Objective-C "
+ "exception syntax");
+
/* First lock the mutex. */
mutex = save_expr (mutex);
args = tree_cons (NULL, mutex, NULL);
Index: objc/ChangeLog
===================================================================
--- objc/ChangeLog (revision 163859)
+++ objc/ChangeLog (working copy)
@@ -1,3 +1,10 @@
+2010-09-04 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ * objc-act.c (objc_begin_try_stmt): Warn on all platforms if @try
+ is used without -fobjc-exceptions.
+ (objc_build_synchronized): Warn on all platforms if @synchronized
+ is used without -fobjc-exceptions, as per documentation.
+
2010-07-15 Nathan Froyd <froydnj@codesourcery.com>
* objc-act.c: Carefully replace TREE_CHAIN with DECL_CHAIN.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [objc] Warnings when -fobjc-exception is not used
2010-09-04 21:12 [objc] Warnings when -fobjc-exception is not used Nicola Pero
@ 2010-09-04 21:33 ` Steven Bosscher
2010-09-05 15:16 ` Nicola Pero
2010-09-07 19:30 ` Mike Stump
1 sibling, 1 reply; 6+ messages in thread
From: Steven Bosscher @ 2010-09-04 21:33 UTC (permalink / raw)
To: Nicola Pero; +Cc: gcc-patches
On Sat, Sep 4, 2010 at 10:48 PM, Nicola Pero
<nicola.pero@meta-innovation.com> wrote:
> 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 ?
> + /* On Darwin, ObjC exceptions require a sufficiently recent version
> + * of the runtime, so the user must ask for them explicitly.
> + * Outside of Darwin, -fobjc-exceptions automatically enables
> + * -fexceptions, without which exceptions don't work.
> + */
Please follow GNU/GCC coding style guidelines:
+ /* On Darwin, ObjC exceptions require a sufficiently recent version
+ of the runtime, so the user must ask for them explicitly.
+ Outside of Darwin, -fobjc-exceptions automatically enables
+ -fexceptions, without which exceptions don't work. */
Why is this only a warning? It seems to me that with a warning you're
suggesting to the user that everything is alright, but the exception
code will not work. Also the way I read the documentation in
c-family/c.opt, what you warn about should actually be an error:
; Nonzero means that we will allow new ObjC exception syntax (@throw,
; @try, etc.) in source code.
fobjc-exceptions
ObjC ObjC++ Var(flag_objc_exceptions)
Enable Objective-C exception and synchronization synta
In other words: @try/@throw/@synchronize without -fobjc-exceptions
should be a syntax error.
Ciao!
Steven
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [objc] Warnings when -fobjc-exception is not used
2010-09-04 21:33 ` Steven Bosscher
@ 2010-09-05 15:16 ` Nicola Pero
0 siblings, 0 replies; 6+ messages in thread
From: Nicola Pero @ 2010-09-05 15:16 UTC (permalink / raw)
To: Steven Bosscher; +Cc: gcc-patches
> Why is this only a warning? It seems to me that with a warning you're
> suggesting to the user that everything is alright, but the exception
> code will not work. Also the way I read the documentation in
> c-family/c.opt, what you warn about should actually be an error:
>
> ; Nonzero means that we will allow new ObjC exception syntax (@throw,
> ; @try, etc.) in source code.
> fobjc-exceptions
> ObjC ObjC++ Var(flag_objc_exceptions)
> Enable Objective-C exception and synchronization synta
>
> In other words: @try/@throw/@synchronize without -fobjc-exceptions
> should be a syntax error.
That is an excellent suggestion :-)
I had also wondered about it, and implemented it this way mostly
because the code for the NeXT runtime
was already treating the lack of -fobjc-exceptions as a warning. My
idea was simply to extend the same warnings
to the GNU runtime. But actually an error makes more sense.
I'll rework the patch and repost it (there is also a mistake in the
patch I posted in that it is warning for @synchronized twice,
so please ignore it for now anyway) with a test case.
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [objc] Warnings when -fobjc-exception is not used
2010-09-04 21:12 [objc] Warnings when -fobjc-exception is not used Nicola Pero
2010-09-04 21:33 ` Steven Bosscher
@ 2010-09-07 19:30 ` Mike Stump
2010-09-08 19:00 ` Nicola Pero
1 sibling, 1 reply; 6+ messages in thread
From: Mike Stump @ 2010-09-07 19:30 UTC (permalink / raw)
To: Nicola Pero; +Cc: gcc-patches
On Sep 4, 2010, at 1:48 PM, Nicola Pero wrote:
> 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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [objc] Warnings when -fobjc-exception is not used
2010-09-07 19:30 ` Mike Stump
@ 2010-09-08 19:00 ` Nicola Pero
2010-09-08 22:47 ` Mike Stump
0 siblings, 1 reply; 6+ messages in thread
From: Nicola Pero @ 2010-09-08 19:00 UTC (permalink / raw)
To: Mike Stump; +Cc: gcc-patches
>> 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;
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [objc] Warnings when -fobjc-exception is not used
2010-09-08 19:00 ` Nicola Pero
@ 2010-09-08 22:47 ` Mike Stump
0 siblings, 0 replies; 6+ messages in thread
From: Mike Stump @ 2010-09-08 22:47 UTC (permalink / raw)
To: Nicola Pero; +Cc: gcc-patches
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-09-08 22:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-04 21:12 [objc] Warnings when -fobjc-exception is not used Nicola Pero
2010-09-04 21:33 ` Steven Bosscher
2010-09-05 15:16 ` Nicola Pero
2010-09-07 19:30 ` Mike Stump
2010-09-08 19:00 ` Nicola Pero
2010-09-08 22:47 ` Mike Stump
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).