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 28506


This patch fixes an ICE-on-invalid regression whereby we would fail to
diagnose initialization of a function.  We were trying to check if a
particular declaration was a function declaration, by looking at the
declarator, but we were not recurring where necessary.

Tested on x86_64-unknown-linux-gnu, applied to mainline.  I will apply
to 4.1 when testing completes.

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

2006-10-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/28506
	* parser.c (function_declarator_p): New function.
	(cp_parser_init_declarator): Use it.
	(cp_parser_member_declaration): Likewise.

2006-10-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/28506
	* g++.dg/parse/pure1.C: New test.

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 117657)
+++ gcc/cp/parser.c	(working copy)
@@ -965,6 +965,24 @@ make_parameter_declarator (cp_decl_speci
   return parameter;
 }
 
+/* Returns true iff DECLARATOR  is a declaration for a function.  */
+
+static bool
+function_declarator_p (const cp_declarator *declarator)
+{
+  while (declarator)
+    {
+      if (declarator->kind == cdk_function
+	  && declarator->declarator->kind == cdk_id)
+	return true;
+      if (declarator->kind == cdk_id
+	  || declarator->kind == cdk_error)
+	return false;
+      declarator = declarator->declarator;
+    }
+  return false;
+}
+ 
 /* The parser.  */
 
 /* Overview
@@ -11157,8 +11175,7 @@ cp_parser_init_declarator (cp_parser* pa
   is_non_constant_init = true;
   if (is_initialized)
     {
-      if (declarator->kind == cdk_function
-	  && declarator->declarator->kind == cdk_id
+      if (function_declarator_p (declarator)
 	  && initialization_kind == CPP_EQ)
 	initializer = cp_parser_pure_specifier (parser);
       else
@@ -13825,8 +13842,7 @@ cp_parser_member_declaration (cp_parser*
 		     for a pure-specifier; otherwise, we look for a
 		     constant-initializer.  When we call `grokfield', it will
 		     perform more stringent semantics checks.  */
-		  if (declarator->kind == cdk_function
-		      && declarator->declarator->kind == cdk_id)
+		  if (function_declarator_p (declarator))
 		    initializer = cp_parser_pure_specifier (parser);
 		  else
 		    /* Parse the initializer.  */
Index: gcc/testsuite/g++.dg/parse/pure1.C
===================================================================
--- gcc/testsuite/g++.dg/parse/pure1.C	(revision 0)
+++ gcc/testsuite/g++.dg/parse/pure1.C	(revision 0)
@@ -0,0 +1,11 @@
+// PR c++/28506
+
+struct A
+{
+  virtual void* foo() = 1; // { dg-error "pure" }
+};
+
+struct B
+{
+  void operator()()() = 1; // { dg-error "pure|function|initializer" }
+};


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