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 29729


This patch fixes an ICE-on-invalid regression where we got confused by
a member template in a local class.  Fixed by just dropping the
template on the floor in the parser, following the strategy that
invalid stuff should be thrown away as soon as possible to avoid
confusing the rest of the front end.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.  I will
apply to 4.1 and 4.2 once testing completes.

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

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.

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

	PR c++/29729
	* g++.dg/template/crash63.C: New test.

Index: gcc/cp/decl2.c
===================================================================
--- gcc/cp/decl2.c	(revision 119478)
+++ gcc/cp/decl2.c	(working copy)
@@ -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: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 119478)
+++ gcc/cp/parser.c	(working copy)
@@ -15696,6 +15696,15 @@ cp_parser_template_declaration_after_exp
   /* 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: gcc/testsuite/g++.dg/template/crash63.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash63.C	(revision 0)
+++ gcc/testsuite/g++.dg/template/crash63.C	(revision 0)
@@ -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;
+    }
+  };
+}


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