ObjC/ObjC++: bug fixes for @catch

Nicola Pero nicola.pero@meta-innovation.com
Sun Nov 28 12:58:00 GMT 2010


This patch fixes a number of bugs, minor and missing/incomplete checks (and some ICEs) in GCC's parsing
of Objective-C @catch syntax.

I started work on this patch by running GCC 4.6.0 against a number of @try/@throw/@catch/@finally
testcases in clang.  I fixed all problems that these highlighted in GCC with respect to @catch, 
and I tidied up a number of additional cases and problems that came up while studying the testcases.

This patch:

 * implements the syntax "@catch(...)" which was missing.  With this patch, this syntax is parsed and
is equivalent to "@catch (id temporary_unused_variable)" (ie, no integration with C++; once better
integration with C++ is implemented, @catch(...) is supposed to also catch C++ exceptions.  Not for 4.6).
4 testcases (one for parsing, one for executing for both ObjC and ObjC++) are included (sadly, as it is
well-known (PR objc++/23616), ObjC exceptions don't actually work in ObjC++, so I had to disable the
ObjC++ execution one as fixing that is not part of this patch.  I don't think I'll work on that for 4.6,
it's too late)

 * implements better type-checking for the argument of @catch().  In particular, arguments that are 
protocol-qualified are now (correctly) rejected.  Testcases included, showing various types of arguments 
that are accepted or rejected (PS: before this patch, both the exceptions-3.m and exceptions-5.m testcases
would not only accept invalid arguments, but actually ICE the compiler).

 * improves error recovery when parsing invalid @catch(){} clauses.  Testcases included, showing a number 
of cases of typos and localized errors and the results.

 * makes the ObjC and ObjC++ parsing code very similar

Ok to commit ?

Thanks

In gcc/objc/:
2010-11-28  Nicola Pero  <nicola.pero@meta-innovation.com>

        * objc-act.c (objc_eh_runtime_type): Avoid ICE if error_mark_node
        is passed as argument.
        (objc_begin_catch_clause): Added code to deal with an
        error_mark_node or NULL_TREE argument.  Improved checks for
        invalid arguments.  Added code to traverse typedefs.

In gcc/testsuite/:
2010-11-28  Nicola Pero  <nicola.pero@meta-innovation.com>

        * objc.dg/exceptions-1.m: New.
        * objc.dg/exceptions-2.m: New.
        * objc.dg/exceptions-3.m: New.
        * objc.dg/exceptions-4.m: New.
        * objc.dg/exceptions-5.m: New.
        * obj-c++.dg/exceptions-1.mm: New.
        * obj-c++.dg/exceptions-2.mm: New.
        * obj-c++.dg/exceptions-3.mm: New.
        * obj-c++.dg/exceptions-4.mm: New.
        * obj-c++.dg/exceptions-5.mm: New.

In gcc/cp/:
2010-11-28  Nicola Pero  <nicola.pero@meta-innovation.com>

        * parser.c (cp_parser_objc_try_catch_finally_statement): Parse
        @catch(...)  and pass NULL_TREE to objc_begin_catch_clause() in
        that case.  Improved error recovery.  Reorganized code to be
        almost identical to c_parser_objc_try_catch_finally_statement.

In gcc/:
2010-11-28  Nicola Pero  <nicola.pero@meta-innovation.com>

        * c-parser.c (c_parser_objc_try_catch_statement): Renamed to
        c_parser_objc_try_catch_finally_statement for consistency with the
        C++ parser.  Parse @catch(...) and pass NULL_TREE to
        objc_begin_catch_clause() in that case.  Improved error recovery.
        Reorganized code to be almost identical to
        cp_parser_objc_try_catch_finally_statement.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20101128/11d59bc0/attachment.txt>


More information about the Gcc-patches mailing list