From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5A070385840C for ; Mon, 24 Oct 2022 19:57:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5A070385840C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666641422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6EAj3gkhJRe+7hZtU6BHQCA1WvOwhbgTU/HXjTbVVF8=; b=SyFDxI5PrtGFi7tI4O8ne5vCWc+dNRSomuuH9n7usSu7+6omjTP4iEo4x+YunKpQHn3br7 hUUKj7dEbWBSaqYzev6dzyIMnObb09+NB6NCPJDOgodUU0a44UrObtuP+srK98huWGHEMa C2H+Xcy6J88eS9lMCC9HUJFl3t1gqu8= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-328-F8Vx4uW5Mp2UdWuzMUuD2w-1; Mon, 24 Oct 2022 15:57:00 -0400 X-MC-Unique: F8Vx4uW5Mp2UdWuzMUuD2w-1 Received: by mail-qv1-f69.google.com with SMTP id x2-20020a0cff22000000b004bb07bf7557so5077097qvt.11 for ; Mon, 24 Oct 2022 12:57:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6EAj3gkhJRe+7hZtU6BHQCA1WvOwhbgTU/HXjTbVVF8=; b=0PAsHAg2n4L+GEVv/uoAKqLnx6zAsRfXaQe2RFtXFtxZsMzNHsOF2k29uPtTgZXPEV LGWnhkyG65yylY0bvXGIxEBhkwr21mOUfIevgTIy68s0ygWW308ElH4LFyMk+xAHOCdV 63A/v9LHUfqukHkKWOE8E2Q3kWclvZq4RZJYQHBX0/uRHdkZcA6/2NpjoR/IlyMr2q1/ QRGe5iY9780IvAA18QOEFVP6V1AsnjSV/fG3ZKdC5v9EcAuHA8gAKsuxJSmCJ9AFM8Gm 2KLtUBV+tMD7I33EseYrIl0strCj+5PxZkucGPtD3vAbsEh1vNAdalr5E3kF1chI8pH8 KJnQ== X-Gm-Message-State: ACrzQf29rn63osW5HYS9AsAC7bBqyGyvKmBvNjciKuJgqyVF6R2gwsIR hiqOOIsy3urv8f6Frl22JVPGXbcZidGC6QYqrIouS+tKmkcqdpxrqAacc3COC/bCEIfYjXcjTGT CN4+xnYDFSPuCKCAMRA== X-Received: by 2002:ae9:ebc1:0:b0:6ed:6b60:4430 with SMTP id b184-20020ae9ebc1000000b006ed6b604430mr24515562qkg.359.1666641419624; Mon, 24 Oct 2022 12:56:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4JraK6gOqy+SV+e8Kwq0sSuhPk/tcUsaqX//SqPgQcV8GgClmZ9Ty8sYBs3Pf3uy+94nrVhw== X-Received: by 2002:ae9:ebc1:0:b0:6ed:6b60:4430 with SMTP id b184-20020ae9ebc1000000b006ed6b604430mr24515544qkg.359.1666641419182; Mon, 24 Oct 2022 12:56:59 -0700 (PDT) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id r5-20020a05620a298500b006ee7e223bb8sm592273qkp.39.2022.10.24.12.56.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Oct 2022 12:56:58 -0700 (PDT) Message-ID: <97401243-a3c9-733a-44fb-c5522c6efb28@redhat.com> Date: Mon, 24 Oct 2022 15:56:57 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH] c++: remove use_default_args parm of coerce_template_parms To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20221024162726.3463437-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20221024162726.3463437-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 List-Id: On 10/24/22 12:27, Patrick Palka wrote: > 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. Agreed, it's probably better in general not to default complain, that's a source of SFINAE bugs. > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? OK. > 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 (); >