Patchwork C++ PATCH for c++/44991 (parse failure on default argument with <)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 29, 2010, 7:33 p.m.
Message ID <4C7AB625.6040106@redhat.com>
Download mbox | patch
Permalink /patch/62962/
State New
Headers show

Comments

Jason Merrill - Aug. 29, 2010, 7:33 p.m.
When I changed parameter parsing to push decls, I didn't think to adjust 
this other caller of cp_parser_parameter_declaration_list to pop the 
decls as necessary.

Tested x86_64-pc-linux-gnu, applied to trunk.  Will apply to 4.4 and 4.5 
after testing.

Patch

commit 29001c5bcfc152158b90b944668d7925e171853c
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Aug 25 23:20:17 2010 -0700

    	PR c++/44991
    	* parser.c (cp_parser_parameter_declaration): Pop parameter decls
    	after tentative parsing.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 6c4fe1d..b71d145 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -15564,6 +15564,7 @@  cp_parser_parameter_declaration (cp_parser *parser,
 			 the default argument; otherwise the default
 			 argument continues.  */
 		      bool error = false;
+		      tree t;
 
 		      /* Set ITALP so cp_parser_parameter_declaration_list
 			 doesn't decide to commit to this parse.  */
@@ -15572,7 +15573,11 @@  cp_parser_parameter_declaration (cp_parser *parser,
 
 		      cp_parser_parse_tentatively (parser);
 		      cp_lexer_consume_token (parser->lexer);
+		      begin_scope (sk_function_parms, NULL_TREE);
 		      cp_parser_parameter_declaration_list (parser, &error);
+		      for (t = current_binding_level->names; t; t = DECL_CHAIN (t))
+			pop_binding (DECL_NAME (t), t);
+		      leave_scope ();
 		      if (!cp_parser_error_occurred (parser) && !error)
 			done = true;
 		      cp_parser_abort_tentative_parse (parser);
diff --git a/gcc/testsuite/g++.dg/parse/defarg15.C b/gcc/testsuite/g++.dg/parse/defarg15.C
new file mode 100644
index 0000000..b93af4c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/defarg15.C
@@ -0,0 +1,5 @@ 
+// PR c++/44991
+
+class bar {
+    void foo(bool a = 3 < 2, bool b = true) {}
+};