re PR c++/26122 (Pure specifiers for templates causing trouble)
authorMark Mitchell <mark@codesourcery.com>
Wed, 17 May 2006 21:39:07 +0000 (21:39 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 17 May 2006 21:39:07 +0000 (21:39 +0000)
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.
PR c++/26122
* g++.old-deja/g++.oliva/template9.C: Remove XFAIL.

From-SVN: r113873

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.oliva/template9.C

index 3c93c355f1a4f51f1cacdda402f0ef63d4bc01ed..0d990506d028951fce0258b07848cc96068aa4e4 100644 (file)
@@ -1,5 +1,12 @@
 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.
+
        PR c++/26068
        * parser.c (cp_parser_set_storage_class): Check for 
        invalid uses of storage classes on unbraced linkage
index f75c4ab602aeb9d35ede97c23dfcaed6edd60483..27b88f06b526f722a962b17a183ddf6ae25858e2 100644 (file)
@@ -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 c6124835599548949b4be862ddd85098c5c5df10..e80b8ee09d957790e48c0b45cd29d8b88815f9e8 100644 (file)
@@ -7664,7 +7664,12 @@ cp_parser_function_specifier_opt (cp_parser* parser,
       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* parser)
   /* 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 b5f5dca03557ca525c96e9b544089a2937183e15..9cf94049cf820acf6a962c0401d948d7888dbeba 100644 (file)
@@ -1,5 +1,8 @@
 2006-05-17  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/26122
+       * g++.old-deja/g++.oliva/template9.C: Remove XFAIL.
+
        PR c++/26068
        * g++.dg/opt/pr17697-3.C: Remove invalid extern specifier.
        * g++.dg/parse/linkage1.C: New test.
index c237dbc58485b0246e37eb21599aa7fe4b1570a9..02be37a5f9977b10d8ca4831fbcc3c5882656bd7 100644 (file)
@@ -7,5 +7,5 @@
 
 struct foo {
   template <class>
-  void bar() = 0; // { dg-error "" "" { xfail *-*-* } } invalid initializer - 
+  void bar() = 0; // { dg-error "virtual" }
 };