]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/34089 (Segfault on specialization using struct instead of template function.)
authorJakub Jelinek <jakub@redhat.com>
Tue, 20 Nov 2007 16:19:40 +0000 (17:19 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 20 Nov 2007 16:19:40 +0000 (17:19 +0100)
PR c++/34089
* parser.c (cp_parser_class_head): Reject function template ids.

* g++.dg/template/crash74.C: New test.

From-SVN: r130316

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/crash74.C [new file with mode: 0644]

index b7c7661a9048d04f25470d634b2a9fad325e71be..a8025f23820b243f5eb9244259a60dab961071ed 100644 (file)
@@ -1,5 +1,8 @@
 2007-11-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/34089
+       * parser.c (cp_parser_class_head): Reject function template ids.
+
        PR c++/28879
        * tree.c (build_cplus_array_type_1): Don't pass any VLA types
        when processing_template_decl to build_array_type.
index 41cb26e5e0fd862ecd00f9656ef2962dec7502fb..8e16d22335ce1df3d1cce04ac1fced0af44639fb 100644 (file)
@@ -14536,8 +14536,18 @@ cp_parser_class_head (cp_parser* parser,
   /* Look up the type.  */
   if (template_id_p)
     {
-      type = TREE_TYPE (id);
-      type = maybe_process_partial_specialization (type);
+      if (TREE_CODE (id) == TEMPLATE_ID_EXPR
+         && (DECL_FUNCTION_TEMPLATE_P (TREE_OPERAND (id, 0))
+             || TREE_CODE (TREE_OPERAND (id, 0)) == OVERLOAD))
+       {
+         error ("function template %qD redeclared as a class template", id);
+         type = error_mark_node;
+       }
+      else
+       {
+         type = TREE_TYPE (id);
+         type = maybe_process_partial_specialization (type);
+       }
       if (nested_name_specifier)
        pushed_scope = push_scope (nested_name_specifier);
     }
index 3ad61fd676dae3071798cff3fc067f832c0a9a70..18413b35a2ef2b55834bf7f33bdf0fa2677a846d 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/34089
+       * g++.dg/template/crash74.C: New test.
+
 2007-11-20  Richard Guenther  <rguenther@suse.de>
 
        * gcc.c-torture/execute/20071120-1.c: New testcase.
diff --git a/gcc/testsuite/g++.dg/template/crash74.C b/gcc/testsuite/g++.dg/template/crash74.C
new file mode 100644 (file)
index 0000000..9f2e415
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/34089
+// { dg-do compile }
+// { dg-options "" }
+
+template<typename F> void foo () { }
+template<typename F> struct foo<F> { };        // { dg-error "redeclared as" }
This page took 0.14511 seconds and 5 git commands to generate.