[patch] Fix PR c++/27398 by fixing the return values of grokdeclarator

Volker Reichelt reichelt@igpm.rwth-aachen.de
Thu May 18 21:32:00 GMT 2006


Concerning a different PR (PR27315), Mark wrote:

  In fact, grokdeclarator *should* always return error_mark_node to
  indicate error; the fact that it still returns NULL_TREE and/or
  void_type_node sometimes is just lingering nastiness.

This patch replaces all 10 occurrences of "return void_type_node;" and
"return NULL_TREE;" by "return error_mark_node;" in grokdeclarator.
The fact that this indeed cures PR 27398 (a 4.1/4.2 regression) is just
another proof for Mark's claim.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?

I haven't tested the 4.1 branch yet.

Regards,
Volker

:ADDPATCH C++:


2006-05-18  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27398
	* decl.c (grokdeclarator): Return error_mark_node instead NULL_TREE
	or void_type_node.

===================================================================
--- gcc/gcc/cp/decl.c	(revision 113772)
+++ gcc/gcc/cp/decl.c	(working copy)
@@ -7285,7 +7285,7 @@ grokdeclarator (const cp_declarator *declarator,
   if (dependent_name && !friendp)
     {
       error ("%<%T::%D%> is not a valid declarator", ctype, dependent_name);
-      return void_type_node;
+      return error_mark_node;
     }
 
   /* Issue errors about use of storage classes for parameters.  */
@@ -7529,7 +7529,7 @@ grokdeclarator (const cp_declarator *declarator,
 		    && !member_function_or_else (ctype,
 						 current_class_type,
 						 flags))
-		  return void_type_node;
+		  return error_mark_node;
 
 		if (flags != DTOR_FLAG)
 		  {
@@ -7543,7 +7543,7 @@ grokdeclarator (const cp_declarator *declarator,
 		      }
 		    if (decl_context == FIELD
 			&& sfk != sfk_constructor)
-		      return NULL_TREE;
+		      return error_mark_node;
 		  }
 		if (decl_context == FIELD)
 		  staticp = 0;
@@ -8148,7 +8148,7 @@ grokdeclarator (const cp_declarator *declarator,
 		  {
 		    error ("can't make %qD into a method -- not in a class",
 			   unqualified_id);
-		    return void_type_node;
+		    return error_mark_node;
 		  }
 
 		/* ``A union may [ ... ] not [ have ] virtual functions.''
@@ -8157,7 +8157,7 @@ grokdeclarator (const cp_declarator *declarator,
 		  {
 		    error ("function %qD declared virtual inside a union",
 			   unqualified_id);
-		    return void_type_node;
+		    return error_mark_node;
 		  }
 
 		if (NEW_DELETE_OPNAME_P (unqualified_id))
@@ -8259,7 +8259,7 @@ grokdeclarator (const cp_declarator *declarator,
 			       funcdef_flag, template_count, in_namespace,
 			       attrlist);
 	    if (decl == NULL_TREE)
-	      return NULL_TREE;
+	      return error_mark_node;
 	  }
 	else if (!staticp && !dependent_type_p (type)
 		 && !COMPLETE_TYPE_P (complete_type (type))
@@ -8316,7 +8316,7 @@ grokdeclarator (const cp_declarator *declarator,
 		return decl;
 	      }
 	    else
-	      return void_type_node;
+	      return error_mark_node;
 	  }
 
 	/* Structure field.  It may not be a function, except for C++.  */
@@ -8355,7 +8355,7 @@ grokdeclarator (const cp_declarator *declarator,
 		     void_type_node, as if this was a friend
 		     declaration, to cause callers to completely
 		     ignore this declaration.  */
-		  return void_type_node;
+		  return error_mark_node;
 	      }
 
 	    if (staticp)
@@ -8403,7 +8403,7 @@ grokdeclarator (const cp_declarator *declarator,
 	int publicp = 0;
 
 	if (!unqualified_id)
-	  return NULL_TREE;
+	  return error_mark_node;
 
 	if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
 	  original_name = dname;
@@ -8458,7 +8458,7 @@ grokdeclarator (const cp_declarator *declarator,
 			   publicp, inlinep, sfk, funcdef_flag,
 			   template_count, in_namespace, attrlist);
 	if (decl == NULL_TREE)
-	  return NULL_TREE;
+	  return error_mark_node;
 
 	if (staticp == 1)
 	  {
===================================================================

2006-05-18  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27398
	* g++.dg/template/crash50.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/template/crash50.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/template/crash50.C	2006-05-17 16:43:33 +0200
@@ -0,0 +1,7 @@
+// PR c++/27398
+// { dg-do compile }
+
+struct A
+{
+  template<int> void* foo(; // { dg-error "primary-expression|initialization|static" }
+};
===================================================================




More information about the Gcc-patches mailing list