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 PR 10603 and 12827


This patch fixes two more error-recovery regressions in the new
parser.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-12-17  Mark Mitchell  <mark@codesourcery.com>

	PR c++/10603
	PR c++/12827
	* parser.c (cp_parser_error): Help c_parse_error print good
	messages if the next token is a keyword.
	(cp_parser_parameter_declaration_list): When resynchronizing after
	a bad parameter declaration, stop if a comma is found.
	(cp_parser_parameter_declaration): Avoid backtracking.

2003-12-17  Mark Mitchell  <mark@codesourcery.com>

	PR c++/10603
	* g++.dg/parse/error6.C: New test.

	PR c++/12827
	* g++.dg/parse/error7.C: New test.

Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.135
diff -c -5 -p -r1.135 parser.c
*** cp/parser.c	16 Dec 2003 16:09:13 -0000	1.135
--- cp/parser.c	17 Dec 2003 16:56:32 -0000
*************** cp_parser_error (cp_parser* parser, cons
*** 1769,1779 ****
    /* Output the MESSAGE -- unless we're parsing tentatively.  */
    if (!cp_parser_simulate_error (parser))
      {
        cp_token *token;
        token = cp_lexer_peek_token (parser->lexer);
!       c_parse_error (message, token->type, token->value);
      }
  }
  
  /* Issue an error about name-lookup failing.  NAME is the
     IDENTIFIER_NODE DECL is the result of
--- 1769,1784 ----
    /* Output the MESSAGE -- unless we're parsing tentatively.  */
    if (!cp_parser_simulate_error (parser))
      {
        cp_token *token;
        token = cp_lexer_peek_token (parser->lexer);
!       c_parse_error (message, 
! 		     /* Because c_parser_error does not understand
! 			CPP_KEYWORD, keywords are treated like
! 			identifiers.  */
! 		     (token->type == CPP_KEYWORD ? CPP_NAME : token->type), 
! 		     token->value);
      }
  }
  
  /* Issue an error about name-lookup failing.  NAME is the
     IDENTIFIER_NODE DECL is the result of
*************** cp_parser_parameter_declaration_list (cp
*** 10802,10812 ****
  	  cp_parser_error (parser, "expected `,' or `...'");
  	  if (!cp_parser_parsing_tentatively (parser)
  	      || cp_parser_committed_to_tentative_parse (parser))
  	    cp_parser_skip_to_closing_parenthesis (parser, 
  						   /*recovering=*/true,
! 						   /*or_comma=*/true,
  						   /*consume_paren=*/false);
  	  break;
  	}
      }
  
--- 10807,10817 ----
  	  cp_parser_error (parser, "expected `,' or `...'");
  	  if (!cp_parser_parsing_tentatively (parser)
  	      || cp_parser_committed_to_tentative_parse (parser))
  	    cp_parser_skip_to_closing_parenthesis (parser, 
  						   /*recovering=*/true,
! 						   /*or_comma=*/false,
  						   /*consume_paren=*/false);
  	  break;
  	}
      }
  
*************** cp_parser_parameter_declaration (cp_pars
*** 10898,10907 ****
--- 10903,10922 ----
    else
      {
        bool saved_default_arg_ok_p = parser->default_arg_ok_p;
        parser->default_arg_ok_p = false;
    
+       /* After seeing a decl-specifier-seq, if the next token is not a
+ 	 "(", there is no possibility that the code is a valid
+ 	 expression initializer.  Therefore, if parsing tentatively,
+ 	 we commit at this point.  */
+       if (!parser->in_template_argument_list_p
+ 	  && cp_parser_parsing_tentatively (parser)
+ 	  && !cp_parser_committed_to_tentative_parse (parser)
+ 	  && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
+ 	cp_parser_commit_to_tentative_parse (parser);
+       /* Parse the declarator.  */
        declarator = cp_parser_declarator (parser,
  					 CP_PARSER_DECLARATOR_EITHER,
  					 /*ctor_dtor_or_conv_p=*/NULL,
  					 parenthesized_p);
        parser->default_arg_ok_p = saved_default_arg_ok_p;
Index: testsuite/g++.dg/parse/error3.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/parse/error3.C,v
retrieving revision 1.1
diff -c -5 -p -r1.1 error3.C
*** testsuite/g++.dg/parse/error3.C	15 Dec 2003 06:28:22 -0000	1.1
--- testsuite/g++.dg/parse/error3.C	17 Dec 2003 16:56:32 -0000
***************
*** 1,6 ****
  // PR c++/10779
  
  static void InstantiateConstraint(const float&, unsigned,
                                    void(*AddFunction)(const TYPE&,bool&, // { dg-error "" }
                                                       char*, char*,
!                                                      unsigned*));
--- 1,6 ----
  // PR c++/10779
  
  static void InstantiateConstraint(const float&, unsigned,
                                    void(*AddFunction)(const TYPE&,bool&, // { dg-error "" }
                                                       char*, char*,
!                                                      unsigned*)); // { dg-error "" }
Index: testsuite/g++.dg/parse/error6.C
===================================================================
RCS file: testsuite/g++.dg/parse/error6.C
diff -N testsuite/g++.dg/parse/error6.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/error6.C	17 Dec 2003 16:56:32 -0000
***************
*** 0 ****
--- 1,6 ----
+ // PR c++/10603
+ 
+ int f(int not) { // { dg-error "!" }
+   return 1-not; // { dg-error "" }
+ } 
+ 
Index: testsuite/g++.dg/parse/error7.C
===================================================================
RCS file: testsuite/g++.dg/parse/error7.C
diff -N testsuite/g++.dg/parse/error7.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/error7.C	17 Dec 2003 16:56:32 -0000
***************
*** 0 ****
--- 1,4 ----
+ // PR c++/12827
+ 
+ void f(int x
+        int y); // { dg-error "," }


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