diff options
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r-- | gcc/cp/pt.cc | 76 |
1 files changed, 63 insertions, 13 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index f7c56a1..a71705f 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -11117,6 +11117,18 @@ any_template_parm_r (tree t, void *data) case LAMBDA_EXPR: { + /* TREE_STATIC on LAMBDA_EXPR_EXTRA_ARGS means a full set of + arguments, so we can just look there; they will replace + any template parms in the rest of the LAMBDA_EXPR. */ + if (tree args = LAMBDA_EXPR_EXTRA_ARGS (t)) + { + WALK_SUBTREE (args); + /* Without TREE_STATIC the args are just outer levels, so we'd + still need to look through the lambda for just inner + parameters. Hopefully that's not necessary. */ + gcc_checking_assert (TREE_STATIC (args)); + return 0; + } /* Look in the parms and body. */ tree fn = lambda_function (t); WALK_SUBTREE (TREE_TYPE (fn)); @@ -11760,6 +11772,10 @@ tsubst_friend_function (tree decl, tree args) elt.args = DECL_TI_ARGS (spec); elt.spec = NULL_TREE; + if (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (DECL_TI_ARGS (spec)) + && !is_specialization_of_friend (spec, new_template)) + continue; + decl_specializations->remove_elt (&elt); tree& spec_args = DECL_TI_ARGS (spec); @@ -12413,6 +12429,8 @@ apply_late_template_attributes (tree *decl_p, tree attributes, int attr_flags, auto o4 = make_temp_override (scope_chain->omp_declare_target_attribute, NULL); auto o5 = make_temp_override (scope_chain->omp_begin_assumes, NULL); + auto o6 = make_temp_override (target_option_current_node, + target_option_default_node); cplus_decl_attributes (decl_p, late_attrs, attr_flags); @@ -13736,11 +13754,12 @@ add_extra_args (tree extra, tree args, tsubst_flags_t complain, tree in_decl) inst = local; /* else inst is already a full instantiation of the pack. */ register_local_specialization (inst, gen); + if (is_normal_capture_proxy (gen)) + register_local_specialization (inst, DECL_CAPTURED_VARIABLE (gen)); } gcc_assert (!TREE_PURPOSE (extra)); extra = TREE_VALUE (extra); } - gcc_checking_assert (TREE_STATIC (extra) == uses_template_parms (extra)); if (TREE_STATIC (extra)) /* This is a partial substitution into e.g. a requires-expr or lambda-expr inside a default template argument; we expect 'extra' to be a full set @@ -17741,13 +17760,37 @@ maybe_dependent_member_ref (tree t, tree args, tsubst_flags_t complain, if (TYPE_P (t)) { + bool stripped = false; if (typedef_variant_p (t)) - t = strip_typedefs (t); - tree decl = TYPE_NAME (t); + { + /* Since this transformation may undesirably turn a deduced context + into a non-deduced one, we'd rather strip typedefs than perform + the transformation. */ + tree u = strip_typedefs (t); + if (u != t) + { + stripped = true; + t = u; + } + } + decl = TYPE_NAME (t); if (decl) decl = maybe_dependent_member_ref (decl, args, complain, in_decl); if (!decl) - return NULL_TREE; + { + if (stripped) + /* The original type was an alias from the current instantiation + which we stripped to something outside it. At this point we + need to commit to using the stripped type rather than deferring + to the caller (which would use the original type), to ensure + eligible bits of the stripped type get transformed. */ + return tsubst (t, args, complain, in_decl); + else + /* The original type wasn't a typedef, and we decided it doesn't + need rewriting, so just let the caller (tsubst) substitute it + normally. */ + return NULL_TREE; + } return cp_build_qualified_type (TREE_TYPE (decl), cp_type_quals (t), complain); } @@ -17765,7 +17808,8 @@ maybe_dependent_member_ref (tree t, tree args, tsubst_flags_t complain, if (TREE_CODE (t) == TYPE_DECL) { - if (TREE_CODE (TREE_TYPE (t)) == TYPENAME_TYPE + if (!is_typedef_decl (t) + && TREE_CODE (TREE_TYPE (t)) == TYPENAME_TYPE && TYPE_NAME (TREE_TYPE (t)) == t) /* The TYPE_DECL for a typename has DECL_CONTEXT of the typename scope, but it doesn't need to be rewritten again. */ @@ -22650,7 +22694,7 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain) FUNCTION_DECL which is the desired context for access checking is not built yet. We solve this chicken-and-egg problem by deferring all checks until we have the FUNCTION_DECL. */ - push_deferring_access_checks (dk_deferred); + deferring_access_check_sentinel dacs (dk_deferred); /* Instantiation of the function happens in the context of the function template, not the context of the overload resolution we're doing. */ @@ -22708,10 +22752,13 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain) pop_from_top_level (); if (fndecl == error_mark_node) - { - pop_deferring_access_checks (); - return error_mark_node; - } + return error_mark_node; + + /* Substituting the type might have recursively instantiated this + same alias (c++/117530). */ + if (DECL_ALIAS_TEMPLATE_P (gen_tmpl) + && (spec = retrieve_specialization (gen_tmpl, targ_ptr, hash))) + return spec; /* The DECL_TI_TEMPLATE should always be the immediate parent template, not the most general template. */ @@ -22746,7 +22793,6 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain) access_ok = false; pop_access_scope (fndecl); } - pop_deferring_access_checks (); /* If we've just instantiated the main entry point for a function, instantiate all the alternate entry points as well. We do this @@ -27712,6 +27758,11 @@ instantiate_body (tree pattern, tree args, tree d, bool nested_p) if (DECL_OMP_DECLARE_REDUCTION_P (code_pattern)) cp_check_omp_declare_reduction (d); + + if (int errs = errorcount + sorrycount) + if (errs > current_tinst_level->errors) + if (function *f = DECL_STRUCT_FUNCTION (d)) + f->language->erroneous = true; } /* We're not deferring instantiation any more. */ @@ -30898,9 +30949,8 @@ alias_ctad_tweaks (tree tmpl, tree uguides) tree aguides = NULL_TREE; tree atparms = INNERMOST_TEMPLATE_PARMS (fullatparms); unsigned natparms = TREE_VEC_LENGTH (atparms); - for (ovl_iterator iter (uguides); iter; ++iter) + for (tree f : lkp_range (uguides)) { - tree f = *iter; tree in_decl = f; location_t loc = DECL_SOURCE_LOCATION (f); tree ret = TREE_TYPE (TREE_TYPE (f)); |