@@ -16139,13 +16139,37 @@ If there is an error in the copying, set *copy_error to TRUE.
1613916139 template <typename T = int, typename S = C<T> > class A {};
1614016140 */
1614116141 if (new_list != NULL && tpp->def_arg_involves_template_param) {
16142+ a_boolean pushed_rescan_scope = FALSE;
16143+ a_ctws_options_set def_arg_options = options;
16144+ if ((is_class_template_symbol(template_sym) ||
16145+ symbol_is(template_sym, sk_variable_template)) &&
16146+ depth_innermost_instantiation_scope != NO_SCOPE_DEPTH &&
16147+ scope_stack[depth_innermost_instantiation_scope].is_rescan &&
16148+ scope_stack[depth_innermost_instantiation_scope].template_sym !=
16149+ template_sym) {
16150+ /* The default argument belongs to template_sym, so names in it
16151+ must be looked up in the context of template_sym, not in the
16152+ context of an enclosing rescan (e.g., of a partial
16153+ specialization declared before entities that the default
16154+ argument refers to). */
16155+ push_instantiation_scope_for_rescan(template_sym);
16156+ pushed_rescan_scope = TRUE;
16157+ /* Pushing an instantiation scope clears the expression stack.
16158+ Also, a deduced pack would already have been added to the new
16159+ template argument list. */
16160+ def_arg_options &= ~(CTWS_INSIDE_EXPR_RESCAN |
16161+ CTWS_PRESERVE_DEDUCED_PACKS);
16162+ } /* if */
1614216163 substitute_template_argument(tap, tpp, new_list,
1614316164 param_list_for_copy,
1614416165 new_list, param_list_for_copy,
1614516166 source_pos,
16146- options ,
16167+ def_arg_options ,
1614716168 is_generic,
1614816169 copy_error, ctws_state);
16170+ if (pushed_rescan_scope) {
16171+ pop_instantiation_scope_for_rescan();
16172+ } /* if */
1614916173 if (*copy_error) goto done;
1615016174 } /* if */
1615116175 if (new_list == NULL) {
0 commit comments