From patchwork Mon Oct 24 16:27:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 59358 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 282943856145 for ; Mon, 24 Oct 2022 16:28:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 282943856145 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666628887; bh=WO2DcSeCILIQS7zLJPf/VTpDCL//o3G5s0KGNpA1gbs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uvoXT4G1J55OGzKVpHx30wRfvzW4ohhvTWkHpWLpIOh3osbpz1rpUkCvS1YLWlxez 9KbIlZl51c6FYoft9ww2pzNGqHtRhAgp8d/ocOSPylWtnaJtZyqyiHKVP4EH/Ofy6X PhuXBl8y0JcsVh+eIT2B/b4qCcMNR2+W9P4zo6k4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id ED19D385696E for ; Mon, 24 Oct 2022 16:27:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED19D385696E Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-50-RuWwQfQJOAe_s_enm0YeCw-1; Mon, 24 Oct 2022 12:27:30 -0400 X-MC-Unique: RuWwQfQJOAe_s_enm0YeCw-1 Received: by mail-qk1-f200.google.com with SMTP id bi38-20020a05620a31a600b006eeb2862816so9390522qkb.0 for ; Mon, 24 Oct 2022 09:27:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WO2DcSeCILIQS7zLJPf/VTpDCL//o3G5s0KGNpA1gbs=; b=x4YD+utIEGmKjBR77/o2NpqAofnQeWS63Jp0WVO5mWp7rRYfLrlHjpePAHsvQ1PKkE fXoX/7Wm24wdFR3FstwYdvsCK09xRU64/Xx635K9kFWhhRqppBYTL6DGkMJHJxbrJ+En DrbXX23yynsUwV7u2FltUiLP1MUdh0B8jXVYV47t8ebZGimMCv9UBGIRmjnU5ST89sbN q8X0X2FWp0d5oIATboFF8TA9FZjy2XkMnvtDN+tX6/7KoywNjbFOBbnAuMyDTOGwNBTw bDVkN//QS5UVarHOvIvoJvxa8mNxSDYqnAn9+97KNbz4UdN+8AbBLGmPUN8A7gvbGAP2 lzzg== X-Gm-Message-State: ACrzQf1ckYmFKlRxzJvbijMKZS5+l9M3/GGz96+jBEVGt3D9O/8RB8EX Ndub0eF0aBdcDvGeSPhmbSuKbTXkFWpnq2No381ntyeHr6eObtZXPAzEuLuFK8NlcA6AUPCgVxC qXz6bm5oSpErrhdcls7dWXfaRc6gGu5k1r5/9+01a6JceIjwxWlROaswBV92jaNFBWWE= X-Received: by 2002:a05:620a:159a:b0:6f3:3369:ea73 with SMTP id d26-20020a05620a159a00b006f33369ea73mr7235770qkk.174.1666628849588; Mon, 24 Oct 2022 09:27:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/0bdpWYnsgG0D/QzJ43Li1S0zn9E8RXvtrNGJuFbPANfgxFncsDpDaViTc+0ardAwEjkF2Q== X-Received: by 2002:a05:620a:159a:b0:6f3:3369:ea73 with SMTP id d26-20020a05620a159a00b006f33369ea73mr7235736qkk.174.1666628849096; Mon, 24 Oct 2022 09:27:29 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id k124-20020a37ba82000000b006ec09d7d357sm231892qkf.47.2022.10.24.09.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 09:27:28 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: remove use_default_args parm of coerce_template_parms Date: Mon, 24 Oct 2022 12:27:26 -0400 Message-Id: <20221024162726.3463437-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.1.143.g1fc3c0ad40 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" It looks like the parameter use_default_args introduced in r110693 is effectively unused ever since r7-5536-g3c75aaa3d884ef removed the last (and probably only) 'coerce_template_parms (..., true, false)' call, so this patch gets rid of it. In passing, I noticed we currently define wrapper overloads of coerce_template_parms that effectively default complain and require_all_args, but it seems cleaner to specify default arguments for the main overload instead. And I suppose we should also give c_innermost_t_p the same defaults. However, I'm not sure about defaulting complain to tf_none since it's contrary to how we default every other complain parameter to either tf_error or tf_warning_or_error (for sake of non-SFINAE callers), so this tf_none default seems surprising. And since just three callers (all in constraint.cc) use this complain=tf_none default, and just one caller (determine_specialization) passes complain=tf_warning_or_error, it seems best to just not default complain here. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: * constraint.cc (resolve_function_concept_overload): Explicitly pass tf_none to coerce_template_parms. (resolve_concept_check): Likewise. (normalize_concept_check): Likewise. * cp-tree.h (coerce_template_parms): Declare the main overload and default its last parameter to true. Remove other overloads. * pt.cc (determine_specialization): Adjust calls to coerce_template_parms and coerce_innermost_template_parms after removing their last parameter. (coerce_template_args_for_ttp): Likewise. (coerce_ttp_args_for_tta): Likewise. (coerce_template_template_parms): Likewise. (coerce_template_parms): Remove use_default_args parameter. Remove wrapper overloads. No longer static. (coerce_innermost_template_parms): Remove use_default_args parameter. (lookup_template_class): As with determine_specialization. (finish_template_variable): Likewise. (tsubst_decl): Likewise. (instantiate_alias_template): Likewise. (fn_type_unification): Likewise. (resolve_overloaded_unification): Likewise. (resolve_nondeduced_context): Likewise. (get_partial_spec_bindings): Likewise. --- gcc/cp/constraint.cc | 6 +-- gcc/cp/cp-tree.h | 4 +- gcc/cp/pt.cc | 107 +++++++++++-------------------------------- 3 files changed, 32 insertions(+), 85 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 74898ca1a23..5e6a3bcf059 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -323,7 +323,7 @@ resolve_function_concept_overload (tree ovl, tree args) /* Remember the candidate if we can deduce a substitution. */ ++processing_template_decl; tree parms = TREE_VALUE (DECL_TEMPLATE_PARMS (tmpl)); - if (tree subst = coerce_template_parms (parms, args, tmpl)) + if (tree subst = coerce_template_parms (parms, args, tmpl, tf_none)) { if (subst == error_mark_node) ++nerrs; @@ -404,7 +404,7 @@ resolve_concept_check (tree check) tree args = TREE_OPERAND (id, 1); tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (tmpl)); ++processing_template_decl; - tree result = coerce_template_parms (parms, args, tmpl); + tree result = coerce_template_parms (parms, args, tmpl, tf_none); --processing_template_decl; if (result == error_mark_node) return error_mark_node; @@ -726,7 +726,7 @@ normalize_concept_check (tree check, tree args, norm_info info) /* Turn on template processing; coercing non-type template arguments will automatically assume they're non-dependent. */ ++processing_template_decl; - tree subst = coerce_template_parms (parms, targs, tmpl); + tree subst = coerce_template_parms (parms, targs, tmpl, tf_none); --processing_template_decl; if (subst == error_mark_node) return error_mark_node; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 60a25101049..b210943ab25 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7459,8 +7459,8 @@ extern tree get_function_template_decl (const_tree); extern tree resolve_nondeduced_context (tree, tsubst_flags_t); extern tree resolve_nondeduced_context_or_error (tree, tsubst_flags_t); extern hashval_t iterative_hash_template_arg (tree arg, hashval_t val); -extern tree coerce_template_parms (tree, tree, tree); -extern tree coerce_template_parms (tree, tree, tree, tsubst_flags_t); +extern tree coerce_template_parms (tree, tree, tree, tsubst_flags_t, + bool = true); extern tree canonicalize_type_argument (tree, tsubst_flags_t); extern void register_local_specialization (tree, tree); extern tree retrieve_local_specialization (tree); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1289aabec75..9882ee6d9ce 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -148,10 +148,8 @@ static void add_pending_template (tree); static tree reopen_tinst_level (struct tinst_level *); static tree tsubst_initializer_list (tree, tree); static tree get_partial_spec_bindings (tree, tree, tree); -static tree coerce_template_parms (tree, tree, tree, tsubst_flags_t, - bool, bool); static tree coerce_innermost_template_parms (tree, tree, tree, tsubst_flags_t, - bool, bool); + bool = true); static void tsubst_enum (tree, tree, tree); static bool check_instantiated_args (tree, tree, tsubst_flags_t); static int check_non_deducible_conversion (tree, tree, unification_kind_t, int, @@ -2172,8 +2170,7 @@ determine_specialization (tree template_id, { tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (fns)); targs = coerce_template_parms (parms, explicit_targs, fns, - tf_warning_or_error, - /*req_all*/true, /*use_defarg*/true); + tf_warning_or_error); if (targs != error_mark_node && constraints_satisfied_p (fns, targs)) templates = tree_cons (targs, fns, templates); @@ -7833,10 +7830,7 @@ coerce_template_args_for_ttp (tree templ, tree arglist, arglist = add_to_template_args (outer, arglist); tree parmlist = DECL_INNERMOST_TEMPLATE_PARMS (templ); - return coerce_template_parms (parmlist, arglist, templ, - complain, - /*require_all_args=*/true, - /*use_default_args=*/true); + return coerce_template_parms (parmlist, arglist, templ, complain); } /* A cache of template template parameters with match-all default @@ -7910,9 +7904,7 @@ coerce_ttp_args_for_tta (tree& arg, tree pargs, tsubst_flags_t complain) { tree aparms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (arg_tmpl)); - pargs = coerce_template_parms (aparms, pargs, arg_tmpl, complain, - /*require_all*/true, - /*use_default*/true); + pargs = coerce_template_parms (aparms, pargs, arg_tmpl, complain); } --processing_template_decl; return pargs; @@ -8079,8 +8071,7 @@ coerce_template_template_parms (tree parm_parms_full, pargs = add_to_template_args (outer_args, pargs); } - pargs = coerce_template_parms (arg_parms, pargs, NULL_TREE, tf_none, - /*require_all*/true, /*use_default*/true); + pargs = coerce_template_parms (arg_parms, pargs, NULL_TREE, tf_none); if (pargs != error_mark_node) { tree targs = make_tree_vec (nargs); @@ -8840,19 +8831,16 @@ pack_expansion_args_count (tree args) warning messages are issued under control of COMPLAIN. If REQUIRE_ALL_ARGS is false, argument deduction will be performed - for arguments not specified in ARGS. Otherwise, if - USE_DEFAULT_ARGS is true, default arguments will be used to fill in - unspecified arguments. If REQUIRE_ALL_ARGS is true, but - USE_DEFAULT_ARGS is false, then all arguments must be specified in - ARGS. */ + for arguments not specified in ARGS. If REQUIRE_ALL_ARGS is true, + arguments not specified in ARGS must have default arguments with + which we'll fill in ARGS. */ -static tree +tree coerce_template_parms (tree parms, tree args, tree in_decl, tsubst_flags_t complain, - bool require_all_args, - bool use_default_args) + bool require_all_args /* = true */) { int nparms, nargs, parm_idx, arg_idx, lost = 0; tree orig_inner_args; @@ -8913,9 +8901,8 @@ coerce_template_parms (tree parms, || (nargs < nparms - variadic_p && require_all_args && !variadic_args_p - && (!use_default_args - || (TREE_VEC_ELT (parms, nargs) != error_mark_node - && !TREE_PURPOSE (TREE_VEC_ELT (parms, nargs)))))) + && (TREE_VEC_ELT (parms, nargs) != error_mark_node + && !TREE_PURPOSE (TREE_VEC_ELT (parms, nargs))))) { bad_nargs: if (complain & tf_error) @@ -9183,30 +9170,6 @@ coerce_template_parms (tree parms, return new_inner_args; } -/* Convert all template arguments to their appropriate types, and - return a vector containing the innermost resulting template - arguments. If any error occurs, return error_mark_node. Error and - warning messages are not issued. - - Note that no function argument deduction is performed, and default - arguments are used to fill in unspecified arguments. */ -tree -coerce_template_parms (tree parms, tree args, tree in_decl) -{ - return coerce_template_parms (parms, args, in_decl, tf_none, true, true); -} - -/* Convert all template arguments to their appropriate type, and - instantiate default arguments as needed. This returns a vector - containing the innermost resulting template arguments, or - error_mark_node if unsuccessful. */ -tree -coerce_template_parms (tree parms, tree args, tree in_decl, - tsubst_flags_t complain) -{ - return coerce_template_parms (parms, args, in_decl, complain, true, true); -} - /* Like coerce_template_parms. If PARMS represents all template parameters levels, this function returns a vector of vectors representing all the resulting argument levels. Note that in this @@ -9219,11 +9182,10 @@ coerce_template_parms (tree parms, tree args, tree in_decl, static tree coerce_innermost_template_parms (tree parms, - tree args, - tree in_decl, - tsubst_flags_t complain, - bool require_all_args, - bool use_default_args) + tree args, + tree in_decl, + tsubst_flags_t complain, + bool require_all_args /* = true */) { int parms_depth = TMPL_PARMS_DEPTH (parms); int args_depth = TMPL_ARGS_DEPTH (args); @@ -9243,8 +9205,7 @@ coerce_innermost_template_parms (tree parms, if (cur_depth == args_depth) l = coerce_template_parms (TREE_VALUE (level), args, in_decl, complain, - require_all_args, - use_default_args); + require_all_args); else l = TMPL_ARGS_LEVEL (args, cur_depth); @@ -9257,8 +9218,7 @@ coerce_innermost_template_parms (tree parms, else coerced_args = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parms), args, in_decl, complain, - require_all_args, - use_default_args); + require_all_args); return coerced_args; } @@ -9953,9 +9913,7 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context, actually tsubst'd into the definition to create the instantiation. */ arglist = coerce_innermost_template_parms (parmlist, arglist, gen_tmpl, - complain, - /*require_all_args=*/true, - /*use_default_args=*/true); + complain); if (arglist == error_mark_node) /* We were unable to bind the arguments. */ @@ -10371,9 +10329,7 @@ finish_template_variable (tree var, tsubst_flags_t complain) tree arglist = TREE_OPERAND (var, 1); tree parms = DECL_TEMPLATE_PARMS (templ); - arglist = coerce_innermost_template_parms (parms, arglist, templ, complain, - /*req_all*/true, - /*use_default*/true); + arglist = coerce_innermost_template_parms (parms, arglist, templ, complain); if (arglist == error_mark_node) return error_mark_node; @@ -15022,8 +14978,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) the template. */ argvec = (coerce_innermost_template_parms (DECL_TEMPLATE_PARMS (gen_tmpl), - argvec, t, complain, - /*all*/true, /*defarg*/true)); + argvec, t, complain)); if (argvec == error_mark_node) RETURN (error_mark_node); hash = spec_hasher::hash (gen_tmpl, argvec); @@ -21956,11 +21911,8 @@ instantiate_alias_template (tree tmpl, tree args, tsubst_flags_t complain) if (tmpl == error_mark_node || args == error_mark_node) return error_mark_node; - args = - coerce_innermost_template_parms (DECL_TEMPLATE_PARMS (tmpl), - args, tmpl, complain, - /*require_all_args=*/true, - /*use_default_args=*/true); + args = coerce_innermost_template_parms (DECL_TEMPLATE_PARMS (tmpl), + args, tmpl, complain); /* FIXME check for satisfaction in check_instantiated_args. */ if (flag_concepts @@ -22210,8 +22162,7 @@ fn_type_unification (tree fn, explicit_targs = (coerce_template_parms (tparms, explicit_targs, fn, complain|tf_partial, - /*require_all_args=*/false, - /*use_default_args=*/false)); + /*require_all_args=*/false)); if (explicit_targs == error_mark_node) goto fail; @@ -23304,9 +23255,7 @@ resolve_overloaded_unification (tree tparms, continue; subargs = coerce_template_parms (DECL_INNERMOST_TEMPLATE_PARMS (fn), - expl_subargs, NULL_TREE, tf_none, - /*require_all_args=*/true, - /*use_default_args=*/true); + expl_subargs, NULL_TREE, tf_none); if (subargs != error_mark_node && !any_dependent_template_arguments_p (subargs)) { @@ -23450,9 +23399,7 @@ resolve_nondeduced_context (tree orig_expr, tsubst_flags_t complain) continue; subargs = coerce_template_parms (DECL_INNERMOST_TEMPLATE_PARMS (fn), - expl_subargs, NULL_TREE, tf_none, - /*require_all_args=*/true, - /*use_default_args=*/true); + expl_subargs, NULL_TREE, tf_none); if (subargs != error_mark_node && !any_dependent_template_arguments_p (subargs)) { @@ -25581,7 +25528,7 @@ get_partial_spec_bindings (tree tmpl, tree spec_tmpl, tree args) if (spec_args != error_mark_node) spec_args = coerce_template_parms (DECL_INNERMOST_TEMPLATE_PARMS (tmpl), INNERMOST_TEMPLATE_ARGS (spec_args), - tmpl, tf_none, false, false); + tmpl, tf_none, false); pop_tinst_level ();