Patchwork ObjC++ bugfix for PR objc++/28050

login
register
mail settings
Submitter Nicola Pero
Date Oct. 5, 2010, 5:09 p.m.
Message ID <1286298561.240132668@192.168.2.231>
Download mbox | patch
Permalink /patch/66849/
State New
Headers show

Comments

Nicola Pero - Oct. 5, 2010, 5:09 p.m.
This ObjC++ patch (to be applied on top of my other two ObjC++ patches from today) 
fixes PR objc++/28050, which is yet another internal compiler error (in this case, 
for an '@interface' with no following identifier).

Thanks

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

       PR objc++/28050
       * obj-c++.dg/syntax-error-10.mm: New.
Mike Stump - Oct. 5, 2010, 5:21 p.m.
On Oct 5, 2010, at 10:09 AM, Nicola Pero wrote:
> This ObjC++ patch (to be applied on top of my other two ObjC++ patches from today) 
> fixes PR objc++/28050, which is yet another internal compiler error (in this case, 
> for an '@interface' with no following identifier).

Ok.

Patch

Index: obj-c++.dg/syntax-error-10.mm
===================================================================
--- obj-c++.dg/syntax-error-10.mm       (revision 0)
+++ obj-c++.dg/syntax-error-10.mm       (revision 0)
@@ -0,0 +1 @@ 
+@interface /* { dg-error "expected identifier" } */

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

       PR objc++/31125
       * parser.c (cp_parser_objc_class_interface): If no identifier
       follows an @interface token, stop parsing the interface after
       printing an error.
       (cp_parser_objc_class_implementation): If no identifier follows an
       @implementation token, stop parsing the implementation after
       printing an error.

Index: parser.c
===================================================================
--- parser.c    (revision 164989)
+++ parser.c    (working copy)
@@ -21932,6 +21976,15 @@  cp_parser_objc_class_interface (cp_parser* parser,
 
   cp_lexer_consume_token (parser->lexer);  /* Eat '@interface'.  */
   name = cp_parser_identifier (parser);
+  if (name == error_mark_node)
+    {
+      /* It's hard to recover because even if valid @interface stuff
+        is to follow, we can't compile it (or validate it) if we
+        don't even know which class it refers to.  Let's assume this
+        was a stray '@interface' token in the stream and skip it.
+      */
+      return;
+    }
   cp_parser_objc_superclass_or_category (parser, &super, &categ);
   protos = cp_parser_objc_protocol_refs_opt (parser);
 
@@ -21958,6 +22011,16 @@  cp_parser_objc_class_implementation (cp_parser* pa
 
   cp_lexer_consume_token (parser->lexer);  /* Eat '@implementation'.  */
   name = cp_parser_identifier (parser);
+  if (name == error_mark_node)
+    {
+      /* It's hard to recover because even if valid @implementation
+        stuff is to follow, we can't compile it (or validate it) if
+        we don't even know which class it refers to.  Let's assume
+        this was a stray '@implementation' token in the stream and
+        skip it.
+      */
+      return;
+    }
   cp_parser_objc_superclass_or_category (parser, &super, &categ);
 
   /* We have either a class or a category on our hands.  */