@@ -16139,13 +16139,36 @@ 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+ depth_innermost_instantiation_scope != NO_SCOPE_DEPTH &&
16146+ scope_stack[depth_innermost_instantiation_scope].is_rescan &&
16147+ scope_stack[depth_innermost_instantiation_scope].template_sym !=
16148+ template_sym) {
16149+ /* The default argument belongs to template_sym, so names in it
16150+ must be looked up in the context of template_sym, not in the
16151+ context of an enclosing rescan (e.g., of a partial
16152+ specialization declared before entities that the default
16153+ argument refers to). */
16154+ push_instantiation_scope_for_rescan(template_sym);
16155+ pushed_rescan_scope = TRUE;
16156+ /* Pushing an instantiation scope clears the expression stack.
16157+ Also, a deduced pack would already have been added to the new
16158+ template argument list. */
16159+ def_arg_options &= ~(CTWS_INSIDE_EXPR_RESCAN |
16160+ CTWS_PRESERVE_DEDUCED_PACKS);
16161+ } /* if */
1614216162 substitute_template_argument(tap, tpp, new_list,
1614316163 param_list_for_copy,
1614416164 new_list, param_list_for_copy,
1614516165 source_pos,
16146- options ,
16166+ def_arg_options ,
1614716167 is_generic,
1614816168 copy_error, ctws_state);
16169+ if (pushed_rescan_scope) {
16170+ pop_instantiation_scope_for_rescan();
16171+ } /* if */
1614916172 if (*copy_error) goto done;
1615016173 } /* if */
1615116174 if (new_list == NULL) {
0 commit comments