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 ();

Reply via email to