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]

[C++ PATCH] Fix error recovery in cp_parser_condition (PR c++/38635)


Hi!

When cp_parser_type_specifier_seq or cp_parser_declarator commits
to tentative parse, cp_parser_simulate_error in:
      /* If the next token is not an `=' or '{', then we might still be
         looking at an expression.  For example:

           if (A(a).x)

         looks like a decl-specifier-seq and a declarator -- but then
         there is no `=', so this is an expression.  */
      if (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ)
          && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE))
        cp_parser_simulate_error (parser);
does nothing, cp_parser_parse_definitely still succeeds.  But the code
later on in that function assumes that the next token must be CPP_EQ
or CPP_OPEN_BRACE.  If the next token is CPP_EOF, cp_lexer_consume_token
ICEs, otherwise it consumes a different token.

The following patch fixes it by calling cp_parser_require instead of
cp_lexer_consume_token when next token is not CPP_OPEN_BRACE.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2008-12-28  Jakub Jelinek  <jakub@redhat.com>

	PR c++/38635
	* parser.c (cp_parser_condition): Use cp_parser_require
	instead of cp_lexer_consume_token to consume =.

	* g++.dg/parse/cond4.C: New test.

--- gcc/cp/parser.c.jj	2008-12-19 10:19:10.000000000 +0100
+++ gcc/cp/parser.c	2008-12-28 01:08:56.000000000 +0100
@@ -7398,7 +7398,7 @@ cp_parser_condition (cp_parser* parser)
 	  else
 	    {
 	      /* Consume the `='.  */
-	      cp_lexer_consume_token (parser->lexer);
+	      cp_parser_require (parser, CPP_EQ, "%<=%>");
 	      initializer = cp_parser_initializer_clause (parser, &non_constant_p);
 	    }
 	  if (BRACE_ENCLOSED_INITIALIZER_P (initializer))
--- gcc/testsuite/g++.dg/parse/cond4.C.jj	2008-12-28 01:12:26.000000000 +0100
+++ gcc/testsuite/g++.dg/parse/cond4.C	2008-12-28 01:11:50.000000000 +0100
@@ -0,0 +1,6 @@
+// PR c++/38635
+// { dg-do compile }
+
+void foo()                                                                                                                              
+{                                                                                                                                       
+  if (struct A{}// { dg-error "types may not be defined|expected" }

	Jakub


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