@@ -16139,13 +16139,40 @@ 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 (depth_innermost_instantiation_scope != NO_SCOPE_DEPTH &&
16145+ scope_stack[depth_innermost_instantiation_scope].is_rescan &&
16146+ scope_stack[depth_innermost_instantiation_scope].template_sym !=
16147+ template_sym) {
16148+ /* The default argument belongs to template_sym, so names in it
16149+ must be looked up in the context of template_sym, not in the
16150+ context of an enclosing rescan (e.g., of a partial
16151+ specialization declared before entities that the default
16152+ argument refers to). */
16153+ push_instantiation_scope_for_rescan(template_sym);
16154+ pushed_rescan_scope = TRUE;
16155+ if (scope_is(&scope_stack_top(), sck_function_access)) {
16156+ /* A default template argument is not part of the template, so
16157+ the friends of the template do not have access to it. */
16158+ scope_stack_top().template_sym = NULL;
16159+ } /* if */
16160+ /* Pushing an instantiation scope clears the expression stack.
16161+ Also, a deduced pack would already have been added to the new
16162+ template argument list. */
16163+ def_arg_options &= ~(CTWS_INSIDE_EXPR_RESCAN |
16164+ CTWS_PRESERVE_DEDUCED_PACKS);
16165+ } /* if */
1614216166 substitute_template_argument(tap, tpp, new_list,
1614316167 param_list_for_copy,
1614416168 new_list, param_list_for_copy,
1614516169 source_pos,
16146- options ,
16170+ def_arg_options ,
1614716171 is_generic,
1614816172 copy_error, ctws_state);
16173+ if (pushed_rescan_scope) {
16174+ pop_instantiation_scope_for_rescan();
16175+ } /* if */
1614916176 if (*copy_error) goto done;
1615016177 } /* if */
1615116178 if (new_list == NULL) {
0 commit comments