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 26122


This patch fixes (the last bit of) PR c++/26122, which is a complaint
about the fact that we allow pure specifiers on member templates.  I
also moved the check for virtual member templates to the parser,
thereby avoiding the possibility of having a TEMPLATE_DECL with
DECL_VIRTUAL set -- along the lines of previous discussions about
avoiding representations of invalid things.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.  I do not
plan to apply this to 4.1, as I have no evidence that this is a
regression.

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

2006-05-17  Mark Mitchell  <mark@codesourcery.com>

	PR c++/26122
	* decl2.c (check_member_template): Remove checks for virtual
	functions.
	* parser.c (cp_parser_function_specifier_opt): Complain about
	virtual templates.
	(cp_parser_pure_specifier): Likewise.

2006-05-17  Mark Mitchell  <mark@codesourcery.com>

	PR c++/26122
	* g++.old-deja/g++.oliva/template9.C: Remove XFAIL.

Index: gcc/cp/decl2.c
===================================================================
--- gcc/cp/decl2.c	(revision 113869)
+++ gcc/cp/decl2.c	(working copy)
@@ -452,16 +452,9 @@ check_member_template (tree tmpl)
 	error ("invalid declaration of member template %q#D in local class",
 	       decl);
 
-      if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
-	{
-	  /* 14.5.2.3 [temp.mem]
-
-	     A member function template shall not be virtual.  */
-	  error
-	    ("invalid use of %<virtual%> in template declaration of %q#D",
-	     decl);
-	  DECL_VIRTUAL_P (decl) = 0;
-	}
+      /* The parser rejects any use of virtual in a function template.  */
+      gcc_assert (!(TREE_CODE (decl) == FUNCTION_DECL
+		    && DECL_VIRTUAL_P (decl)));
 
       /* The debug-information generating code doesn't know what to do
 	 with member templates.  */
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 113869)
+++ gcc/cp/parser.c	(working copy)
@@ -7664,7 +7664,12 @@ cp_parser_function_specifier_opt (cp_par
       break;
 
     case RID_VIRTUAL:
-      if (decl_specs)
+      /* 14.5.2.3 [temp.mem]
+	 
+         A member function template shall not be virtual.  */
+      if (PROCESSING_REAL_TEMPLATE_DECL_P ())
+	error ("templates may not be %<virtual%>");
+      else if (decl_specs)
 	++decl_specs->specs[(int) ds_virtual];
       break;
 
@@ -13864,12 +13869,20 @@ cp_parser_pure_specifier (cp_parser* par
   /* Look for the `0' token.  */
   token = cp_lexer_consume_token (parser->lexer);
   /* c_lex_with_flags marks a single digit '0' with PURE_ZERO.  */
-  if (token->type == CPP_NUMBER && (token->flags & PURE_ZERO))
-    return integer_zero_node;
+  if (token->type != CPP_NUMBER || !(token->flags & PURE_ZERO))
+    {
+      cp_parser_error (parser, 
+		       "invalid pure specifier (only `= 0' is allowed)");
+      cp_parser_skip_to_end_of_statement (parser);
+      return error_mark_node;
+    }
+  if (PROCESSING_REAL_TEMPLATE_DECL_P ())
+    {
+      error ("templates may not be %<virtual%>");
+      return error_mark_node;
+    }
 
-  cp_parser_error (parser, "invalid pure specifier (only `= 0' is allowed)");
-  cp_parser_skip_to_end_of_statement (parser);
-  return error_mark_node;
+  return integer_zero_node;
 }
 
 /* Parse a constant-initializer.
Index: gcc/testsuite/g++.old-deja/g++.oliva/template9.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.oliva/template9.C	(revision 113869)
+++ gcc/testsuite/g++.old-deja/g++.oliva/template9.C	(working copy)
@@ -7,5 +7,5 @@
 
 struct foo {
   template <class>
-  void bar() = 0; // { dg-error "" "" { xfail *-*-* } } invalid initializer - 
+  void bar() = 0; // { dg-error "virtual" }
 };


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