diff mbox

PR c++/47311

Message ID m3fwsgehwh.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli Jan. 25, 2011, 10:29 p.m. UTC
Jason Merrill <jason@redhat.com> writes:

> On 01/20/2011 10:40 AM, Dodji Seketeli wrote:
>> +      if (incomplete_args_for_template_parm_fixup_p (arglist, parm))
>
> It seems to me that if we do things in the right order, we shouldn't
> need this test.  Can't we arrange to defer fixing up template template
> parameter template parameters some other way than testing what's in
> the arglist?

The idea of changing the signature of some functions to pass down the
information that we are parsing the parameter-list of a template
template parameter during stage 3 made me shudder at first. That's why I
try that other way. I agree this wasn't rational.

The patch below basically adds a flag to
cp_parser_template_parameter_list so it knows when it is processing the
parameters of a template template parm. It passes the information down
to end_template_parm_list that just avoids doing the fixup in that case.

The change of fixup_template_parm is to fixup the parms of a template
template parameter before fixing its type.

Tested on x86_unknown-linux-gnu without boostrap; a full boostrap is
currently running.

Comments

Dodji Seketeli Jan. 26, 2011, 7:23 a.m. UTC | #1
Dodji Seketeli <dodji@redhat.com> writes:

> Tested on x86_unknown-linux-gnu without boostrap; a full boostrap is
> currently running.

It fully bootstrapped and passed regression tests.
Jason Merrill Jan. 26, 2011, 3:31 p.m. UTC | #2
Would it work to call fixup_template_parms from 
cp_parser_template_declaration_after_export instead of adding this flag?

Jason
diff mbox

Patch

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 7500826..3669578 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5024,7 +5024,7 @@  extern tree splice_late_return_type		(tree, tree);
 extern bool is_auto				(const_tree);
 extern tree process_template_parm		(tree, location_t, tree, 
 						 bool, bool, unsigned);
-extern tree end_template_parm_list		(tree);
+extern tree end_template_parm_list		(tree, bool);
 extern void end_template_decl			(void);
 extern tree maybe_update_decl_type		(tree, tree);
 extern bool check_default_tmpl_args             (tree, tree, int, int, int);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 41f82ac..c328639 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2039,7 +2039,7 @@  static tree cp_parser_operator
 static void cp_parser_template_declaration
   (cp_parser *, bool);
 static tree cp_parser_template_parameter_list
-  (cp_parser *);
+  (cp_parser *, bool);
 static tree cp_parser_template_parameter
   (cp_parser *, bool *, bool *);
 static tree cp_parser_type_parameter
@@ -11131,7 +11131,8 @@  cp_parser_template_declaration (cp_parser* parser, bool member_p)
    The nodes are connected via their TREE_CHAINs.  */
 
 static tree
-cp_parser_template_parameter_list (cp_parser* parser)
+cp_parser_template_parameter_list (cp_parser* parser,
+				   bool template_template_parm_p)
 {
   tree parameter_list = NULL_TREE;
 
@@ -11176,7 +11177,8 @@  cp_parser_template_parameter_list (cp_parser* parser)
       cp_lexer_consume_token (parser->lexer);
     }
 
-  return end_template_parm_list (parameter_list);
+  return end_template_parm_list (parameter_list,
+				 template_template_parm_p);
 }
 
 /* Parse a template-parameter.
@@ -11433,7 +11435,7 @@  cp_parser_type_parameter (cp_parser* parser, bool *is_parameter_pack)
 	/* Look for the `<'.  */
 	cp_parser_require (parser, CPP_LESS, RT_LESS);
 	/* Parse the template-parameter-list.  */
-	cp_parser_template_parameter_list (parser);
+	cp_parser_template_parameter_list (parser, true);
 	/* Look for the `>'.  */
 	cp_parser_require (parser, CPP_GREATER, RT_GREATER);
 	/* Look for the `class' keyword.  */
