This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR c++/31745: ICE on invalid use of namespace


Hi Mark.

This version is OK -- though I think that Manuel is correct that
updating cp_parser_skip_to_closing_brace to return the next token type,
or a boolean indicating whether it found a closing brace, is a nice
idea, just in making the code a little simpler.
Ok, here's a version implementing Manuel's idea (I only attach the
updated patch and Changelog for gcc/cp; the testcases and Changelog for
gcc/testsuite are the same as previously).

I've successfully regtested it on i386-apple-darwin8.9.1 with no new
unexpected failures. Is it OK?

Best regards,
Simon

2007-05-22  Simon Martin  <simartin@users.sourceforge.net>
	    Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c++/31745
	* parser.c (cp_parser_skip_to_closing_brace): Return true if the next
	token is a closing brace, false if there are no tokens left.
	(cp_parser_namespace_alias_definition): Only consume the next token if
	it is a closing brace.

	* parser.c (cp_parser_class_specifier): Likewise.

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 124910)
+++ gcc/cp/parser.c	(working copy)
@@ -1999,7 +1999,7 @@ static void cp_parser_consume_semicolon_
   (cp_parser *);
 static void cp_parser_skip_to_end_of_block_or_statement
   (cp_parser *);
-static void cp_parser_skip_to_closing_brace
+static bool cp_parser_skip_to_closing_brace
   (cp_parser *);
 static void cp_parser_skip_to_end_of_template_parameter_list
   (cp_parser *);
@@ -2599,9 +2599,10 @@ cp_parser_skip_to_end_of_block_or_statem
 }
 
 /* Skip tokens until a non-nested closing curly brace is the next
-   token.  */
+   token, or there are no more tokens. Return true in the first case,
+   false otherwise.  */
 
-static void
+static bool
 cp_parser_skip_to_closing_brace (cp_parser *parser)
 {
   unsigned nesting_depth = 0;
@@ -2615,13 +2616,13 @@ cp_parser_skip_to_closing_brace (cp_pars
 	case CPP_EOF:
 	case CPP_PRAGMA_EOL:
 	  /* If we've run out of tokens, stop.  */
-	  return;
+	  return false;
 
 	case CPP_CLOSE_BRACE:
 	  /* If the next token is a non-nested `}', then we have reached
 	     the end of the current block.  */
 	  if (nesting_depth-- == 0)
-	    return;
+	    return true;
 	  break;
 
 	case CPP_OPEN_BRACE:
@@ -11295,8 +11296,8 @@ cp_parser_namespace_alias_definition (cp
       error ("%<namespace%> definition is not allowed here");
       /* Skip the definition.  */
       cp_lexer_consume_token (parser->lexer);
-      cp_parser_skip_to_closing_brace (parser);
-      cp_lexer_consume_token (parser->lexer);
+      if (cp_parser_skip_to_closing_brace (parser))
+	cp_lexer_consume_token (parser->lexer);
       return;
     }
   cp_parser_require (parser, CPP_EQ, "`='");
@@ -13818,11 +13819,10 @@ cp_parser_class_specifier (cp_parser* pa
      entire class body.  */
   if (!xref_basetypes (type, bases))
     {
-      cp_parser_skip_to_closing_brace (parser);
-
       /* Consuming the closing brace yields better error messages
          later on.  */
-      cp_lexer_consume_token (parser->lexer);
+      if (cp_parser_skip_to_closing_brace (parser))
+	cp_lexer_consume_token (parser->lexer);
       pop_deferring_access_checks ();
       return error_mark_node;
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]