@@ -13490,6 +13490,39 @@ template within a real instantiation of a class.
1349013490} /* is_alias_prototype_in_real_instantiation */
1349113491
1349213492
13493+ static a_boolean has_unbound_template_pack(a_pack_expansion_descr_ptr pedp)
13494+ /*
13495+ Return TRUE if the expansion described by pedp references a template parameter
13496+ pack not found in the current or enclosing instantiations. A pack found with
13497+ no argument elements is bound and does not cause TRUE to be returned.
13498+ */
13499+ {
13500+ a_boolean result = FALSE;
13501+ a_pack_reference_ptr prp;
13502+ a_template_param_ptr templ_param_list;
13503+ a_template_arg_ptr templ_arg_list;
13504+
13505+ get_curr_template_params_and_args(&templ_param_list, &templ_arg_list);
13506+ for (prp = pedp->packs_referenced; prp != NULL; prp = prp->next) {
13507+ if (prp->kind == prk_template_param) {
13508+ uint32_t elements;
13509+ a_template_param_ptr tpp;
13510+ a_boolean found;
13511+
13512+ (void)find_template_arg_for_pack(templ_param_list, templ_arg_list,
13513+ prp->symbol, &elements, &tpp, &found,
13514+ /*is_rescan=*/FALSE,
13515+ /*is_deduction=*/FALSE);
13516+ if (!found) {
13517+ result = TRUE;
13518+ break;
13519+ } /* if */
13520+ } /* if */
13521+ } /* for */
13522+ return result;
13523+ } /* has_unbound_template_pack */
13524+
13525+
1349313526static a_boolean is_pack_instantiation_context(
1349413527 a_pack_expansion_descr_ptr *p_pedp)
1349513528/*
@@ -13502,7 +13535,8 @@ Something is treated as an instantiation context if:
1350213535 only uses enclosing packs (e.g., the declaration of a member template
1350313536 in the instantiation of an enclosing class template).
1350413537 - We are in a generic lambda prototype instantiation inside some real
13505- enclosing instantiation.
13538+ enclosing instantiation and have arguments for all referenced template
13539+ parameter packs.
1350613540 - We have real template arguments for all referenced packs.
1350713541
1350813542In such contexts, return TRUE. If we found a pack expansion, set *p_pedp
@@ -13527,7 +13561,9 @@ that *p_pedp is set even when FALSE is returned.
1352713561 result = TRUE;
1352813562 } else if (pedp->uses_any_enclosing_packs &&
1352913563 in_generic_lambda_in_real_instantiation()) {
13530- result = TRUE;
13564+ /* A nested lambda's template parameter defaults can reference packs
13565+ whose prototype arguments have not been created yet. */
13566+ result = !has_unbound_template_pack(pedp);
1353113567 } else if (pedp->uses_only_enclosing_packs) {
1353213568 a_pack_reference_ptr prp;
1353313569 a_template_nesting_depth max_pack_depth = NO_NESTING_DEPTH;
0 commit comments