template. */
/* Shortcut looking up the current class scope again. */
- if (current_class_type)
- if (tree ti = CLASSTYPE_TEMPLATE_INFO (current_class_type))
+ for (tree cur = current_nonlambda_class_type ();
+ cur != NULL_TREE;
+ cur = get_containing_scope (cur))
+ {
+ if (!CLASS_TYPE_P (cur))
+ continue;
+
+ tree ti = CLASSTYPE_TEMPLATE_INFO (cur);
+ if (!ti || arg_depth > TMPL_ARGS_DEPTH (TI_ARGS (ti)))
+ break;
+
if (gen_tmpl == most_general_template (TI_TEMPLATE (ti))
&& comp_template_args (arglist, TI_ARGS (ti)))
- return current_class_type;
+ return cur;
+ }
/* Calculate the BOUND_ARGS. These will be the args that are
actually tsubst'd into the definition to create the
instantiation. */
- arglist = coerce_template_parms (parmlist, arglist, gen_tmpl, complain);
+ if (PRIMARY_TEMPLATE_P (gen_tmpl))
+ arglist = coerce_template_parms (parmlist, arglist, gen_tmpl, complain);
if (arglist == error_mark_node)
/* We were unable to bind the arguments. */