@@ -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);
@@ -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
@@ -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),
new file mode 100644
@@ -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;