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: PR 13736


This patch fixes a regression introduced when improving some error
messages from the new parser.

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

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

2004-01-28  Mark Mitchell  <mark@codesourcery.com>

	PR c++/13736
	* parser.c (cp_parser_direct_declarator): Do not prevent
	backtracking inside a parenthesized declarator.
	(cp_parser_parameter_declaration): Fix typo in comment.

2004-01-28  Mark Mitchell  <mark@codesourcery.com>

	PR c++/13736
	* g++.dg/parse/cast2.C: New test.

Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.161
diff -c -5 -p -r1.161 parser.c
*** parser.c	25 Jan 2004 22:43:08 -0000	1.161
--- parser.c	29 Jan 2004 01:22:35 -0000
*************** cp_parser_direct_declarator (cp_parser* 
*** 10283,10301 ****
--- 10283,10306 ----
  	  
  	  /* If this is the first, we can try a parenthesized
  	     declarator.  */
  	  if (first)
  	    {
+ 	      bool saved_in_type_id_in_expr_p;
+ 
  	      parser->default_arg_ok_p = saved_default_arg_ok_p;
  	      parser->in_declarator_p = saved_in_declarator_p;
  	      
  	      /* Consume the `('.  */
  	      cp_lexer_consume_token (parser->lexer);
  	      /* Parse the nested declarator.  */
+ 	      saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
+ 	      parser->in_type_id_in_expr_p = true;
  	      declarator 
  		= cp_parser_declarator (parser, dcl_kind, ctor_dtor_or_conv_p,
  					/*parenthesized_p=*/NULL);
+ 	      parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
  	      first = false;
  	      /* Expect a `)'.  */
  	      if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
  		declarator = error_mark_node;
  	      if (declarator == error_mark_node)
*************** cp_parser_parameter_declaration (cp_pars
*** 11046,11060 ****
  	 expression.  Therefore, if parsing tentatively, we commit at
  	 this point.  */
        if (!parser->in_template_argument_list_p
  	  /* In an expression context, having seen:
  
! 	       (int((char *)...
  
  	     we cannot be sure whether we are looking at a
! 	     function-type (taking a "char*" as a parameter) or a cast
! 	     of some object of type "char*" to "int".  */
  	  && !parser->in_type_id_in_expr_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);
--- 11051,11065 ----
  	 expression.  Therefore, if parsing tentatively, we commit at
  	 this point.  */
        if (!parser->in_template_argument_list_p
  	  /* In an expression context, having seen:
  
! 	       (int((char ...
  
  	     we cannot be sure whether we are looking at a
! 	     function-type (taking a "char" as a parameter) or a cast
! 	     of some object of type "char" to "int".  */
  	  && !parser->in_type_id_in_expr_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);
Index: testsuite/g++.dg/parse/cast2.C
===================================================================
RCS file: testsuite/g++.dg/parse/cast2.C
diff -N testsuite/g++.dg/parse/cast2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/cast2.C	29 Jan 2004 01:33:24 -0000
***************
*** 0 ****
--- 1,13 ----
+ // PR c++/13736
+ 
+ struct string
+ {
+   string() {}
+   string(const string&) {}
+   string(const char*) {}
+ };
+ 
+ int main()
+ {
+   string s2(string( (const char*)("")));
+ }


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