@@ -19920,7 +19922,7 @@  cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p)
     }
   else
     /* Parse the template parameters.  */
-    parameter_list = cp_parser_template_parameter_list (parser);
+    parameter_list = cp_parser_template_parameter_list (parser, false);
 
   /* Get the deferred access checks from the parameter list.  These
      will be checked once we know what is being declared, as for a
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 7d39e1c..f9b2280 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3597,7 +3597,8 @@  process_template_parm (tree list, location_t parm_loc, tree parm,
    as PARM_DECLs.  */
 
 tree
-end_template_parm_list (tree parms)
+end_template_parm_list (tree parms,
+			bool template_template_parm_p)
 {
   int nparms;
   tree parm, next;
@@ -3614,7 +3615,8 @@  end_template_parm_list (tree parms)
       TREE_CHAIN (parm) = NULL_TREE;
     }
 
-  fixup_template_parms ();
+  if (!template_template_parm_p)
+    fixup_template_parms ();
 
   --processing_template_parmlist;
 
@@ -3774,21 +3776,16 @@  fixup_template_parm (tree parm_desc,
     {
       /* PARM is a template template parameter. This is going to
 	 be interesting.  */
-      tree tparms, targs, innermost_args;
+      tree tparms, targs, innermost_args, t;
       int j;
 
-      /* First, fix up the type of the parm.  */
+      /* First, fix up the parms of the template template parm
+	 because the parms are involved in defining the new canonical
+	 type of the template template parm.  */
 
-      tree t =
-	fixup_template_type_parm_type (TREE_TYPE (parm), num_parms);
-      TREE_TYPE (parm) = t;
-
-      TREE_VEC_ELT (fixedup_args, idx) =
-	template_parm_to_arg (parm_desc);
-
-      /* Now we need to substitute the template parm types that
-	 have been fixed up so far into the non-type template
-	 parms of this template template parm. E.g, consider this:
+      /* So we need to substitute the template parm types that have
+	 been fixed up so far into the template parms of this template
+	 template parm. E.g, consider this:
 
 	 template<class T, template<T u> class TT> class S;
 
@@ -3827,6 +3824,14 @@  fixup_template_parm (tree parm_desc,
 			       TREE_VEC_LENGTH (tparms),
 			       targs);
 	}
+
+      /* Now fix up the type of the template template parm.  */
+
+      t = fixup_template_type_parm_type (TREE_TYPE (parm), num_parms);
+      TREE_TYPE (parm) = t;
+
+      TREE_VEC_ELT (fixedup_args, idx) =
+	template_parm_to_arg (parm_desc);
     }
   else if (TREE_CODE (parm) == PARM_DECL)
     {
@@ -3882,7 +3887,7 @@  fixup_template_parm (tree parm_desc,
   pop_deferring_access_checks ();
 }
 
-/* Walk current the template parms and properly compute the canonical
+/* Walk the current template parms and properly compute the canonical
    types of the dependent types created during
    cp_parser_template_parameter_list.  */
 
@@ -3911,8 +3916,6 @@  fixup_template_parms (void)
   arglist = current_template_args ();
   arglist = add_outermost_template_args (arglist, fixedup_args);
 
-  fixedup_args = INNERMOST_TEMPLATE_ARGS (arglist);
-
   /* Let's do the proper fixup now.  */
   for (i = 0; i < num_parms; ++i)
     fixup_template_parm (TREE_VEC_ELT (parameter_vec, i),
diff --git a/gcc/testsuite/g++.dg/template/param2.C b/gcc/testsuite/g++.dg/template/param2.C
new file mode 100644
index 0000000..d25b855
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/param2.C
@@ -0,0 +1,8 @@ 
+// Origin PR c++/47311
+// { dg-do compile }
+
+template < typename > class A0;
+template <class Key, class T, template < typename TF = T> class TC = A0> class B0;
+
+template <int> class A1;
+template <class Key, class T, template <T p> class TC = A1> class B1;