C++ PATCH: PR 29730

Mark Mitchell mark@codesourcery.com
Wed Dec 6 22:54:00 GMT 2006


This patch fixes PR c++/29730, an ICE-on-invalid regression with an
attempt to initialize a function.  Fixed by having the parser reject
and ignore such initializations.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.  I will
apply this to 4.2 and 4.1 once testing completes.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2006-12-06  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29730
	* parser.c (cp_parser_init_declarator): Reject initialization of
	functions.

2006-12-06  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29730
	* g++.dg/template/crash64.C: New test.
	* g++.dg/parse/crash27.C: Adjust error markers.

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 119575)
+++ gcc/cp/parser.c	(working copy)
@@ -11311,9 +11311,23 @@ cp_parser_init_declarator (cp_parser* pa
   is_non_constant_init = true;
   if (is_initialized)
     {
-      if (function_declarator_p (declarator)
-	  && initialization_kind == CPP_EQ)
-	initializer = cp_parser_pure_specifier (parser);
+      if (function_declarator_p (declarator))
+	{
+	   if (initialization_kind == CPP_EQ)
+	     initializer = cp_parser_pure_specifier (parser);
+	   else
+	     {
+	       /* If the declaration was erroneous, we don't really
+		  know what the user intended, so just silently
+		  consume the initializer.  */
+	       if (decl != error_mark_node)
+		 error ("initializer provided for function");
+	       cp_parser_skip_to_closing_parenthesis (parser,
+						      /*recovering=*/true,
+						      /*or_comma=*/false,
+						      /*consume_paren=*/true);
+	     }
+	}
       else
 	initializer = cp_parser_initializer (parser,
 					     &is_parenthesized_init,
Index: gcc/testsuite/g++.dg/parse/crash27.C
===================================================================
--- gcc/testsuite/g++.dg/parse/crash27.C	(revision 119478)
+++ gcc/testsuite/g++.dg/parse/crash27.C	(working copy)
@@ -3,6 +3,3 @@
 void Dispatcher()
 	 (__builtin_offsetof (ArgsType, largeMsgLen))
 	/* { dg-error "function " "function" { target *-*-* } 4 } */
-	/* { dg-error "expected type" "expected 1" { target *-*-* } 4 } */
-	/* { dg-error "expected `,' before" "expected 2" { target *-*-* } 4 } */
-	/* { dg-error "expected `\\\)" "expected 3" { target *-*-* } 4 } */
Index: gcc/testsuite/g++.dg/template/crash64.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash64.C	(revision 0)
+++ gcc/testsuite/g++.dg/template/crash64.C	(revision 0)
@@ -0,0 +1,6 @@
+// PR c++/29730
+
+struct A
+{
+  template<int> void foo()(0); // { dg-error "initializer" } 
+};



More information about the Gcc-patches mailing list