ObjC++ bugfix for PR objc++/28050

Nicola Pero nicola.pero@meta-innovation.com
Tue Oct 5 17:09:00 GMT 2010


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.

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.  */




More information about the Gcc-patches mailing list