]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/29729 (ICE with template class in template function)
authorMark Mitchell <mark@codesourcery.com>
Wed, 6 Dec 2006 05:12:46 +0000 (05:12 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 6 Dec 2006 05:12:46 +0000 (05:12 +0000)
PR c++/29729
* decl2.c (check_member_template): Move check for member
templates in local classes to ...
* parser.c (cp_parser_template_declaration_after_export):
... here.
PR c++/29729
* g++.dg/template/crash63.C: New test.

From-SVN: r119575

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

index d9de3612f7430d316be3e82ed058fc4db41baa9f..9e63aca5e8a1cf93ee6ac848fc9a9a5294f173da 100644 (file)
@@ -1,5 +1,11 @@
 2006-12-05  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/29729
+       * decl2.c (check_member_template): Move check for member
+       templates in local classes to ...
+       * parser.c (cp_parser_template_declaration_after_export):
+       ... here.
+
        PR c++/29728
        * decl.c (check_array_designated_initializer): New function.
        (maybe_deduce_size_from_array_init): Use it.
index 43889181f2f1e8a7e6de084472808d88c4f0ef19..b2a97ff9dc2c213372ba6ee93f85bb9b943d7c13 100644 (file)
@@ -445,13 +445,8 @@ check_member_template (tree tmpl)
       || (TREE_CODE (decl) == TYPE_DECL
          && IS_AGGR_TYPE (TREE_TYPE (decl))))
     {
-      if (current_function_decl)
-       /* 14.5.2.2 [temp.mem]
-
-          A local class shall not have member templates.  */
-       error ("invalid declaration of member template %q#D in local class",
-              decl);
-
+      /* The parser rejects template declarations in local classes.  */
+      gcc_assert (!current_function_decl);
       /* The parser rejects any use of virtual in a function template.  */
       gcc_assert (!(TREE_CODE (decl) == FUNCTION_DECL
                    && DECL_VIRTUAL_P (decl)));
index 3ed7497624298641d14e3f23147cb8d4f6e1ab43..82ee8873355adace8ac39de8932f21d53fce9bfe 100644 (file)
@@ -15696,6 +15696,15 @@ cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p)
   /* And the `<'.  */
   if (!cp_parser_require (parser, CPP_LESS, "`<'"))
     return;
+  if (at_class_scope_p () && current_function_decl)
+    {
+      /* 14.5.2.2 [temp.mem]
+
+         A local class shall not have member templates.  */
+      error ("invalid declaration of member template in local class");
+      cp_parser_skip_to_end_of_block_or_statement (parser);
+      return;
+    }
   /* [temp]
 
      A template ... shall not have C linkage.  */
index d7bae48f0a102725c2209eee2dfc8c5a9144f4fd..089232fa404a7d28fc4b89311dc5a3568f678da5 100644 (file)
@@ -1,5 +1,8 @@
 2006-12-05  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/29729
+       * g++.dg/template/crash63.C: New test.
+
        PR c++/29728
        * g++.dg/template/crash62.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/template/crash63.C b/gcc/testsuite/g++.dg/template/crash63.C
new file mode 100644 (file)
index 0000000..b7056e8
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/29729
+
+template<typename T> void foo(T)
+{
+  struct A
+  {
+    template<int> struct B // { dg-error "local class" }
+    {
+      typedef B<0> C;
+    }
+  };
+}