LCOV - code coverage report
Current view: top level - gcc/cp - call.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.1 % 6404 6153
Test Date: 2026-10-24 16:24:59 Functions: 99.6 % 226 225
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Functions related to invoking C++ methods and overloaded functions.
       2              :    Copyright (C) 1987-2026 Free Software Foundation, Inc.
       3              :    Contributed by Michael Tiemann (tiemann@cygnus.com) and
       4              :    modified by Brendan Kehoe (brendan@cygnus.com).
       5              : 
       6              : This file is part of GCC.
       7              : 
       8              : GCC is free software; you can redistribute it and/or modify
       9              : it under the terms of the GNU General Public License as published by
      10              : the Free Software Foundation; either version 3, or (at your option)
      11              : any later version.
      12              : 
      13              : GCC is distributed in the hope that it will be useful,
      14              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16              : GNU General Public License for more details.
      17              : 
      18              : You should have received a copy of the GNU General Public License
      19              : along with GCC; see the file COPYING3.  If not see
      20              : <http://www.gnu.org/licenses/>.  */
      21              : 
      22              : 
      23              : /* High-level class interface.  */
      24              : 
      25              : #include "config.h"
      26              : #include "system.h"
      27              : #include "coretypes.h"
      28              : #include "target.h"
      29              : #include "cp-tree.h"
      30              : #include "timevar.h"
      31              : #include "stringpool.h"
      32              : #include "cgraph.h"
      33              : #include "stor-layout.h"
      34              : #include "trans-mem.h"
      35              : #include "flags.h"
      36              : #include "toplev.h"
      37              : #include "intl.h"
      38              : #include "convert.h"
      39              : #include "langhooks.h"
      40              : #include "c-family/c-objc.h"
      41              : #include "internal-fn.h"
      42              : #include "attribs.h"
      43              : #include "decl.h"
      44              : #include "c-family/c-type-mismatch.h"
      45              : #include "tristate.h"
      46              : #include "tree-pretty-print-markup.h"
      47              : #include "contracts.h" // maybe_contract_wrap_call
      48              : 
      49              : /* The various kinds of conversion.  */
      50              : 
      51              : enum conversion_kind {
      52              :   ck_identity,
      53              :   ck_lvalue,
      54              :   ck_fnptr,
      55              :   ck_qual,
      56              :   ck_std,
      57              :   ck_ptr,
      58              :   ck_pmem,
      59              :   ck_base,
      60              :   ck_ref_bind,
      61              :   ck_user,
      62              :   ck_ambig,
      63              :   ck_list,
      64              :   ck_aggr,
      65              :   ck_rvalue,
      66              :   /* When LOOKUP_SHORTCUT_BAD_CONVS is set, we may return a conversion of
      67              :      this kind whenever we know the true conversion is either bad or outright
      68              :      invalid, but we don't want to attempt to compute the bad conversion (for
      69              :      sake of avoiding unnecessary instantiation).  bad_p should always be set
      70              :      for these.  */
      71              :   ck_deferred_bad,
      72              : };
      73              : 
      74              : /* The rank of the conversion.  Order of the enumerals matters; better
      75              :    conversions should come earlier in the list.  */
      76              : 
      77              : enum conversion_rank {
      78              :   cr_identity,
      79              :   cr_exact,
      80              :   cr_promotion,
      81              :   cr_std,
      82              :   cr_pbool,
      83              :   cr_user,
      84              :   cr_ellipsis,
      85              :   cr_bad
      86              : };
      87              : 
      88              : /* An implicit conversion sequence, in the sense of [over.best.ics].
      89              :    The first conversion to be performed is at the end of the chain.
      90              :    That conversion is always a cr_identity conversion.  */
      91              : 
      92              : struct conversion {
      93              :   /* The kind of conversion represented by this step.  */
      94              :   conversion_kind kind;
      95              :   /* The rank of this conversion.  */
      96              :   conversion_rank rank;
      97              :   bool user_conv_p : 1;
      98              :   bool ellipsis_p : 1;
      99              :   bool this_p : 1;
     100              :   /* True if this conversion would be permitted with a bending of
     101              :      language standards, e.g. disregarding pointer qualifiers or
     102              :      converting integers to pointers.  */
     103              :   bool bad_p : 1;
     104              :   /* If KIND is ck_ref_bind or ck_base, true to indicate that a
     105              :      temporary should be created to hold the result of the
     106              :      conversion.  If KIND is ck_ambig or ck_user, true means force
     107              :      copy-initialization.  */
     108              :   bool need_temporary_p : 1;
     109              :   /* If KIND is ck_ptr or ck_pmem, true to indicate that a conversion
     110              :      from a pointer-to-derived to pointer-to-base is being performed.  */
     111              :   bool base_p : 1;
     112              :   /* If KIND is ck_ref_bind, true when either an lvalue reference is
     113              :      being bound to an lvalue expression or an rvalue reference is
     114              :      being bound to an rvalue expression.  If KIND is ck_rvalue or ck_base,
     115              :      true when we are treating an lvalue as an rvalue (12.8p33).  If
     116              :      ck_identity, we will be binding a reference directly or decaying to
     117              :      a pointer.  */
     118              :   bool rvaluedness_matches_p: 1;
     119              :   bool check_narrowing: 1;
     120              :   /* Whether check_narrowing should only check TREE_CONSTANTs; used
     121              :      in build_converted_constant_expr.  */
     122              :   bool check_narrowing_const_only: 1;
     123              :   /* True if this conversion is taking place in a copy-initialization context
     124              :      and we should only consider converting constructors.  Only set in
     125              :      ck_base and ck_rvalue.  */
     126              :   bool copy_init_p : 1;
     127              :   /* The type of the expression resulting from the conversion.  */
     128              :   tree type;
     129              :   union {
     130              :     /* The next conversion in the chain.  Since the conversions are
     131              :        arranged from outermost to innermost, the NEXT conversion will
     132              :        actually be performed before this conversion.  This variant is
     133              :        used only when KIND is neither ck_identity, ck_aggr, ck_ambig nor
     134              :        ck_list.  Please use the next_conversion function instead
     135              :        of using this field directly.  */
     136              :     conversion *next;
     137              :     /* The expression at the beginning of the conversion chain.  This
     138              :        variant is used only if KIND is ck_identity, ck_aggr, or ck_ambig.
     139              :        You can use conv_get_original_expr to get this expression.  */
     140              :     tree expr;
     141              :     /* The array of conversions for an initializer_list, so this
     142              :        variant is used only when KIN D is ck_list.  */
     143              :     conversion **list;
     144              :   } u;
     145              :   /* The function candidate corresponding to this conversion
     146              :      sequence.  This field is only used if KIND is ck_user.  */
     147              :   struct z_candidate *cand;
     148              : };
     149              : 
     150              : #define CONVERSION_RANK(NODE)                   \
     151              :   ((NODE)->bad_p ? cr_bad                    \
     152              :    : (NODE)->ellipsis_p ? cr_ellipsis                \
     153              :    : (NODE)->user_conv_p ? cr_user           \
     154              :    : (NODE)->rank)
     155              : 
     156              : #define BAD_CONVERSION_RANK(NODE)               \
     157              :   ((NODE)->ellipsis_p ? cr_ellipsis          \
     158              :    : (NODE)->user_conv_p ? cr_user           \
     159              :    : (NODE)->rank)
     160              : 
     161              : static struct obstack conversion_obstack;
     162              : static bool conversion_obstack_initialized;
     163              : struct rejection_reason;
     164              : 
     165              : static struct z_candidate * tourney (struct z_candidate *, tsubst_flags_t);
     166              : static int equal_functions (tree, tree);
     167              : static int joust (struct z_candidate *, struct z_candidate *, bool,
     168              :                   tsubst_flags_t);
     169              : static int compare_ics (conversion *, conversion *);
     170              : static void maybe_warn_class_memaccess (location_t, tree,
     171              :                                         const vec<tree, va_gc> *);
     172              : static tree build_over_call (struct z_candidate *, int, tsubst_flags_t);
     173              : static tree convert_like (conversion *, tree, tsubst_flags_t);
     174              : static tree convert_like_with_context (conversion *, tree, tree, int,
     175              :                                        tsubst_flags_t);
     176              : static void op_error (const op_location_t &, enum tree_code, enum tree_code,
     177              :                       tree, tree, tree, bool);
     178              : static struct z_candidate *build_user_type_conversion_1 (tree, tree, int,
     179              :                                                          tsubst_flags_t);
     180              : static void print_z_candidate (location_t, const char *, struct z_candidate *);
     181              : static void print_z_candidates (location_t, struct z_candidate *,
     182              :                                 tristate = tristate::unknown ());
     183              : static tree build_this (tree);
     184              : static struct z_candidate *splice_viable (struct z_candidate *, bool, bool *);
     185              : static bool any_strictly_viable (struct z_candidate *);
     186              : static struct z_candidate *add_template_candidate
     187              :         (struct z_candidate **, tree, tree, tree, tree, const vec<tree, va_gc> *,
     188              :          tree, tree, tree, int, unification_kind_t, bool, tsubst_flags_t);
     189              : static struct z_candidate *add_template_candidate_real
     190              :         (struct z_candidate **, tree, tree, tree, tree, const vec<tree, va_gc> *,
     191              :          tree, tree, tree, int, tree, unification_kind_t, bool, tsubst_flags_t);
     192              : static bool is_complete (tree);
     193              : static struct z_candidate *add_conv_candidate
     194              :         (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, tree,
     195              :          tree, tsubst_flags_t);
     196              : static struct z_candidate *add_function_candidate
     197              :         (struct z_candidate **, tree, tree, tree, const vec<tree, va_gc> *, tree,
     198              :          tree, int, conversion**, bool, tsubst_flags_t);
     199              : static conversion *implicit_conversion (tree, tree, tree, bool, int,
     200              :                                         tsubst_flags_t);
     201              : static conversion *reference_binding (tree, tree, tree, bool, int,
     202              :                                       tsubst_flags_t);
     203              : static conversion *build_conv (conversion_kind, tree, conversion *);
     204              : static conversion *build_list_conv (tree, tree, int, tsubst_flags_t);
     205              : static conversion *next_conversion (conversion *);
     206              : static bool is_subseq (conversion *, conversion *);
     207              : static conversion *maybe_handle_ref_bind (conversion **);
     208              : static void maybe_handle_implicit_object (conversion **);
     209              : static struct z_candidate *add_candidate
     210              :         (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, size_t,
     211              :          conversion **, tree, tree, int, struct rejection_reason *, int);
     212              : static tree source_type (conversion *);
     213              : static void add_warning (struct z_candidate *, struct z_candidate *);
     214              : static conversion *direct_reference_binding (tree, conversion *);
     215              : static bool promoted_arithmetic_type_p (tree);
     216              : static conversion *conditional_conversion (tree, tree, tsubst_flags_t);
     217              : static char *name_as_c_string (tree, tree, bool *);
     218              : static tree prep_operand (tree);
     219              : static void add_candidates (tree, tree, const vec<tree, va_gc> *, tree, tree,
     220              :                             bool, tree, tree, int, struct z_candidate **,
     221              :                             tsubst_flags_t);
     222              : static conversion *merge_conversion_sequences (conversion *, conversion *);
     223              : static tree build_temp (tree, tree, int, enum diagnostics::kind *,
     224              :                         tsubst_flags_t);
     225              : static conversion *build_identity_conv (tree, tree);
     226              : static inline bool conv_binds_to_array_of_unknown_bound (conversion *);
     227              : static bool conv_is_prvalue (conversion *);
     228              : static tree prevent_lifetime_extension (tree);
     229              : 
     230              : /* Returns nonzero iff the destructor name specified in NAME matches BASETYPE.
     231              :    NAME can take many forms...  */
     232              : 
     233              : bool
     234      3219385 : check_dtor_name (tree basetype, tree name)
     235              : {
     236              :   /* Just accept something we've already complained about.  */
     237      3219385 :   if (name == error_mark_node)
     238              :     return true;
     239              : 
     240      3219385 :   if (TREE_CODE (name) == TYPE_DECL)
     241           84 :     name = TREE_TYPE (name);
     242      3219301 :   else if (TYPE_P (name))
     243              :     /* OK */;
     244           26 :   else if (identifier_p (name))
     245              :     {
     246           26 :       if ((MAYBE_CLASS_TYPE_P (basetype)
     247            0 :            || TREE_CODE (basetype) == ENUMERAL_TYPE)
     248           26 :           && name == constructor_name (basetype))
     249              :         return true;
     250              : 
     251              :       /* Otherwise lookup the name, it could be an unrelated typedef
     252              :          of the correct type.  */
     253            6 :       name = lookup_name (name, LOOK_want::TYPE);
     254            6 :       if (!name)
     255              :         return false;
     256            3 :       name = TREE_TYPE (name);
     257            3 :       if (name == error_mark_node)
     258              :         return false;
     259              :     }
     260              :   else
     261              :     {
     262              :       /* In the case of:
     263              : 
     264              :          template <class T> struct S { ~S(); };
     265              :          int i;
     266              :          i.~S();
     267              : 
     268              :          NAME will be a class template.  */
     269            0 :       gcc_assert (DECL_CLASS_TEMPLATE_P (name));
     270              :       return false;
     271              :     }
     272              : 
     273      3219359 :   return same_type_p (TYPE_MAIN_VARIANT (basetype), TYPE_MAIN_VARIANT (name));
     274              : }
     275              : 
     276              : /* We want the address of a function or method.  We avoid creating a
     277              :    pointer-to-member function.  */
     278              : 
     279              : tree
     280    364941487 : build_addr_func (tree function, tsubst_flags_t complain)
     281              : {
     282    364941487 :   tree type = TREE_TYPE (function);
     283              : 
     284              :   /* We have to do these by hand to avoid real pointer to member
     285              :      functions.  */
     286    364941487 :   if (TREE_CODE (type) == METHOD_TYPE)
     287              :     {
     288     55772881 :       if (TREE_CODE (function) == OFFSET_REF)
     289              :         {
     290           74 :           tree object = build_address (TREE_OPERAND (function, 0));
     291           74 :           return get_member_function_from_ptrfunc (&object,
     292           74 :                                                    TREE_OPERAND (function, 1),
     293              :                                                    complain);
     294              :         }
     295     55772807 :       function = build_address (function);
     296              :     }
     297    309168606 :   else if (TREE_CODE (function) == FUNCTION_DECL
     298    441382348 :            && DECL_IMMEDIATE_FUNCTION_P (function))
     299      1708997 :     function = build_address (function);
     300              :   else
     301    307459609 :     function = decay_conversion (function, complain, /*reject_builtin=*/false);
     302              : 
     303              :   return function;
     304              : }
     305              : 
     306              : /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
     307              :    POINTER_TYPE to those.  Note, pointer to member function types
     308              :    (TYPE_PTRMEMFUNC_P) must be handled by our callers.  There are
     309              :    two variants.  build_call_a is the primitive taking an array of
     310              :    arguments, while build_call_n is a wrapper that handles varargs.  */
     311              : 
     312              : tree
     313       172567 : build_call_n (tree function, int n, ...)
     314              : {
     315       172567 :   if (n == 0)
     316            0 :     return build_call_a (function, 0, NULL);
     317              :   else
     318              :     {
     319       172567 :       tree *argarray = XALLOCAVEC (tree, n);
     320       172567 :       va_list ap;
     321       172567 :       int i;
     322              : 
     323       172567 :       va_start (ap, n);
     324       346438 :       for (i = 0; i < n; i++)
     325       173871 :         argarray[i] = va_arg (ap, tree);
     326       172567 :       va_end (ap);
     327       172567 :       return build_call_a (function, n, argarray);
     328              :     }
     329              : }
     330              : 
     331              : /* Update various flags in cfun and the call itself based on what is being
     332              :    called.  Split out of build_call_a so that bot_manip can use it too.  */
     333              : 
     334              : void
     335    178094897 : set_flags_from_callee (tree call)
     336              : {
     337              :   /* Handle both CALL_EXPRs and AGGR_INIT_EXPRs.  */
     338    178094897 :   tree decl = cp_get_callee_fndecl_nofold (call);
     339              : 
     340              :   /* We check both the decl and the type; a function may be known not to
     341              :      throw without being declared throw().  */
     342    178094897 :   bool nothrow = decl && TREE_NOTHROW (decl);
     343    178094897 :   tree callee = cp_get_callee (call);
     344    178094897 :   if (callee)
     345    178094889 :     nothrow |= TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (callee)));
     346            8 :   else if (TREE_CODE (call) == CALL_EXPR
     347            8 :            && internal_fn_flags (CALL_EXPR_IFN (call)) & ECF_NOTHROW)
     348              :     nothrow = true;
     349              : 
     350    178094897 :   if (cfun && cp_function_chain && !cp_unevaluated_operand)
     351              :     {
     352    102069633 :       if (!nothrow && at_function_scope_p ())
     353     25265072 :         cp_function_chain->can_throw = 1;
     354              : 
     355    102069633 :       if (decl && TREE_THIS_VOLATILE (decl))
     356      3065839 :         current_function_returns_abnormally = 1;
     357              :     }
     358              : 
     359    178094897 :   TREE_NOTHROW (call) = nothrow;
     360    178094897 : }
     361              : 
     362              : tree
     363    172014042 : build_call_a (tree function, int n, tree *argarray)
     364              : {
     365    172014042 :   tree decl;
     366    172014042 :   tree result_type;
     367    172014042 :   tree fntype;
     368    172014042 :   int i;
     369              : 
     370    172014042 :   function = build_addr_func (function, tf_warning_or_error);
     371              : 
     372    172014042 :   gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
     373    172014042 :   fntype = TREE_TYPE (TREE_TYPE (function));
     374    172014042 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     375    172014042 :   result_type = TREE_TYPE (fntype);
     376              :   /* An rvalue has no cv-qualifiers.  */
     377    172014042 :   if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
     378    100115011 :     result_type = cv_unqualified (result_type);
     379              : 
     380    172014042 :   function = build_call_array_loc (input_location,
     381              :                                    result_type, function, n, argarray);
     382    172014042 :   set_flags_from_callee (function);
     383              : 
     384    172014042 :   decl = get_callee_fndecl (function);
     385              : 
     386    172014042 :   if (decl && !TREE_USED (decl))
     387              :     {
     388              :       /* We invoke build_call directly for several library
     389              :          functions.  These may have been declared normally if
     390              :          we're building libgcc, so we can't just check
     391              :          DECL_ARTIFICIAL.  */
     392       218177 :       gcc_assert (DECL_ARTIFICIAL (decl)
     393              :                   || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
     394              :                                "__", 2));
     395       218177 :       mark_used (decl);
     396              :     }
     397              : 
     398    172014042 :   require_complete_eh_spec_types (fntype, decl);
     399              : 
     400    496110458 :   TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl));
     401              : 
     402              :   /* Don't pass empty class objects by value.  This is useful
     403              :      for tags in STL, which are used to control overload resolution.
     404              :      We don't need to handle other cases of copying empty classes.  */
     405    172014042 :   if (!decl || !fndecl_built_in_p (decl))
     406    345117129 :     for (i = 0; i < n; i++)
     407              :       {
     408    181064314 :         tree arg = CALL_EXPR_ARG (function, i);
     409    181064314 :         if (is_empty_class (TREE_TYPE (arg))
     410    181064314 :             && simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
     411              :           {
     412      5715896 :             while (TREE_CODE (arg) == TARGET_EXPR)
     413              :               /* We're disconnecting the initializer from its target,
     414              :                  don't create a temporary.  */
     415      2856767 :               arg = TARGET_EXPR_INITIAL (arg);
     416      2859129 :             suppress_warning (arg, OPT_Wunused_result);
     417      2859129 :             tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
     418      2859129 :             arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
     419      2859129 :             CALL_EXPR_ARG (function, i) = arg;
     420              :           }
     421              :       }
     422              : 
     423    172014042 :   return function;
     424              : }
     425              : 
     426              : /* New overloading code.  */
     427              : 
     428              : struct z_candidate;
     429              : 
     430              : struct candidate_warning {
     431              :   z_candidate *loser;
     432              :   candidate_warning *next;
     433              : };
     434              : 
     435              : /* Information for providing diagnostics about why overloading failed.  */
     436              : 
     437              : enum rejection_reason_code {
     438              :   rr_none,
     439              :   rr_arity,
     440              :   rr_explicit_conversion,
     441              :   rr_template_conversion,
     442              :   rr_arg_conversion,
     443              :   rr_bad_arg_conversion,
     444              :   rr_template_unification,
     445              :   rr_invalid_copy,
     446              :   rr_inherited_ctor,
     447              :   rr_constraint_failure,
     448              :   rr_ignored,
     449              : };
     450              : 
     451              : struct conversion_info {
     452              :   /* The index of the argument, 0-based.  */
     453              :   int n_arg;
     454              :   /* The actual argument or its type.  */
     455              :   tree from;
     456              :   /* The type of the parameter.  */
     457              :   tree to_type;
     458              :   /* The location of the argument.  */
     459              :   location_t loc;
     460              : };
     461              : 
     462              : struct rejection_reason {
     463              :   enum rejection_reason_code code;
     464              :   union {
     465              :     /* Information about an arity mismatch.  */
     466              :     struct {
     467              :       /* The expected number of arguments.  */
     468              :       int expected;
     469              :       /* The actual number of arguments in the call.  */
     470              :       int actual;
     471              :       /* Whether EXPECTED should be treated as a lower bound.  */
     472              :       bool least_p;
     473              :     } arity;
     474              :     /* Information about an argument conversion mismatch.  */
     475              :     struct conversion_info conversion;
     476              :     /* Same, but for bad argument conversions.  */
     477              :     struct conversion_info bad_conversion;
     478              :     /* Information about template unification failures.  These are the
     479              :        parameters passed to fn_type_unification.  */
     480              :     struct {
     481              :       tree tmpl;
     482              :       tree explicit_targs;
     483              :       int num_targs;
     484              :       const tree *args;
     485              :       unsigned int nargs;
     486              :       tree return_type;
     487              :       unification_kind_t strict;
     488              :       int flags;
     489              :     } template_unification;
     490              :     /* Information about template instantiation failures.  These are the
     491              :        parameters passed to instantiate_template.  */
     492              :     struct {
     493              :       tree tmpl;
     494              :       tree targs;
     495              :     } template_instantiation;
     496              :   } u;
     497              : };
     498              : 
     499              : struct z_candidate {
     500              :   /* The FUNCTION_DECL that will be called if this candidate is
     501              :      selected by overload resolution.  */
     502              :   tree fn;
     503              :   /* If not NULL_TREE, the first argument to use when calling this
     504              :      function.  */
     505              :   tree first_arg;
     506              :   /* The rest of the arguments to use when calling this function.  If
     507              :      there are no further arguments this may be NULL or it may be an
     508              :      empty vector.  */
     509              :   const vec<tree, va_gc> *args;
     510              :   /* The implicit conversion sequences for each of the arguments to
     511              :      FN.  */
     512              :   conversion **convs;
     513              :   /* The number of implicit conversion sequences.  */
     514              :   size_t num_convs;
     515              :   /* If FN is a user-defined conversion, the standard conversion
     516              :      sequence from the type returned by FN to the desired destination
     517              :      type.  */
     518              :   conversion *second_conv;
     519              :   struct rejection_reason *reason;
     520              :   /* If FN is a member function, the binfo indicating the path used to
     521              :      qualify the name of FN at the call site.  This path is used to
     522              :      determine whether or not FN is accessible if it is selected by
     523              :      overload resolution.  The DECL_CONTEXT of FN will always be a
     524              :      (possibly improper) base of this binfo.  */
     525              :   tree access_path;
     526              :   /* If FN is a non-static member function, the binfo indicating the
     527              :      subobject to which the `this' pointer should be converted if FN
     528              :      is selected by overload resolution.  The type pointed to by
     529              :      the `this' pointer must correspond to the most derived class
     530              :      indicated by the CONVERSION_PATH.  */
     531              :   tree conversion_path;
     532              :   tree template_decl;
     533              :   tree explicit_targs;
     534              :   candidate_warning *warnings;
     535              :   z_candidate *next;
     536              :   int viable;
     537              : 
     538              :   /* The flags active in add_candidate.  */
     539              :   int flags;
     540              : 
     541     66111874 :   bool rewritten () const { return (flags & LOOKUP_REWRITTEN); }
     542   1084228713 :   bool reversed () const { return (flags & LOOKUP_REVERSED); }
     543              : };
     544              : 
     545              : /* Returns true iff T is a null pointer constant in the sense of
     546              :    [conv.ptr].  */
     547              : 
     548              : bool
     549    131866529 : null_ptr_cst_p (tree t)
     550              : {
     551    131866529 :   tree type = TREE_TYPE (t);
     552              : 
     553              :   /* [conv.ptr]
     554              : 
     555              :      A null pointer constant is an integer literal ([lex.icon]) with value
     556              :      zero or a prvalue of type std::nullptr_t.  */
     557    131866529 :   if (NULLPTR_TYPE_P (type))
     558              :     return true;
     559              : 
     560    122649027 :   if (cxx_dialect >= cxx11)
     561              :     {
     562    122254079 :       STRIP_ANY_LOCATION_WRAPPER (t);
     563              : 
     564              :       /* Core issue 903 says only literal 0 is a null pointer constant.  */
     565    122254079 :       if (TREE_CODE (t) == INTEGER_CST
     566     13891974 :           && !TREE_OVERFLOW (t)
     567     13891974 :           && TREE_CODE (type) == INTEGER_TYPE
     568     13277434 :           && integer_zerop (t)
     569    131069054 :           && !char_type_p (type))
     570      8814679 :         return true;
     571              :     }
     572       394948 :   else if (CP_INTEGRAL_TYPE_P (type))
     573              :     {
     574        76147 :       t = fold_non_dependent_expr (t, tf_none);
     575        76147 :       STRIP_NOPS (t);
     576        76147 :       if (integer_zerop (t) && !TREE_OVERFLOW (t))
     577        54575 :         return true;
     578              :     }
     579              : 
     580              :   return false;
     581              : }
     582              : 
     583              : /* Returns true iff T is a null member pointer value (4.11).  */
     584              : 
     585              : bool
     586    102525849 : null_member_pointer_value_p (tree t)
     587              : {
     588    102525849 :   tree type = TREE_TYPE (t);
     589    102525849 :   if (!type)
     590              :     return false;
     591    102337245 :   else if (TYPE_PTRMEMFUNC_P (type))
     592         1109 :     return (TREE_CODE (t) == CONSTRUCTOR
     593          564 :             && CONSTRUCTOR_NELTS (t)
     594         1670 :             && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
     595    102336136 :   else if (TYPE_PTRDATAMEM_P (type))
     596         5971 :     return integer_all_onesp (t);
     597              :   else
     598              :     return false;
     599              : }
     600              : 
     601              : /* Returns nonzero if PARMLIST consists of only default parms,
     602              :    ellipsis, and/or undeduced parameter packs.  */
     603              : 
     604              : bool
     605    746397496 : sufficient_parms_p (const_tree parmlist)
     606              : {
     607    756280909 :   for (; parmlist && parmlist != void_list_node;
     608      9883413 :        parmlist = TREE_CHAIN (parmlist))
     609    227024127 :     if (!TREE_PURPOSE (parmlist)
     610    227024127 :         && !PACK_EXPANSION_P (TREE_VALUE (parmlist)))
     611              :       return false;
     612              :   return true;
     613              : }
     614              : 
     615              : /* Allocate N bytes of memory from the conversion obstack.  The memory
     616              :    is zeroed before being returned.  */
     617              : 
     618              : static void *
     619   8169677911 : conversion_obstack_alloc (size_t n)
     620              : {
     621   8169677911 :   void *p;
     622   8169677911 :   if (!conversion_obstack_initialized)
     623              :     {
     624        87175 :       gcc_obstack_init (&conversion_obstack);
     625        87175 :       conversion_obstack_initialized = true;
     626              :     }
     627   8169677911 :   p = obstack_alloc (&conversion_obstack, n);
     628   8169677911 :   memset (p, 0, n);
     629   8169677911 :   return p;
     630              : }
     631              : 
     632              : /* RAII class to discard anything added to conversion_obstack.  */
     633              : 
     634              : struct conversion_obstack_sentinel
     635              : {
     636              :   void *p;
     637   2641791766 :   conversion_obstack_sentinel (): p (conversion_obstack_alloc (0)) {}
     638   1320882329 :   ~conversion_obstack_sentinel () { obstack_free (&conversion_obstack, p); }
     639              : };
     640              : 
     641              : /* Allocate rejection reasons.  */
     642              : 
     643              : static struct rejection_reason *
     644    790148934 : alloc_rejection (enum rejection_reason_code code)
     645              : {
     646    790148934 :   struct rejection_reason *p;
     647            0 :   p = (struct rejection_reason *) conversion_obstack_alloc (sizeof *p);
     648    790148934 :   p->code = code;
     649    790148934 :   return p;
     650              : }
     651              : 
     652              : static struct rejection_reason *
     653    199374879 : arity_rejection (tree first_arg, int expected, int actual, bool least_p = false)
     654              : {
     655    159186261 :   struct rejection_reason *r = alloc_rejection (rr_arity);
     656    199374879 :   int adjust = first_arg != NULL_TREE;
     657    199374879 :   r->u.arity.expected = expected - adjust;
     658    199374879 :   r->u.arity.actual = actual - adjust;
     659    199374879 :   r->u.arity.least_p = least_p;
     660    199374879 :   return r;
     661              : }
     662              : 
     663              : static struct rejection_reason *
     664    167956986 : arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     665              :                           location_t loc)
     666              : {
     667      7176792 :   struct rejection_reason *r = alloc_rejection (rr_arg_conversion);
     668    167956986 :   int adjust = first_arg != NULL_TREE;
     669    167956986 :   r->u.conversion.n_arg = n_arg - adjust;
     670    167956986 :   r->u.conversion.from = from;
     671    167956986 :   r->u.conversion.to_type = to;
     672    167956986 :   r->u.conversion.loc = loc;
     673    167956986 :   return r;
     674              : }
     675              : 
     676              : static struct rejection_reason *
     677     22712663 : bad_arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     678              :                               location_t loc)
     679              : {
     680         2606 :   struct rejection_reason *r = alloc_rejection (rr_bad_arg_conversion);
     681     22712663 :   int adjust = first_arg != NULL_TREE;
     682     22712663 :   r->u.bad_conversion.n_arg = n_arg - adjust;
     683     22712663 :   r->u.bad_conversion.from = from;
     684     22712663 :   r->u.bad_conversion.to_type = to;
     685     22712663 :   r->u.bad_conversion.loc = loc;
     686     22712663 :   return r;
     687              : }
     688              : 
     689              : static struct rejection_reason *
     690         2747 : explicit_conversion_rejection (tree from, tree to)
     691              : {
     692         2747 :   struct rejection_reason *r = alloc_rejection (rr_explicit_conversion);
     693         2747 :   r->u.conversion.n_arg = 0;
     694         2747 :   r->u.conversion.from = from;
     695         2747 :   r->u.conversion.to_type = to;
     696         2747 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     697         2747 :   return r;
     698              : }
     699              : 
     700              : static struct rejection_reason *
     701           21 : template_conversion_rejection (tree from, tree to)
     702              : {
     703           21 :   struct rejection_reason *r = alloc_rejection (rr_template_conversion);
     704           21 :   r->u.conversion.n_arg = 0;
     705           21 :   r->u.conversion.from = from;
     706           21 :   r->u.conversion.to_type = to;
     707           21 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     708           21 :   return r;
     709              : }
     710              : 
     711              : static struct rejection_reason *
     712    398333378 : template_unification_rejection (tree tmpl, tree explicit_targs, tree targs,
     713              :                                 const tree *args, unsigned int nargs,
     714              :                                 tree return_type, unification_kind_t strict,
     715              :                                 int flags)
     716              : {
     717    398333378 :   size_t args_n_bytes = sizeof (*args) * nargs;
     718    398333378 :   tree *args1 = (tree *) conversion_obstack_alloc (args_n_bytes);
     719    398333378 :   struct rejection_reason *r = alloc_rejection (rr_template_unification);
     720    398333378 :   r->u.template_unification.tmpl = tmpl;
     721    398333378 :   r->u.template_unification.explicit_targs = explicit_targs;
     722    398333378 :   r->u.template_unification.num_targs = TREE_VEC_LENGTH (targs);
     723              :   /* Copy args to our own storage.  */
     724    398333378 :   memcpy (args1, args, args_n_bytes);
     725    398333378 :   r->u.template_unification.args = args1;
     726    398333378 :   r->u.template_unification.nargs = nargs;
     727    398333378 :   r->u.template_unification.return_type = return_type;
     728    398333378 :   r->u.template_unification.strict = strict;
     729    398333378 :   r->u.template_unification.flags = flags;
     730    398333378 :   return r;
     731              : }
     732              : 
     733              : static struct rejection_reason *
     734          116 : template_unification_error_rejection (void)
     735              : {
     736            0 :   return alloc_rejection (rr_template_unification);
     737              : }
     738              : 
     739              : static struct rejection_reason *
     740       760495 : invalid_copy_with_fn_template_rejection (void)
     741              : {
     742            0 :   struct rejection_reason *r = alloc_rejection (rr_invalid_copy);
     743       760495 :   return r;
     744              : }
     745              : 
     746              : static struct rejection_reason *
     747       808279 : inherited_ctor_rejection (void)
     748              : {
     749            0 :   struct rejection_reason *r = alloc_rejection (rr_inherited_ctor);
     750       808279 :   return r;
     751              : }
     752              : 
     753              : /* Build a constraint failure record.  */
     754              : 
     755              : static struct rejection_reason *
     756       199370 : constraint_failure (void)
     757              : {
     758            0 :   struct rejection_reason *r = alloc_rejection (rr_constraint_failure);
     759       199370 :   return r;
     760              : }
     761              : 
     762              : /* Dynamically allocate a conversion.  */
     763              : 
     764              : static conversion *
     765   2808309443 : alloc_conversion (conversion_kind kind)
     766              : {
     767   2808309443 :   conversion *c;
     768            0 :   c = (conversion *) conversion_obstack_alloc (sizeof (conversion));
     769   2808309443 :   c->kind = kind;
     770   2808309443 :   return c;
     771              : }
     772              : 
     773              : /* Make sure that all memory on the conversion obstack has been
     774              :    freed.  */
     775              : 
     776              : void
     777        99525 : validate_conversion_obstack (void)
     778              : {
     779        99525 :   if (conversion_obstack_initialized)
     780        86841 :     gcc_assert ((obstack_next_free (&conversion_obstack)
     781              :                  == obstack_base (&conversion_obstack)));
     782        99525 : }
     783              : 
     784              : /* Dynamically allocate an array of N conversions.  */
     785              : 
     786              : static conversion **
     787   1055366628 : alloc_conversions (size_t n)
     788              : {
     789            0 :   return (conversion **) conversion_obstack_alloc (n * sizeof (conversion *));
     790              : }
     791              : 
     792              : /* True iff the active member of conversion::u for code CODE is NEXT.  */
     793              : 
     794              : static inline bool
     795   1533658416 : has_next (conversion_kind code)
     796              : {
     797   1441467590 :   return !(code == ck_identity
     798   1533658416 :            || code == ck_ambig
     799              :            || code == ck_list
     800   1441560911 :            || code == ck_aggr
     801   1533658416 :            || code == ck_deferred_bad);
     802              : }
     803              : 
     804              : static conversion *
     805    823220252 : build_conv (conversion_kind code, tree type, conversion *from)
     806              : {
     807    823220252 :   conversion *t;
     808    823220252 :   conversion_rank rank = CONVERSION_RANK (from);
     809              : 
     810              :   /* Only call this function for conversions that use u.next.  */
     811    823220252 :   gcc_assert (from == NULL || has_next (code));
     812              : 
     813              :   /* Note that the caller is responsible for filling in t->cand for
     814              :      user-defined conversions.  */
     815    823220252 :   t = alloc_conversion (code);
     816    823220252 :   t->type = type;
     817    823220252 :   t->u.next = from;
     818              : 
     819    823220252 :   switch (code)
     820              :     {
     821    240461023 :     case ck_ptr:
     822    240461023 :     case ck_pmem:
     823    240461023 :     case ck_base:
     824    240461023 :     case ck_std:
     825    240461023 :       if (rank < cr_std)
     826    823220252 :         rank = cr_std;
     827              :       break;
     828              : 
     829     55506946 :     case ck_qual:
     830     55506946 :     case ck_fnptr:
     831     55506946 :       if (rank < cr_exact)
     832    823220252 :         rank = cr_exact;
     833              :       break;
     834              : 
     835              :     default:
     836              :       break;
     837              :     }
     838    823220252 :   t->rank = rank;
     839    823220252 :   t->user_conv_p = (code == ck_user || from->user_conv_p);
     840    823220252 :   t->bad_p = from->bad_p;
     841    823220252 :   t->base_p = false;
     842    823220252 :   return t;
     843              : }
     844              : 
     845              : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
     846              :    specialization of std::initializer_list<T>, if such a conversion is
     847              :    possible.  */
     848              : 
     849              : static conversion *
     850        96410 : build_list_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     851              : {
     852        96410 :   tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (type), 0);
     853        96410 :   unsigned len = CONSTRUCTOR_NELTS (ctor);
     854        96410 :   conversion **subconvs = alloc_conversions (len);
     855        96410 :   conversion *t;
     856        96410 :   unsigned i;
     857        96410 :   tree val;
     858              : 
     859              :   /* Within a list-initialization we can have more user-defined
     860              :      conversions.  */
     861        96410 :   flags &= ~LOOKUP_NO_CONVERSION;
     862              :   /* But no narrowing conversions.  */
     863        96410 :   flags |= LOOKUP_NO_NARROWING;
     864              : 
     865              :   /* Can't make an array of these types.  */
     866        96410 :   if (TYPE_REF_P (elttype)
     867        96401 :       || TREE_CODE (elttype) == FUNCTION_TYPE
     868        96401 :       || VOID_TYPE_P (elttype))
     869              :     return NULL;
     870              : 
     871       343806 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
     872              :     {
     873       261115 :       if (TREE_CODE (val) == RAW_DATA_CST)
     874              :         {
     875           51 :           tree elt
     876           51 :             = build_int_cst (TREE_TYPE (val), RAW_DATA_UCHAR_ELT (val, 0));
     877           51 :           conversion *sub
     878           51 :             = implicit_conversion (elttype, TREE_TYPE (val), elt,
     879              :                                    false, flags, complain);
     880           51 :           conversion *next;
     881           51 :           if (sub == NULL)
     882              :             return NULL;
     883              :           /* For conversion to initializer_list<unsigned char> or
     884              :              initializer_list<char> or initializer_list<signed char>
     885              :              we can optimize and keep RAW_DATA_CST with adjusted
     886              :              type if we report narrowing errors if needed.
     887              :              Use just one subconversion for that case.  */
     888           69 :           if (sub->kind == ck_std
     889           24 :               && sub->type
     890           24 :               && (TREE_CODE (sub->type) == INTEGER_TYPE
     891            6 :                   || is_byte_access_type (sub->type))
     892           18 :               && TYPE_PRECISION (sub->type) == CHAR_BIT
     893           18 :               && (next = next_conversion (sub))
     894           69 :               && next->kind == ck_identity)
     895              :             {
     896           18 :               subconvs[i] = sub;
     897           18 :               continue;
     898              :             }
     899              :           /* Otherwise. build separate subconv for each RAW_DATA_CST
     900              :              byte.  Wrap those into an artificial ck_list which convert_like
     901              :              will then handle.  */
     902           33 :           conversion **subsubconvs = alloc_conversions (RAW_DATA_LENGTH (val));
     903           33 :           unsigned int j;
     904           33 :           subsubconvs[0] = sub;
     905        15849 :           for (j = 1; j < (unsigned) RAW_DATA_LENGTH (val); ++j)
     906              :             {
     907        15816 :               elt = build_int_cst (TREE_TYPE (val),
     908        15816 :                                    RAW_DATA_UCHAR_ELT (val, j));
     909        15816 :               sub = implicit_conversion (elttype, TREE_TYPE (val), elt,
     910              :                                          false, flags, complain);
     911        15816 :               if (sub == NULL)
     912              :                 return NULL;
     913        15816 :               subsubconvs[j] = sub;
     914              :             }
     915              : 
     916           33 :           t = alloc_conversion (ck_list);
     917           33 :           t->type = type;
     918           33 :           t->u.list = subsubconvs;
     919           33 :           t->rank = cr_exact;
     920        15882 :           for (j = 0; j < (unsigned) RAW_DATA_LENGTH (val); ++j)
     921              :             {
     922        15849 :               sub = subsubconvs[j];
     923        15849 :               if (sub->rank > t->rank)
     924            6 :                 t->rank = sub->rank;
     925        15849 :               if (sub->user_conv_p)
     926        12063 :                 t->user_conv_p = true;
     927        15849 :               if (sub->bad_p)
     928            0 :                 t->bad_p = true;
     929              :             }
     930           33 :           subconvs[i] = t;
     931           33 :           continue;
     932           33 :         }
     933              : 
     934       261064 :       conversion *sub
     935       261064 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
     936              :                                false, flags, complain);
     937       261064 :       if (sub == NULL)
     938              :         return NULL;
     939              : 
     940       247354 :       subconvs[i] = sub;
     941              :     }
     942              : 
     943        82691 :   t = alloc_conversion (ck_list);
     944        82691 :   t->type = type;
     945        82691 :   t->u.list = subconvs;
     946        82691 :   t->rank = cr_exact;
     947              : 
     948       311206 :   for (i = 0; i < len; ++i)
     949              :     {
     950       228515 :       conversion *sub = subconvs[i];
     951       228515 :       if (sub->rank > t->rank)
     952        63696 :         t->rank = sub->rank;
     953       228515 :       if (sub->user_conv_p)
     954        10370 :         t->user_conv_p = true;
     955       228515 :       if (sub->bad_p)
     956        63683 :         t->bad_p = true;
     957              :     }
     958              : 
     959              :   return t;
     960              : }
     961              : 
     962              : /* Return the next conversion of the conversion chain (if applicable),
     963              :    or NULL otherwise.  Please use this function instead of directly
     964              :    accessing fields of struct conversion.  */
     965              : 
     966              : static conversion *
     967    618506608 : next_conversion (conversion *conv)
     968              : {
     969    618506608 :   if (conv == NULL
     970    618506608 :       || !has_next (conv->kind))
     971              :     return NULL;
     972    606036611 :   return conv->u.next;
     973              : }
     974              : 
     975              : /* Strip to the first ck_user, ck_ambig, ck_list, ck_aggr or ck_identity
     976              :    encountered.  */
     977              : 
     978              : static conversion *
     979      1544038 : strip_standard_conversion (conversion *conv)
     980              : {
     981      1544038 :   while (conv
     982      1554491 :          && conv->kind != ck_user
     983      1596648 :          && has_next (conv->kind))
     984        10453 :     conv = next_conversion (conv);
     985      1544038 :   return conv;
     986              : }
     987              : 
     988              : /* Subroutine of build_aggr_conv: check whether FROM is a valid aggregate
     989              :    initializer for array type ATYPE.  */
     990              : 
     991              : static bool
     992        27994 : can_convert_array (tree atype, tree from, int flags, tsubst_flags_t complain)
     993              : {
     994        28006 :   tree elttype = TREE_TYPE (atype);
     995        28006 :   unsigned i;
     996              : 
     997        28006 :   if (TREE_CODE (from) == CONSTRUCTOR)
     998              :     {
     999        31225 :       for (i = 0; i < CONSTRUCTOR_NELTS (from); ++i)
    1000              :         {
    1001         3276 :           tree val = CONSTRUCTOR_ELT (from, i)->value;
    1002         3276 :           bool ok;
    1003         3276 :           if (TREE_CODE (elttype) == ARRAY_TYPE)
    1004           18 :             ok = can_convert_array (elttype, val, flags, complain);
    1005              :           else
    1006         3258 :             ok = can_convert_arg (elttype, TREE_TYPE (val), val, flags,
    1007              :                                   complain);
    1008         3276 :           if (!ok)
    1009              :             return false;
    1010              :         }
    1011              :       return true;
    1012              :     }
    1013              : 
    1014           57 :   if (char_type_p (TYPE_MAIN_VARIANT (elttype))
    1015           57 :       && TREE_CODE (tree_strip_any_location_wrapper (from)) == STRING_CST)
    1016           45 :     return array_string_literal_compatible_p (atype, from);
    1017              : 
    1018           12 :   if (tree vi = (get_vec_init_expr (from)))
    1019           12 :     return can_convert_array (atype, VEC_INIT_EXPR_INIT (vi), flags, complain);
    1020              : 
    1021              :   /* No other valid way to aggregate initialize an array.  */
    1022              :   return false;
    1023              : }
    1024              : 
    1025              : /* Helper for build_aggr_conv.  Return true if FIELD is in PSET, or if
    1026              :    FIELD has ANON_AGGR_TYPE_P and any initializable field in there recursively
    1027              :    is in PSET.  */
    1028              : 
    1029              : static bool
    1030       874761 : field_in_pset (hash_set<tree, true> &pset, tree field)
    1031              : {
    1032       874761 :   if (pset.contains (field))
    1033              :     return true;
    1034         2602 :   if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    1035            0 :     for (field = TYPE_FIELDS (TREE_TYPE (field));
    1036            0 :          field; field = DECL_CHAIN (field))
    1037              :       {
    1038            0 :         field = next_aggregate_field (field);
    1039            0 :         if (field == NULL_TREE)
    1040              :           break;
    1041            0 :         if (field_in_pset (pset, field))
    1042              :           return true;
    1043              :       }
    1044              :   return false;
    1045              : }
    1046              : 
    1047              : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
    1048              :    aggregate class, if such a conversion is possible.  */
    1049              : 
    1050              : static conversion *
    1051      1375326 : build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1052              : {
    1053      1375326 :   unsigned HOST_WIDE_INT i = 0;
    1054      1375326 :   conversion *c;
    1055      1375326 :   tree field = next_aggregate_field (TYPE_FIELDS (type));
    1056      1375326 :   tree empty_ctor = NULL_TREE;
    1057      1375326 :   hash_set<tree, true> pset;
    1058              : 
    1059              :   /* We already called reshape_init in implicit_conversion, but it might not
    1060              :      have done anything in the case of parenthesized aggr init.  */
    1061              : 
    1062              :   /* The conversions within the init-list aren't affected by the enclosing
    1063              :      context; they're always simple copy-initialization.  */
    1064      1375326 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1065              : 
    1066              :   /* For designated initializers, verify that each initializer is convertible
    1067              :      to corresponding TREE_TYPE (ce->index) and mark those FIELD_DECLs as
    1068              :      visited.  In the following loop then ignore already visited
    1069              :      FIELD_DECLs.  */
    1070      1375326 :   tree idx, val;
    1071      3622811 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
    1072              :     {
    1073       872251 :       if (!idx)
    1074              :         break;
    1075              : 
    1076       872191 :       gcc_checking_assert (TREE_CODE (idx) == FIELD_DECL);
    1077              : 
    1078       872191 :       tree ftype = TREE_TYPE (idx);
    1079       872191 :       bool ok;
    1080              : 
    1081       872191 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1082         1197 :         ok = can_convert_array (ftype, val, flags, complain);
    1083              :       else
    1084       870994 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1085              :                               complain);
    1086              : 
    1087       872191 :       if (!ok)
    1088              :         return NULL;
    1089              : 
    1090              :       /* For unions, there should be just one initializer.  */
    1091       872182 :       if (TREE_CODE (type) == UNION_TYPE)
    1092              :         {
    1093      1375317 :           field = NULL_TREE;
    1094      1375317 :           i = 1;
    1095              :           break;
    1096              :         }
    1097       872159 :       pset.add (idx);
    1098              :     }
    1099              : 
    1100      2358050 :   for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
    1101              :     {
    1102       982993 :       tree ftype = TREE_TYPE (field);
    1103       982993 :       bool ok;
    1104              : 
    1105       982993 :       if (!pset.is_empty () && field_in_pset (pset, field))
    1106       872159 :         continue;
    1107       110834 :       if (i < CONSTRUCTOR_NELTS (ctor))
    1108              :         {
    1109           39 :           constructor_elt *ce = CONSTRUCTOR_ELT (ctor, i);
    1110           39 :           gcc_checking_assert (!ce->index);
    1111           39 :           val = ce->value;
    1112           39 :           ++i;
    1113              :         }
    1114       110795 :       else if (DECL_INITIAL (field))
    1115        44939 :         val = get_nsdmi (field, /*ctor*/false, complain);
    1116        65856 :       else if (TYPE_REF_P (ftype))
    1117              :         /* Value-initialization of reference is ill-formed.  */
    1118              :         return NULL;
    1119              :       else
    1120              :         {
    1121        65850 :           if (empty_ctor == NULL_TREE)
    1122        47001 :             empty_ctor = build_constructor (init_list_type_node, NULL);
    1123              :           val = empty_ctor;
    1124              :         }
    1125              : 
    1126       110828 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1127        26779 :         ok = can_convert_array (ftype, val, flags, complain);
    1128              :       else
    1129        84049 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1130              :                               complain);
    1131              : 
    1132       110828 :       if (!ok)
    1133              :         return NULL;
    1134              : 
    1135       110815 :       if (TREE_CODE (type) == UNION_TYPE)
    1136              :         break;
    1137              :     }
    1138              : 
    1139      1375298 :   if (i < CONSTRUCTOR_NELTS (ctor))
    1140              :     return NULL;
    1141              : 
    1142      1375271 :   c = alloc_conversion (ck_aggr);
    1143      1375271 :   c->type = type;
    1144      1375271 :   c->rank = cr_exact;
    1145      1375271 :   c->user_conv_p = true;
    1146      1375271 :   c->check_narrowing = true;
    1147      1375271 :   c->u.expr = ctor;
    1148      1375271 :   return c;
    1149      1375326 : }
    1150              : 
    1151              : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
    1152              :    array type, if such a conversion is possible.  */
    1153              : 
    1154              : static conversion *
    1155         1889 : build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1156              : {
    1157         1889 :   conversion *c;
    1158         1889 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1159         1889 :   tree elttype = TREE_TYPE (type);
    1160         1889 :   bool bad = false;
    1161         1889 :   bool user = false;
    1162         1889 :   enum conversion_rank rank = cr_exact;
    1163              : 
    1164              :   /* We might need to propagate the size from the element to the array.  */
    1165         1889 :   complete_type (type);
    1166              : 
    1167         1889 :   if (TYPE_DOMAIN (type)
    1168         1889 :       && !variably_modified_type_p (TYPE_DOMAIN (type), NULL_TREE))
    1169              :     {
    1170         1815 :       unsigned HOST_WIDE_INT alen = tree_to_uhwi (array_type_nelts_top (type));
    1171         1815 :       if (alen < len)
    1172              :         return NULL;
    1173              :     }
    1174              : 
    1175         1842 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1176              : 
    1177         7707 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1178              :     {
    1179         3030 :       conversion *sub
    1180         3030 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1181              :                                false, flags, complain);
    1182         3030 :       if (sub == NULL)
    1183              :         return NULL;
    1184              : 
    1185         2267 :       if (sub->rank > rank)
    1186          287 :         rank = sub->rank;
    1187         2267 :       if (sub->user_conv_p)
    1188           27 :         user = true;
    1189         2267 :       if (sub->bad_p)
    1190          218 :         bad = true;
    1191              :     }
    1192              : 
    1193         1079 :   c = alloc_conversion (ck_aggr);
    1194         1079 :   c->type = type;
    1195         1079 :   c->rank = rank;
    1196         1079 :   c->user_conv_p = user;
    1197         1079 :   c->bad_p = bad;
    1198         1079 :   c->u.expr = ctor;
    1199         1079 :   return c;
    1200              : }
    1201              : 
    1202              : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
    1203              :    complex type, if such a conversion is possible.  */
    1204              : 
    1205              : static conversion *
    1206        57352 : build_complex_conv (tree type, tree ctor, int flags,
    1207              :                     tsubst_flags_t complain)
    1208              : {
    1209        57352 :   conversion *c;
    1210        57352 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1211        57352 :   tree elttype = TREE_TYPE (type);
    1212        57352 :   bool bad = false;
    1213        57352 :   bool user = false;
    1214        57352 :   enum conversion_rank rank = cr_exact;
    1215              : 
    1216        57352 :   if (len != 2)
    1217              :     return NULL;
    1218              : 
    1219        57312 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1220              : 
    1221       286560 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1222              :     {
    1223       114624 :       conversion *sub
    1224       114624 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1225              :                                false, flags, complain);
    1226       114624 :       if (sub == NULL)
    1227              :         return NULL;
    1228              : 
    1229       114624 :       if (sub->rank > rank)
    1230           44 :         rank = sub->rank;
    1231       114624 :       if (sub->user_conv_p)
    1232            0 :         user = true;
    1233       114624 :       if (sub->bad_p)
    1234            0 :         bad = true;
    1235              :     }
    1236              : 
    1237        57312 :   c = alloc_conversion (ck_aggr);
    1238        57312 :   c->type = type;
    1239        57312 :   c->rank = rank;
    1240        57312 :   c->user_conv_p = user;
    1241        57312 :   c->bad_p = bad;
    1242        57312 :   c->u.expr = ctor;
    1243        57312 :   return c;
    1244              : }
    1245              : 
    1246              : /* Build a representation of the identity conversion from EXPR to
    1247              :    itself.  The TYPE should match the type of EXPR, if EXPR is non-NULL.  */
    1248              : 
    1249              : static conversion *
    1250   1975813631 : build_identity_conv (tree type, tree expr)
    1251              : {
    1252   1975813631 :   conversion *c;
    1253              : 
    1254            0 :   c = alloc_conversion (ck_identity);
    1255   1975813631 :   c->type = type;
    1256   1975813631 :   c->u.expr = expr;
    1257              : 
    1258   1975813631 :   return c;
    1259              : }
    1260              : 
    1261              : /* Converting from EXPR to TYPE was ambiguous in the sense that there
    1262              :    were multiple user-defined conversions to accomplish the job.
    1263              :    Build a conversion that indicates that ambiguity.  */
    1264              : 
    1265              : static conversion *
    1266         1346 : build_ambiguous_conv (tree type, tree expr)
    1267              : {
    1268         1346 :   conversion *c;
    1269              : 
    1270            0 :   c = alloc_conversion (ck_ambig);
    1271         1346 :   c->type = type;
    1272         1346 :   c->u.expr = expr;
    1273              : 
    1274         1346 :   return c;
    1275              : }
    1276              : 
    1277              : tree
    1278   3539820680 : strip_top_quals (tree t)
    1279              : {
    1280   3539820680 :   if (TREE_CODE (t) == ARRAY_TYPE)
    1281              :     return t;
    1282   3532610106 :   return cp_build_qualified_type (t, 0);
    1283              : }
    1284              : 
    1285              : /* Returns the standard conversion path (see [conv]) from type FROM to type
    1286              :    TO, if any.  For proper handling of null pointer constants, you must
    1287              :    also pass the expression EXPR to convert from.  If C_CAST_P is true,
    1288              :    this conversion is coming from a C-style cast.  */
    1289              : 
    1290              : static conversion *
    1291   1581881979 : standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
    1292              :                      int flags, tsubst_flags_t complain)
    1293              : {
    1294   1581881979 :   enum tree_code fcode, tcode;
    1295   1581881979 :   conversion *conv;
    1296   1581881979 :   bool fromref = false;
    1297   1581881979 :   tree qualified_to;
    1298              : 
    1299   1581881979 :   to = non_reference (to);
    1300   1581881979 :   if (TYPE_REF_P (from))
    1301              :     {
    1302        80780 :       fromref = true;
    1303        80780 :       from = TREE_TYPE (from);
    1304              :     }
    1305   1581881979 :   qualified_to = to;
    1306   1581881979 :   to = strip_top_quals (to);
    1307   1581881979 :   from = strip_top_quals (from);
    1308              : 
    1309   1581881979 :   if (expr && type_unknown_p (expr))
    1310              :     {
    1311       723017 :       if (TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
    1312              :         {
    1313        68041 :           tsubst_flags_t tflags = tf_conv;
    1314        68041 :           expr = instantiate_type (to, expr, tflags);
    1315        68041 :           if (expr == error_mark_node)
    1316              :             return NULL;
    1317        42664 :           from = TREE_TYPE (expr);
    1318              :         }
    1319       654976 :       else if (TREE_CODE (to) == BOOLEAN_TYPE)
    1320              :         {
    1321              :           /* Necessary for eg, TEMPLATE_ID_EXPRs (c++/50961).  */
    1322        12469 :           expr = resolve_nondeduced_context (expr, complain);
    1323        12469 :           from = TREE_TYPE (expr);
    1324              :         }
    1325              :     }
    1326              : 
    1327   1581856602 :   fcode = TREE_CODE (from);
    1328   1581856602 :   tcode = TREE_CODE (to);
    1329              : 
    1330   1581856602 :   conv = build_identity_conv (from, expr);
    1331   1581856602 :   if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
    1332              :     {
    1333      7233849 :       from = type_decays_to (from);
    1334      7233849 :       fcode = TREE_CODE (from);
    1335              :       /* Tell convert_like that we're using the address.  */
    1336      7233849 :       conv->rvaluedness_matches_p = true;
    1337      7233849 :       conv = build_conv (ck_lvalue, from, conv);
    1338              :     }
    1339              :   /* Wrapping a ck_rvalue around a class prvalue (as a result of using
    1340              :      obvalue_p) seems odd, since it's already a prvalue, but that's how we
    1341              :      express the copy constructor call required by copy-initialization.  */
    1342   1574622753 :   else if (fromref || (expr && obvalue_p (expr)))
    1343              :     {
    1344    366472513 :       if (expr)
    1345              :         {
    1346    366391745 :           tree bitfield_type;
    1347    366391745 :           bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1348    366391745 :           if (bitfield_type)
    1349              :             {
    1350      2929979 :               from = strip_top_quals (bitfield_type);
    1351      2929979 :               fcode = TREE_CODE (from);
    1352              :             }
    1353              :         }
    1354    366472513 :       conv = build_conv (ck_rvalue, from, conv);
    1355              :       /* If we're performing copy-initialization, remember to skip
    1356              :          explicit constructors.  */
    1357    366472513 :       if (flags & LOOKUP_ONLYCONVERTING)
    1358    314195724 :         conv->copy_init_p = true;
    1359              :     }
    1360              : 
    1361              :    /* Allow conversion between `__complex__' data types.  */
    1362   1581856602 :   if (tcode == COMPLEX_TYPE && fcode == COMPLEX_TYPE)
    1363              :     {
    1364              :       /* The standard conversion sequence to convert FROM to TO is
    1365              :          the standard conversion sequence to perform componentwise
    1366              :          conversion.  */
    1367      2392227 :       conversion *part_conv = standard_conversion
    1368      2392227 :         (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, c_cast_p, flags,
    1369              :          complain);
    1370              : 
    1371      2392227 :       if (!part_conv)
    1372              :         conv = NULL;
    1373      2392227 :       else if (part_conv->kind == ck_identity)
    1374              :         /* Leave conv alone.  */;
    1375              :       else
    1376              :         {
    1377       280500 :           conv = build_conv (part_conv->kind, to, conv);
    1378       280500 :           conv->rank = part_conv->rank;
    1379              :         }
    1380              : 
    1381              :       return conv;
    1382              :     }
    1383              : 
    1384   1579464375 :   if (same_type_p (from, to))
    1385              :     {
    1386    966444987 :       if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
    1387     17844230 :         conv->type = qualified_to;
    1388    948600757 :       else if (from != to)
    1389              :         /* Use TO in order to not lose TO in diagnostics.  */
    1390     82532525 :         conv->type = to;
    1391              :       return conv;
    1392              :     }
    1393              : 
    1394              :   /* [conv.ptr]
    1395              :      A null pointer constant can be converted to a pointer type; ... A
    1396              :      null pointer constant of integral type can be converted to an
    1397              :      rvalue of type std::nullptr_t. */
    1398    394411655 :   if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
    1399    394319806 :        || NULLPTR_TYPE_P (to))
    1400    619142867 :       && ((expr && null_ptr_cst_p (expr))
    1401    218989971 :           || NULLPTR_TYPE_P (from)))
    1402      5741245 :     conv = build_conv (ck_std, to, conv);
    1403    607278143 :   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
    1404    606570149 :            || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
    1405              :     {
    1406              :       /* For backwards brain damage compatibility, allow interconversion of
    1407              :          pointers and integers with a pedwarn.  */
    1408      2245353 :       conv = build_conv (ck_std, to, conv);
    1409      2245353 :       conv->bad_p = true;
    1410              :     }
    1411    605032790 :   else if (UNSCOPED_ENUM_P (to) && fcode == INTEGER_TYPE)
    1412              :     {
    1413              :       /* For backwards brain damage compatibility, allow interconversion of
    1414              :          enums and integers with a pedwarn.  */
    1415       365307 :       conv = build_conv (ck_std, to, conv);
    1416       365307 :       conv->bad_p = true;
    1417              :     }
    1418    604667483 :   else if ((tcode == POINTER_TYPE && fcode == POINTER_TYPE)
    1419    398389152 :            || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from)))
    1420              :     {
    1421         2765 :       tree to_pointee;
    1422         2765 :       tree from_pointee;
    1423              : 
    1424         2765 :       if (tcode == POINTER_TYPE)
    1425              :         {
    1426    206278331 :           to_pointee = TREE_TYPE (to);
    1427    206278331 :           from_pointee = TREE_TYPE (from);
    1428              : 
    1429              :           /* Since this is the target of a pointer, it can't have function
    1430              :              qualifiers, so any TYPE_QUALS must be for attributes const or
    1431              :              noreturn.  Strip them.  */
    1432    206278331 :           if (TREE_CODE (to_pointee) == FUNCTION_TYPE
    1433    206278331 :               && TYPE_QUALS (to_pointee))
    1434            9 :             to_pointee = build_qualified_type (to_pointee, TYPE_UNQUALIFIED);
    1435    206278331 :           if (TREE_CODE (from_pointee) == FUNCTION_TYPE
    1436    206278331 :               && TYPE_QUALS (from_pointee))
    1437           54 :             from_pointee = build_qualified_type (from_pointee, TYPE_UNQUALIFIED);
    1438              :         }
    1439              :       else
    1440              :         {
    1441         2765 :           to_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (to);
    1442         2765 :           from_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (from);
    1443              :         }
    1444              : 
    1445    206281096 :       if (tcode == POINTER_TYPE
    1446    206281096 :           && same_type_ignoring_top_level_qualifiers_p (from_pointee,
    1447              :                                                         to_pointee))
    1448              :         ;
    1449    146072534 :       else if (VOID_TYPE_P (to_pointee)
    1450      4632830 :                && !TYPE_PTRDATAMEM_P (from)
    1451      4632830 :                && TREE_CODE (from_pointee) != FUNCTION_TYPE)
    1452              :         {
    1453      4632418 :           tree nfrom = TREE_TYPE (from);
    1454              :           /* Don't try to apply restrict to void.  */
    1455      4632418 :           int quals = cp_type_quals (nfrom) & ~TYPE_QUAL_RESTRICT;
    1456      4632418 :           from_pointee = cp_build_qualified_type (void_type_node, quals);
    1457      4632418 :           from = build_pointer_type (from_pointee);
    1458      4632418 :           conv = build_conv (ck_ptr, from, conv);
    1459      4632418 :         }
    1460    141440116 :       else if (TYPE_PTRDATAMEM_P (from))
    1461              :         {
    1462         2765 :           tree fbase = TYPE_PTRMEM_CLASS_TYPE (from);
    1463         2765 :           tree tbase = TYPE_PTRMEM_CLASS_TYPE (to);
    1464              : 
    1465         2765 :           if (same_type_p (fbase, tbase))
    1466              :             /* No base conversion needed.  */;
    1467          619 :           else if (DERIVED_FROM_P (fbase, tbase)
    1468         1026 :                    && (same_type_ignoring_top_level_qualifiers_p
    1469          407 :                        (from_pointee, to_pointee)))
    1470              :             {
    1471          383 :               from = build_ptrmem_type (tbase, from_pointee);
    1472          383 :               conv = build_conv (ck_pmem, from, conv);
    1473              :             }
    1474              :           else
    1475              :             return NULL;
    1476              :         }
    1477     67726974 :       else if (CLASS_TYPE_P (from_pointee)
    1478     67724601 :                && CLASS_TYPE_P (to_pointee)
    1479              :                /* [conv.ptr]
    1480              : 
    1481              :                   An rvalue of type "pointer to cv D," where D is a
    1482              :                   class type, can be converted to an rvalue of type
    1483              :                   "pointer to cv B," where B is a base class (clause
    1484              :                   _class.derived_) of D.  If B is an inaccessible
    1485              :                   (clause _class.access_) or ambiguous
    1486              :                   (_class.member.lookup_) base class of D, a program
    1487              :                   that necessitates this conversion is ill-formed.
    1488              :                   Therefore, we use DERIVED_FROM_P, and do not check
    1489              :                   access or uniqueness.  */
    1490    208265159 :                && DERIVED_FROM_P (to_pointee, from_pointee))
    1491              :         {
    1492      6264301 :           from_pointee
    1493      6264301 :             = cp_build_qualified_type (to_pointee,
    1494              :                                        cp_type_quals (from_pointee));
    1495      6264301 :           from = build_pointer_type (from_pointee);
    1496      6264301 :           conv = build_conv (ck_ptr, from, conv);
    1497      6264301 :           conv->base_p = true;
    1498              :         }
    1499              : 
    1500    206280860 :       if (same_type_p (from, to))
    1501              :         /* OK */;
    1502    198070897 :       else if (c_cast_p && comp_ptr_ttypes_const (to, from, bounds_either))
    1503              :         /* In a C-style cast, we ignore CV-qualification because we
    1504              :            are allowed to perform a static_cast followed by a
    1505              :            const_cast.  */
    1506          636 :         conv = build_conv (ck_qual, to, conv);
    1507    198070261 :       else if (!c_cast_p && comp_ptr_ttypes (to_pointee, from_pointee))
    1508     55242944 :         conv = build_conv (ck_qual, to, conv);
    1509    142827317 :       else if (expr && string_conv_p (to, expr, 0))
    1510              :         /* converting from string constant to char *.  */
    1511          204 :         conv = build_conv (ck_qual, to, conv);
    1512    142827113 :       else if (fnptr_conv_p (to, from))
    1513       245465 :         conv = build_conv (ck_fnptr, to, conv);
    1514              :       /* Allow conversions among compatible ObjC pointer types (base
    1515              :          conversions have been already handled above).  */
    1516    142581648 :       else if (c_dialect_objc ()
    1517    142581648 :                && objc_compare_types (to, from, -4, NULL_TREE))
    1518            0 :         conv = build_conv (ck_ptr, to, conv);
    1519    142581648 :       else if (ptr_reasonably_similar (to_pointee, from_pointee))
    1520              :         {
    1521      8671161 :           conv = build_conv (ck_ptr, to, conv);
    1522      8671161 :           conv->bad_p = true;
    1523              :         }
    1524              :       else
    1525              :         return NULL;
    1526              : 
    1527    279693088 :       from = to;
    1528              :     }
    1529    398386387 :   else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
    1530              :     {
    1531        86685 :       tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
    1532        86685 :       tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
    1533        86685 :       tree fbase = class_of_this_parm (fromfn);
    1534        86685 :       tree tbase = class_of_this_parm (tofn);
    1535              : 
    1536              :       /* If FBASE and TBASE are equivalent but incomplete, DERIVED_FROM_P
    1537              :          yields false.  But a pointer to member of incomplete class is OK.  */
    1538        86685 :       if (!same_type_p (fbase, tbase) && !DERIVED_FROM_P (fbase, tbase))
    1539              :         return NULL;
    1540              : 
    1541        86524 :       tree fstat = static_fn_type (fromfn);
    1542        86524 :       tree tstat = static_fn_type (tofn);
    1543        86524 :       if (same_type_p (tstat, fstat)
    1544        86524 :           || fnptr_conv_p (tstat, fstat))
    1545              :         /* OK */;
    1546              :       else
    1547              :         return NULL;
    1548              : 
    1549        86256 :       if (!same_type_p (fbase, tbase))
    1550              :         {
    1551        86143 :           tree first = to;
    1552        86143 :           if (!same_type_p (tstat, fstat))
    1553              :             {
    1554            0 :               first = build_memfn_type (fstat,
    1555              :                                         tbase,
    1556              :                                         cp_type_quals (tbase),
    1557              :                                         type_memfn_rqual (tofn));
    1558            0 :               first = build_ptrmemfunc_type (build_pointer_type (first));
    1559              :             }
    1560        86143 :           conv = build_conv (ck_pmem, first, conv);
    1561        86143 :           conv->base_p = true;
    1562              :         }
    1563        86256 :       if (fnptr_conv_p (tstat, fstat))
    1564          113 :         conv = build_conv (ck_fnptr, to, conv);
    1565              :     }
    1566    398299702 :   else if (tcode == BOOLEAN_TYPE)
    1567              :     {
    1568              :       /* [conv.bool]
    1569              : 
    1570              :           A prvalue of arithmetic, unscoped enumeration, pointer, or pointer
    1571              :           to member type can be converted to a prvalue of type bool. ...
    1572              :           For direct-initialization (8.5 [dcl.init]), a prvalue of type
    1573              :           std::nullptr_t can be converted to a prvalue of type bool;  */
    1574     12497518 :       if (ARITHMETIC_TYPE_P (from)
    1575      2199445 :           || UNSCOPED_ENUM_P (from)
    1576      4268806 :           || fcode == POINTER_TYPE
    1577      2998082 :           || TYPE_PTRMEM_P (from)
    1578      2997841 :           || NULLPTR_TYPE_P (from))
    1579              :         {
    1580      9499759 :           conv = build_conv (ck_std, to, conv);
    1581      9499759 :           if (fcode == POINTER_TYPE
    1582      8229035 :               || TYPE_PTRDATAMEM_P (from)
    1583      8228880 :               || (TYPE_PTRMEMFUNC_P (from)
    1584           86 :                   && conv->rank < cr_pbool)
    1585     17728553 :               || NULLPTR_TYPE_P (from))
    1586      1271047 :             conv->rank = cr_pbool;
    1587      9499759 :           if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
    1588           40 :             conv->bad_p = true;
    1589      9499759 :           if (flags & LOOKUP_NO_NARROWING)
    1590        31627 :             conv->check_narrowing = true;
    1591              :           return conv;
    1592              :         }
    1593              : 
    1594              :       return NULL;
    1595              :     }
    1596              :   /* We don't check for ENUMERAL_TYPE here because there are no standard
    1597              :      conversions to enum type.  */
    1598              :   /* As an extension, allow conversion to complex type.  */
    1599    385802184 :   else if (ARITHMETIC_TYPE_P (to))
    1600              :     {
    1601     32107609 :       if (! (INTEGRAL_CODE_P (fcode)
    1602     25180645 :              || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
    1603    232013703 :           || SCOPED_ENUM_P (from))
    1604              :         return NULL;
    1605              : 
    1606              :       /* If we're parsing an enum with no fixed underlying type, we're
    1607              :          dealing with an incomplete type, which renders the conversion
    1608              :          ill-formed.  */
    1609    198415580 :       if (!COMPLETE_TYPE_P (from))
    1610              :         return NULL;
    1611              : 
    1612    198415574 :       conv = build_conv (ck_std, to, conv);
    1613              : 
    1614    198415574 :       tree underlying_type = NULL_TREE;
    1615    198415574 :       if (TREE_CODE (from) == ENUMERAL_TYPE
    1616    198415574 :           && ENUM_FIXED_UNDERLYING_TYPE_P (from))
    1617      1721160 :         underlying_type = ENUM_UNDERLYING_TYPE (from);
    1618              : 
    1619              :       /* Give this a better rank if it's a promotion.
    1620              : 
    1621              :          To handle CWG 1601, also bump the rank if we are converting
    1622              :          an enumeration with a fixed underlying type to the underlying
    1623              :          type.  */
    1624    198415574 :       if ((same_type_p (to, type_promotes_to (from))
    1625    186362066 :            || (underlying_type && same_type_p (to, underlying_type)))
    1626    198415593 :           && next_conversion (conv)->rank <= cr_promotion)
    1627     12053527 :         conv->rank = cr_promotion;
    1628              : 
    1629              :       /* A prvalue of floating-point type can be converted to a prvalue of
    1630              :          another floating-point type with a greater or equal conversion
    1631              :          rank ([conv.rank]).  A prvalue of standard floating-point type can
    1632              :          be converted to a prvalue of another standard floating-point type.
    1633              :          For backwards compatibility with handling __float128 and other
    1634              :          non-standard floating point types, allow all implicit floating
    1635              :          point conversions if neither type is extended floating-point
    1636              :          type and if at least one of them is, fail if they have unordered
    1637              :          conversion rank or from has higher conversion rank.  */
    1638    198415574 :       if (fcode == REAL_TYPE
    1639    198415574 :           && tcode == REAL_TYPE
    1640     17152321 :           && (extended_float_type_p (from)
    1641     16328586 :               || extended_float_type_p (to))
    1642    202374438 :           && cp_compare_floating_point_conversion_ranks (from, to) >= 2)
    1643      1816500 :         conv->bad_p = true;
    1644              :     }
    1645    178969126 :   else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
    1646    178969126 :            && vector_types_convertible_p (from, to, false))
    1647         4905 :     return build_conv (ck_std, to, conv);
    1648    178964221 :   else if (MAYBE_CLASS_TYPE_P (to) && MAYBE_CLASS_TYPE_P (from)
    1649     70315304 :            && is_properly_derived_from (from, to))
    1650              :     {
    1651       468980 :       if (conv->kind == ck_rvalue)
    1652       468929 :         conv = next_conversion (conv);
    1653       468980 :       conv = build_conv (ck_base, to, conv);
    1654              :       /* The derived-to-base conversion indicates the initialization
    1655              :          of a parameter with base type from an object of a derived
    1656              :          type.  A temporary object is created to hold the result of
    1657              :          the conversion unless we're binding directly to a reference.  */
    1658       468980 :       conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
    1659              :       /* If we're performing copy-initialization, remember to skip
    1660              :          explicit constructors.  */
    1661       468980 :       if (flags & LOOKUP_ONLYCONVERTING)
    1662       468913 :         conv->copy_init_p = true;
    1663              :     }
    1664              :   else
    1665              :     return NULL;
    1666              : 
    1667    279693088 :   if (flags & LOOKUP_NO_NARROWING)
    1668     96326738 :     conv->check_narrowing = true;
    1669              : 
    1670              :   return conv;
    1671              : }
    1672              : 
    1673              : /* Returns nonzero if T1 is reference-related to T2.
    1674              : 
    1675              :    This is considered when a reference to T1 is initialized by a T2.  */
    1676              : 
    1677              : bool
    1678    284278431 : reference_related_p (tree t1, tree t2)
    1679              : {
    1680    284278431 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1681              :     return false;
    1682              : 
    1683    284278427 :   t1 = TYPE_MAIN_VARIANT (t1);
    1684    284278427 :   t2 = TYPE_MAIN_VARIANT (t2);
    1685              : 
    1686              :   /* [dcl.init.ref]
    1687              : 
    1688              :      Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
    1689              :      to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2.  */
    1690    284278427 :   return (similar_type_p (t1, t2)
    1691    284278427 :           || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    1692     68697302 :               && DERIVED_FROM_P (t1, t2)));
    1693              : }
    1694              : 
    1695              : /* Returns nonzero if T1 is reference-compatible with T2.  */
    1696              : 
    1697              : bool
    1698    252172216 : reference_compatible_p (tree t1, tree t2)
    1699              : {
    1700              :   /* [dcl.init.ref]
    1701              : 
    1702              :      "cv1 T1" is reference compatible with "cv2 T2" if
    1703              :      a prvalue of type "pointer to cv2 T2" can be converted to the type
    1704              :      "pointer to cv1 T1" via a standard conversion sequence.  */
    1705    252172216 :   tree ptype1 = build_pointer_type (t1);
    1706    252172216 :   tree ptype2 = build_pointer_type (t2);
    1707    252172216 :   conversion *conv = standard_conversion (ptype1, ptype2, NULL_TREE,
    1708              :                                           /*c_cast_p=*/false, 0, tf_none);
    1709    252172216 :   if (!conv || conv->bad_p)
    1710    140467077 :     return false;
    1711              :   return true;
    1712              : }
    1713              : 
    1714              : /* Return true if converting FROM to TO would involve a qualification
    1715              :    conversion.  */
    1716              : 
    1717              : static bool
    1718    122630657 : involves_qualification_conversion_p (tree to, tree from)
    1719              : {
    1720              :   /* If we're not converting a pointer to another one, we won't get
    1721              :      a qualification conversion.  */
    1722    122630657 :   if (!((TYPE_PTR_P (to) && TYPE_PTR_P (from))
    1723         3098 :         || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from))))
    1724              :     return false;
    1725              : 
    1726      4816616 :   conversion *conv = standard_conversion (to, from, NULL_TREE,
    1727              :                                           /*c_cast_p=*/false, 0, tf_none);
    1728     14432293 :   for (conversion *t = conv; t; t = next_conversion (t))
    1729      4816645 :     if (t->kind == ck_qual)
    1730              :       return true;
    1731              : 
    1732              :   return false;
    1733              : }
    1734              : 
    1735              : /* Return true if HANDLER is a match for exception object with EXCEPT_TYPE as
    1736              :    per [except.handle]/3.  */
    1737              : 
    1738              : bool
    1739        10656 : handler_match_for_exception_type (tree handler_type, tree except_type)
    1740              : {
    1741        10656 :   if (handler_type && TREE_CODE (handler_type) == HANDLER)
    1742         4241 :     handler_type = TREE_TYPE (handler_type);
    1743         4241 :   if (handler_type == NULL_TREE)
    1744              :     return true; /* ... */
    1745        10574 :   if (same_type_ignoring_top_level_qualifiers_p (handler_type, except_type))
    1746              :     return true;
    1747         6827 :   if (CLASS_TYPE_P (except_type) && CLASS_TYPE_P (handler_type))
    1748         3806 :     return publicly_uniquely_derived_p (handler_type, except_type);
    1749         3021 :   if (TYPE_PTR_P (handler_type) || TYPE_PTRMEM_P (handler_type))
    1750              :     {
    1751          813 :       if (TREE_CODE (except_type) == NULLPTR_TYPE)
    1752              :         return true;
    1753          748 :       if ((TYPE_PTR_P (handler_type) && TYPE_PTR_P (except_type))
    1754           80 :           || (TYPE_PTRDATAMEM_P (handler_type)
    1755           10 :               && TYPE_PTRDATAMEM_P (except_type))
    1756          844 :           || (TYPE_PTRMEMFUNC_P (handler_type)
    1757           16 :               && TYPE_PTRMEMFUNC_P (except_type)))
    1758              :         {
    1759          720 :           conversion *conv
    1760          720 :             = standard_conversion (handler_type, except_type, NULL_TREE,
    1761              :                                    /*c_cast_p=*/false, 0, tf_none);
    1762          720 :           if (conv && !conv->bad_p)
    1763              :             {
    1764          464 :               for (conversion *t = conv; t; t = next_conversion (t))
    1765          418 :                 switch (t->kind)
    1766              :                   {
    1767          336 :                   case ck_ptr:
    1768              :                     /* ...not involving conversions to pointers to private or
    1769              :                        protected or ambiguous classes, */
    1770          336 :                     if (CLASS_TYPE_P (TREE_TYPE (handler_type)))
    1771          320 :                       return (publicly_uniquely_derived_p
    1772          320 :                               (TREE_TYPE (handler_type),
    1773          640 :                                TREE_TYPE (except_type)));
    1774           98 :                     gcc_fallthrough ();
    1775           98 :                   case ck_fnptr:
    1776           98 :                   case ck_qual:
    1777           98 :                   case ck_identity:
    1778           98 :                     break;
    1779              :                   default:
    1780              :                     return false;
    1781              :                   }
    1782              :               return true;
    1783              :             }
    1784              :         }
    1785              :     }
    1786              :   return false;
    1787              : }
    1788              : 
    1789              : /* A reference of the indicated TYPE is being bound directly to the
    1790              :    expression represented by the implicit conversion sequence CONV.
    1791              :    Return a conversion sequence for this binding.  */
    1792              : 
    1793              : static conversion *
    1794    126415645 : direct_reference_binding (tree type, conversion *conv)
    1795              : {
    1796    126415645 :   tree t;
    1797              : 
    1798    126415645 :   gcc_assert (TYPE_REF_P (type));
    1799    126415645 :   gcc_assert (!TYPE_REF_P (conv->type));
    1800              : 
    1801    126415645 :   t = TREE_TYPE (type);
    1802              : 
    1803    126415645 :   if (conv->kind == ck_identity)
    1804              :     /* Mark the identity conv as to not decay to rvalue.  */
    1805    126415645 :     conv->rvaluedness_matches_p = true;
    1806              : 
    1807              :   /* [over.ics.rank]
    1808              : 
    1809              :      When a parameter of reference type binds directly
    1810              :      (_dcl.init.ref_) to an argument expression, the implicit
    1811              :      conversion sequence is the identity conversion, unless the
    1812              :      argument expression has a type that is a derived class of the
    1813              :      parameter type, in which case the implicit conversion sequence is
    1814              :      a derived-to-base Conversion.
    1815              : 
    1816              :      If the parameter binds directly to the result of applying a
    1817              :      conversion function to the argument expression, the implicit
    1818              :      conversion sequence is a user-defined conversion sequence
    1819              :      (_over.ics.user_), with the second standard conversion sequence
    1820              :      either an identity conversion or, if the conversion function
    1821              :      returns an entity of a type that is a derived class of the
    1822              :      parameter type, a derived-to-base conversion.  */
    1823    126415645 :   if (is_properly_derived_from (conv->type, t))
    1824              :     {
    1825              :       /* Represent the derived-to-base conversion.  */
    1826      3784988 :       conv = build_conv (ck_base, t, conv);
    1827              :       /* We will actually be binding to the base-class subobject in
    1828              :          the derived class, so we mark this conversion appropriately.
    1829              :          That way, convert_like knows not to generate a temporary.  */
    1830      3784988 :       conv->need_temporary_p = false;
    1831              :     }
    1832    122630657 :   else if (involves_qualification_conversion_p (t, conv->type))
    1833              :     /* Represent the qualification conversion.  After DR 2352
    1834              :        #1 and #2 were indistinguishable conversion sequences:
    1835              : 
    1836              :          void f(int*); // #1
    1837              :          void f(const int* const &); // #2
    1838              :          void g(int* p) { f(p); }
    1839              : 
    1840              :        because the types "int *" and "const int *const" are
    1841              :        reference-related and we were binding both directly and they
    1842              :        had the same rank.  To break it up, we add a ck_qual under the
    1843              :        ck_ref_bind so that conversion sequence ranking chooses #1.
    1844              : 
    1845              :        We strip_top_quals here which is also what standard_conversion
    1846              :        does.  Failure to do so would confuse comp_cv_qual_signature
    1847              :        into thinking that in
    1848              : 
    1849              :          void f(const int * const &); // #1
    1850              :          void f(const int *); // #2
    1851              :          int *x;
    1852              :          f(x);
    1853              : 
    1854              :        #2 is a better match than #1 even though they're ambiguous (97296).  */
    1855        17584 :     conv = build_conv (ck_qual, strip_top_quals (t), conv);
    1856              : 
    1857    126415645 :   return build_conv (ck_ref_bind, type, conv);
    1858              : }
    1859              : 
    1860              : /* Returns the conversion path from type FROM to reference type TO for
    1861              :    purposes of reference binding.  For lvalue binding, either pass a
    1862              :    reference type to FROM or an lvalue expression to EXPR.  If the
    1863              :    reference will be bound to a temporary, NEED_TEMPORARY_P is set for
    1864              :    the conversion returned.  If C_CAST_P is true, this
    1865              :    conversion is coming from a C-style cast.  */
    1866              : 
    1867              : static conversion *
    1868    251310569 : reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
    1869              :                    tsubst_flags_t complain)
    1870              : {
    1871    251310569 :   conversion *conv = NULL;
    1872    251310569 :   conversion *bad_direct_conv = nullptr;
    1873    251310569 :   tree to = TREE_TYPE (rto);
    1874    251310569 :   tree from = rfrom;
    1875    251310569 :   tree tfrom;
    1876    251310569 :   bool related_p;
    1877    251310569 :   bool compatible_p;
    1878    251310569 :   cp_lvalue_kind gl_kind;
    1879    251310569 :   bool is_lvalue;
    1880              : 
    1881    251310569 :   if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
    1882              :     {
    1883           52 :       expr = instantiate_type (to, expr, tf_none);
    1884           52 :       if (expr == error_mark_node)
    1885              :         return NULL;
    1886           52 :       from = TREE_TYPE (expr);
    1887              :     }
    1888              : 
    1889    251310569 :   bool copy_list_init = false;
    1890    251310569 :   bool single_list_conv = false;
    1891    251310569 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    1892              :     {
    1893       104965 :       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    1894              :       /* DR 1288: Otherwise, if the initializer list has a single element
    1895              :          of type E and ... [T's] referenced type is reference-related to E,
    1896              :          the object or reference is initialized from that element...
    1897              : 
    1898              :          ??? With P0388R4, we should bind 't' directly to U{}:
    1899              :            using U = A[2];
    1900              :            A (&&t)[] = {U{}};
    1901              :          because A[] and A[2] are reference-related.  But we don't do it
    1902              :          because grok_reference_init has deduced the array size (to 1), and
    1903              :          A[1] and A[2] aren't reference-related.  */
    1904       104965 :       if (CONSTRUCTOR_NELTS (expr) == 1
    1905        59954 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    1906              :         {
    1907         4352 :           tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    1908         4352 :           if (error_operand_p (elt))
    1909              :             return NULL;
    1910         4347 :           tree etype = TREE_TYPE (elt);
    1911         4347 :           if (reference_related_p (to, etype))
    1912              :             {
    1913          748 :               expr = elt;
    1914          748 :               from = etype;
    1915          748 :               goto skip;
    1916              :             }
    1917         3599 :           else if (CLASS_TYPE_P (etype) && TYPE_HAS_CONVERSION (etype))
    1918              :             /* CWG1996: jason's proposed drafting adds "or initializing T from E
    1919              :                would bind directly".  We check that in the direct binding with
    1920              :                conversion code below.  */
    1921              :             single_list_conv = true;
    1922              :         }
    1923              :       /* Otherwise, if T is a reference type, a prvalue temporary of the type
    1924              :          referenced by T is copy-list-initialized, and the reference is bound
    1925              :          to that temporary. */
    1926              :       copy_list_init = true;
    1927    251310564 :     skip:;
    1928              :     }
    1929              : 
    1930    251310564 :   if (TYPE_REF_P (from))
    1931              :     {
    1932        64116 :       from = TREE_TYPE (from);
    1933        64116 :       if (!TYPE_REF_IS_RVALUE (rfrom)
    1934        64116 :           || TREE_CODE (from) == FUNCTION_TYPE)
    1935              :         gl_kind = clk_ordinary;
    1936              :       else
    1937    251310564 :         gl_kind = clk_rvalueref;
    1938              :     }
    1939    251246448 :   else if (expr)
    1940    247750328 :     gl_kind = lvalue_kind (expr);
    1941      3208994 :   else if (CLASS_TYPE_P (from)
    1942      3496120 :            || TREE_CODE (from) == ARRAY_TYPE)
    1943              :     gl_kind = clk_class;
    1944              :   else
    1945              :     gl_kind = clk_none;
    1946              : 
    1947              :   /* Don't allow a class prvalue when LOOKUP_NO_TEMP_BIND.  */
    1948    251310564 :   if ((flags & LOOKUP_NO_TEMP_BIND)
    1949      3610497 :       && (gl_kind & clk_class))
    1950              :     gl_kind = clk_none;
    1951              : 
    1952              :   /* Same mask as real_lvalue_p.  */
    1953    248544983 :   is_lvalue = gl_kind && !(gl_kind & (clk_rvalueref|clk_class));
    1954              : 
    1955    213528772 :   tfrom = from;
    1956    213528772 :   if ((gl_kind & clk_bitfield) != 0)
    1957      2044189 :     tfrom = unlowered_expr_type (expr);
    1958              : 
    1959              :   /* Figure out whether or not the types are reference-related and
    1960              :      reference compatible.  We have to do this after stripping
    1961              :      references from FROM.  */
    1962    251310564 :   related_p = reference_related_p (to, tfrom);
    1963              :   /* If this is a C cast, first convert to an appropriately qualified
    1964              :      type, so that we can later do a const_cast to the desired type.  */
    1965    251310564 :   if (related_p && c_cast_p
    1966    251310564 :       && !at_least_as_qualified_p (to, tfrom))
    1967          200 :     to = cp_build_qualified_type (to, cp_type_quals (tfrom));
    1968    251310564 :   compatible_p = reference_compatible_p (to, tfrom);
    1969              : 
    1970              :   /* Directly bind reference when target expression's type is compatible with
    1971              :      the reference and expression is an lvalue. In DR391, the wording in
    1972              :      [8.5.3/5 dcl.init.ref] is changed to also require direct bindings for
    1973              :      const and rvalue references to rvalues of compatible class type.
    1974              :      We should also do direct bindings for non-class xvalues.  */
    1975    251310564 :   if ((related_p || compatible_p) && gl_kind)
    1976              :     {
    1977              :       /* [dcl.init.ref]
    1978              : 
    1979              :          If the initializer expression
    1980              : 
    1981              :          -- is an lvalue (but not an lvalue for a bit-field), and "cv1 T1"
    1982              :             is reference-compatible with "cv2 T2,"
    1983              : 
    1984              :          the reference is bound directly to the initializer expression
    1985              :          lvalue.
    1986              : 
    1987              :          [...]
    1988              :          If the initializer expression is an rvalue, with T2 a class type,
    1989              :          and "cv1 T1" is reference-compatible with "cv2 T2", the reference
    1990              :          is bound to the object represented by the rvalue or to a sub-object
    1991              :          within that object.  */
    1992              : 
    1993    112982872 :       conv = build_identity_conv (tfrom, expr);
    1994    112982872 :       conv = direct_reference_binding (rto, conv);
    1995              : 
    1996    112982872 :       if (TYPE_REF_P (rfrom))
    1997              :         /* Handle rvalue reference to function properly.  */
    1998        16443 :         conv->rvaluedness_matches_p
    1999        16443 :           = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
    2000              :       else
    2001    112966429 :         conv->rvaluedness_matches_p
    2002    112966429 :           = (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
    2003              : 
    2004    112982872 :       if ((gl_kind & clk_bitfield) != 0
    2005    112982872 :           || ((gl_kind & clk_packed) != 0 && !TYPE_PACKED (to)))
    2006              :         /* For the purposes of overload resolution, we ignore the fact
    2007              :            this expression is a bitfield or packed field. (In particular,
    2008              :            [over.ics.ref] says specifically that a function with a
    2009              :            non-const reference parameter is viable even if the
    2010              :            argument is a bitfield.)
    2011              : 
    2012              :            However, when we actually call the function we must create
    2013              :            a temporary to which to bind the reference.  If the
    2014              :            reference is volatile, or isn't const, then we cannot make
    2015              :            a temporary, so we just issue an error when the conversion
    2016              :            actually occurs.  */
    2017          110 :         conv->need_temporary_p = true;
    2018              : 
    2019              :       /* Don't allow binding of lvalues (other than function lvalues) to
    2020              :          rvalue references.  */
    2021     82959275 :       if (is_lvalue && TYPE_REF_IS_RVALUE (rto)
    2022    123191386 :           && TREE_CODE (to) != FUNCTION_TYPE)
    2023     10206515 :         conv->bad_p = true;
    2024              : 
    2025              :       /* Nor the reverse.  */
    2026     30023597 :       if (!is_lvalue && !TYPE_REF_IS_RVALUE (rto)
    2027              :           /* Unless it's really a C++20 lvalue being treated as an xvalue.
    2028              :              But in C++23, such an expression is just an xvalue, not a special
    2029              :              lvalue, so the binding is once again ill-formed.  */
    2030     18597674 :           && !(cxx_dialect <= cxx20
    2031     14792929 :                && (gl_kind & clk_implicit_rval))
    2032     17495699 :           && (!CP_TYPE_CONST_NON_VOLATILE_P (to)
    2033     17378028 :               || (flags & LOOKUP_NO_RVAL_BIND))
    2034    113100543 :           && TREE_CODE (to) != FUNCTION_TYPE)
    2035       117671 :         conv->bad_p = true;
    2036              : 
    2037    112982872 :       if (!compatible_p)
    2038      6667178 :         conv->bad_p = true;
    2039              : 
    2040              :       return conv;
    2041              :     }
    2042              :   /* [class.conv.fct] A conversion function is never used to convert a
    2043              :      (possibly cv-qualified) object to the (possibly cv-qualified) same
    2044              :      object type (or a reference to it), to a (possibly cv-qualified) base
    2045              :      class of that type (or a reference to it).... */
    2046      4530154 :   else if (!related_p
    2047    133797538 :            && !(flags & LOOKUP_NO_CONVERSION)
    2048     49437106 :            && (CLASS_TYPE_P (from) || single_list_conv))
    2049              :     {
    2050     17963670 :       tree rexpr = expr;
    2051     17963670 :       if (single_list_conv)
    2052          144 :         rexpr = CONSTRUCTOR_ELT (expr, 0)->value;
    2053              : 
    2054              :       /* [dcl.init.ref]
    2055              : 
    2056              :          If the initializer expression
    2057              : 
    2058              :          -- has a class type (i.e., T2 is a class type) can be
    2059              :             implicitly converted to an lvalue of type "cv3 T3," where
    2060              :             "cv1 T1" is reference-compatible with "cv3 T3".  (this
    2061              :             conversion is selected by enumerating the applicable
    2062              :             conversion functions (_over.match.ref_) and choosing the
    2063              :             best one through overload resolution.  (_over.match_).
    2064              : 
    2065              :         the reference is bound to the lvalue result of the conversion
    2066              :         in the second case.  */
    2067     17963670 :       z_candidate *cand = build_user_type_conversion_1 (rto, rexpr, flags,
    2068              :                                                         complain);
    2069     17963670 :       if (cand)
    2070              :         {
    2071        12702 :           if (!cand->second_conv->bad_p)
    2072              :             return cand->second_conv;
    2073              : 
    2074              :           /* Direct reference binding wasn't successful and yielded a bad
    2075              :              conversion.  Proceed with trying to go through a temporary
    2076              :              instead, and if that also fails then we'll return this bad
    2077              :              conversion rather than no conversion for sake of better
    2078              :              diagnostics.  */
    2079              :           bad_direct_conv = cand->second_conv;
    2080              :         }
    2081              :     }
    2082              : 
    2083              :   /* From this point on, we conceptually need temporaries, even if we
    2084              :      elide them.  Only the cases above are "direct bindings".  */
    2085    138315527 :   if (flags & LOOKUP_NO_TEMP_BIND)
    2086              :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2087              : 
    2088              :   /* [over.ics.rank]
    2089              : 
    2090              :      When a parameter of reference type is not bound directly to an
    2091              :      argument expression, the conversion sequence is the one required
    2092              :      to convert the argument expression to the underlying type of the
    2093              :      reference according to _over.best.ics_.  Conceptually, this
    2094              :      conversion sequence corresponds to copy-initializing a temporary
    2095              :      of the underlying type with the argument expression.  Any
    2096              :      difference in top-level cv-qualification is subsumed by the
    2097              :      initialization itself and does not constitute a conversion.  */
    2098              : 
    2099    134940385 :   bool maybe_valid_p = true;
    2100              : 
    2101              :   /* [dcl.init.ref]
    2102              : 
    2103              :      Otherwise, the reference shall be an lvalue reference to a
    2104              :      non-volatile const type, or the reference shall be an rvalue
    2105              :      reference.  */
    2106    178454912 :   if (!CP_TYPE_CONST_NON_VOLATILE_P (to) && !TYPE_REF_IS_RVALUE (rto))
    2107              :     maybe_valid_p = false;
    2108              : 
    2109              :   /* [dcl.init.ref]
    2110              : 
    2111              :      Otherwise, a temporary of type "cv1 T1" is created and
    2112              :      initialized from the initializer expression using the rules for a
    2113              :      non-reference copy initialization.  If T1 is reference-related to
    2114              :      T2, cv1 must be the same cv-qualification as, or greater
    2115              :      cv-qualification than, cv2; otherwise, the program is ill-formed.  */
    2116    134940385 :   if (related_p && !at_least_as_qualified_p (to, from))
    2117              :     maybe_valid_p = false;
    2118              : 
    2119              :   /* We try below to treat an invalid reference binding as a bad conversion
    2120              :      to improve diagnostics, but doing so may cause otherwise unnecessary
    2121              :      instantiations that can lead to a hard error.  So during the first pass
    2122              :      of overload resolution wherein we shortcut bad conversions, instead just
    2123              :      produce a special conversion indicating a second pass is necessary if
    2124              :      there's no strictly viable candidate.  */
    2125    134940385 :   if (!maybe_valid_p && (flags & LOOKUP_SHORTCUT_BAD_CONVS))
    2126              :     {
    2127      7758295 :       if (bad_direct_conv)
    2128              :         return bad_direct_conv;
    2129              : 
    2130      7757828 :       conv = alloc_conversion (ck_deferred_bad);
    2131      7757828 :       conv->bad_p = true;
    2132      7757828 :       return conv;
    2133              :     }
    2134              : 
    2135              :   /* We're generating a temporary now, but don't bind any more in the
    2136              :      conversion (specifically, don't slice the temporary returned by a
    2137              :      conversion operator).  */
    2138    127182090 :   flags |= LOOKUP_NO_TEMP_BIND;
    2139              : 
    2140              :   /* Core issue 899: When [copy-]initializing a temporary to be bound
    2141              :      to the first parameter of a copy constructor (12.8) called with
    2142              :      a single argument in the context of direct-initialization,
    2143              :      explicit conversion functions are also considered.
    2144              : 
    2145              :      So don't set LOOKUP_ONLYCONVERTING in that case.  */
    2146    127182090 :   if (!(flags & LOOKUP_COPY_PARM))
    2147    107775397 :     flags |= LOOKUP_ONLYCONVERTING;
    2148              : 
    2149    127182090 :   if (!conv)
    2150    127182090 :     conv = implicit_conversion (to, from, expr, c_cast_p,
    2151              :                                 flags, complain);
    2152    127182090 :   if (!conv)
    2153              :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2154              : 
    2155     12022705 :   if (conv->user_conv_p)
    2156              :     {
    2157      8097443 :       if (copy_list_init)
    2158              :         /* Remember this was copy-list-initialization.  */
    2159        74200 :         conv->need_temporary_p = true;
    2160              : 
    2161              :       /* If initializing the temporary used a conversion function,
    2162              :          recalculate the second conversion sequence.  */
    2163     23346691 :       for (conversion *t = conv; t; t = next_conversion (t))
    2164     15708378 :         if (t->kind == ck_user
    2165      8067369 :             && c_cast_p && !maybe_valid_p)
    2166              :           {
    2167           12 :             if (complain & tf_warning)
    2168           12 :               warning (OPT_Wcast_user_defined,
    2169              :                        "casting %qT to %qT does not use %qD",
    2170           12 :                        from, rto, t->cand->fn);
    2171              :             /* Don't let recalculation try to make this valid.  */
    2172              :             break;
    2173              :           }
    2174     15708366 :         else if (t->kind == ck_user
    2175     15708366 :                  && DECL_CONV_FN_P (t->cand->fn))
    2176              :           {
    2177       459118 :             tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn));
    2178              :             /* A prvalue of non-class type is cv-unqualified.  */
    2179       459118 :             if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype))
    2180         4174 :               ftype = cv_unqualified (ftype);
    2181       459118 :             int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND;
    2182       459118 :             conversion *new_second
    2183       459118 :               = reference_binding (rto, ftype, NULL_TREE, c_cast_p,
    2184              :                                    sflags, complain);
    2185       459118 :             if (!new_second)
    2186              :               return bad_direct_conv ? bad_direct_conv : nullptr;
    2187       459118 :             conv = merge_conversion_sequences (t, new_second);
    2188       459118 :             gcc_assert (maybe_valid_p || conv->bad_p);
    2189              :             return conv;
    2190              :           }
    2191              :     }
    2192              : 
    2193     11563587 :   conv = build_conv (ck_ref_bind, rto, conv);
    2194              :   /* This reference binding, unlike those above, requires the
    2195              :      creation of a temporary.  */
    2196     11563587 :   conv->need_temporary_p = true;
    2197     11563587 :   conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
    2198     11563587 :   conv->bad_p |= !maybe_valid_p;
    2199              : 
    2200     11563587 :   return conv;
    2201              : }
    2202              : 
    2203              : /* Returns the implicit conversion sequence (see [over.ics]) from type
    2204              :    FROM to type TO.  The optional expression EXPR may affect the
    2205              :    conversion.  FLAGS are the usual overloading flags.  If C_CAST_P is
    2206              :    true, this conversion is coming from a C-style cast.  */
    2207              : 
    2208              : static conversion *
    2209   1566816080 : implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
    2210              :                      int flags, tsubst_flags_t complain)
    2211              : {
    2212   1566816165 :   conversion *conv;
    2213              : 
    2214   1566816165 :   if (from == error_mark_node || to == error_mark_node
    2215   1566814600 :       || expr == error_mark_node)
    2216              :     return NULL;
    2217              : 
    2218              :   /* Other flags only apply to the primary function in overload
    2219              :      resolution, or after we've chosen one.  */
    2220   1566814600 :   flags &= (LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION|LOOKUP_COPY_PARM
    2221              :             |LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND|LOOKUP_NO_NARROWING
    2222              :             |LOOKUP_PROTECT|LOOKUP_NO_NON_INTEGRAL|LOOKUP_SHORTCUT_BAD_CONVS);
    2223              : 
    2224              :   /* FIXME: actually we don't want warnings either, but we can't just
    2225              :      have 'complain &= ~(tf_warning|tf_error)' because it would cause
    2226              :      the regression of, eg, g++.old-deja/g++.benjamin/16077.C.
    2227              :      We really ought not to issue that warning until we've committed
    2228              :      to that conversion.  */
    2229   1566814600 :   complain &= ~tf_error;
    2230              : 
    2231              :   /* Call reshape_init early to remove redundant braces.  */
    2232   1566814600 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) && CLASS_TYPE_P (to))
    2233              :     {
    2234      2420450 :       to = complete_type (to);
    2235      2420450 :       if (!COMPLETE_TYPE_P (to))
    2236              :         return nullptr;
    2237      2420426 :       if (!CLASSTYPE_NON_AGGREGATE (to))
    2238              :         {
    2239      1375628 :           expr = reshape_init (to, expr, complain);
    2240      1375628 :           if (expr == error_mark_node)
    2241              :             return nullptr;
    2242      1375385 :           from = TREE_TYPE (expr);
    2243              :         }
    2244              :     }
    2245              : 
    2246              :   /* An argument should have gone through convert_from_reference.  */
    2247   1566814333 :   gcc_checking_assert (!expr || !TYPE_REF_P (from));
    2248              : 
    2249   1566814333 :   if (TYPE_REF_P (to))
    2250    244314133 :     conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
    2251              :   else
    2252   1322500200 :     conv = standard_conversion (to, from, expr, c_cast_p, flags, complain);
    2253              : 
    2254   1566814333 :   if (conv)
    2255              :     return conv;
    2256              : 
    2257    308648355 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    2258              :     {
    2259      4952483 :       if (is_std_init_list (to) && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2260        96410 :         return build_list_conv (to, expr, flags, complain);
    2261              : 
    2262              :       /* As an extension, allow list-initialization of _Complex.  */
    2263      4759654 :       if (TREE_CODE (to) == COMPLEX_TYPE
    2264      4817015 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2265              :         {
    2266        57352 :           conv = build_complex_conv (to, expr, flags, complain);
    2267        57352 :           if (conv)
    2268              :             return conv;
    2269              :         }
    2270              : 
    2271              :       /* Allow conversion from an initializer-list with one element to a
    2272              :          scalar type.  */
    2273      4702342 :       if (SCALAR_TYPE_P (to))
    2274              :         {
    2275      2352608 :           int nelts = CONSTRUCTOR_NELTS (expr);
    2276       364492 :           tree elt;
    2277              : 
    2278       364492 :           if (nelts == 0)
    2279      1988116 :             elt = build_value_init (to, tf_none);
    2280       364492 :           else if (nelts == 1 && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2281       363618 :             elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2282              :           else
    2283          874 :             elt = error_mark_node;
    2284              : 
    2285      2352608 :           conv = implicit_conversion (to, TREE_TYPE (elt), elt,
    2286              :                                       c_cast_p, flags, complain);
    2287      2352608 :           if (conv)
    2288              :             {
    2289      2350596 :               conv->check_narrowing = true;
    2290      2350596 :               if (BRACE_ENCLOSED_INITIALIZER_P (elt))
    2291              :                 /* Too many levels of braces, i.e. '{{1}}'.  */
    2292           16 :                 conv->bad_p = true;
    2293              :               return conv;
    2294              :             }
    2295              :         }
    2296      2349734 :       else if (TREE_CODE (to) == ARRAY_TYPE)
    2297         1889 :         return build_array_conv (to, expr, flags, complain);
    2298              :     }
    2299              : 
    2300    306142148 :   if (expr != NULL_TREE
    2301    298964845 :       && (MAYBE_CLASS_TYPE_P (from)
    2302    161504421 :           || MAYBE_CLASS_TYPE_P (to))
    2303    522090055 :       && (flags & LOOKUP_NO_CONVERSION) == 0)
    2304              :     {
    2305     81284743 :       struct z_candidate *cand;
    2306              : 
    2307     55823998 :       if (CLASS_TYPE_P (to)
    2308     55823948 :           && BRACE_ENCLOSED_INITIALIZER_P (expr)
    2309     83608142 :           && !CLASSTYPE_NON_AGGREGATE (complete_type (to)))
    2310      1375326 :         return build_aggr_conv (to, expr, flags, complain);
    2311              : 
    2312     79909417 :       cand = build_user_type_conversion_1 (to, expr, flags, complain);
    2313     79909417 :       if (cand)
    2314              :         {
    2315       933763 :           if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    2316       923988 :               && CONSTRUCTOR_NELTS (expr) == 1
    2317        59172 :               && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    2318     15082133 :               && !is_list_ctor (cand->fn))
    2319              :             {
    2320              :               /* "If C is not an initializer-list constructor and the
    2321              :                  initializer list has a single element of type cv U, where U is
    2322              :                  X or a class derived from X, the implicit conversion sequence
    2323              :                  has Exact Match rank if U is X, or Conversion rank if U is
    2324              :                  derived from X."  */
    2325        58772 :               tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2326        58772 :               tree elttype = TREE_TYPE (elt);
    2327        58772 :               if (reference_related_p (to, elttype))
    2328              :                 return implicit_conversion (to, elttype, elt,
    2329              :                                             c_cast_p, flags, complain);
    2330              :             }
    2331     15022876 :           conv = cand->second_conv;
    2332              :         }
    2333              : 
    2334              :       /* We used to try to bind a reference to a temporary here, but that
    2335              :          is now handled after the recursive call to this function at the end
    2336              :          of reference_binding.  */
    2337              :       return conv;
    2338              :     }
    2339              : 
    2340              :   return NULL;
    2341              : }
    2342              : 
    2343              : /* Like implicit_conversion, but return NULL if the conversion is bad.
    2344              : 
    2345              :    This is not static so that check_non_deducible_conversion can call it within
    2346              :    add_template_candidate_real as part of overload resolution; it should not be
    2347              :    called outside of overload resolution.  */
    2348              : 
    2349              : conversion *
    2350      7365682 : good_conversion (tree to, tree from, tree expr,
    2351              :                  int flags, tsubst_flags_t complain)
    2352              : {
    2353      7365682 :   conversion *c = implicit_conversion (to, from, expr, /*cast*/false,
    2354              :                                        flags, complain);
    2355      7365682 :   if (c && c->bad_p)
    2356      3178042 :     c = NULL;
    2357      7365682 :   return c;
    2358              : }
    2359              : 
    2360              : /* Add a new entry to the list of candidates.  Used by the add_*_candidate
    2361              :    functions.  ARGS will not be changed until a single candidate is
    2362              :    selected.  */
    2363              : 
    2364              : static struct z_candidate *
    2365   1096199110 : add_candidate (struct z_candidate **candidates,
    2366              :                tree fn, tree first_arg, const vec<tree, va_gc> *args,
    2367              :                size_t num_convs, conversion **convs,
    2368              :                tree access_path, tree conversion_path,
    2369              :                int viable, struct rejection_reason *reason,
    2370              :                int flags)
    2371              : {
    2372   1096199110 :   struct z_candidate *cand = (struct z_candidate *)
    2373   1096199110 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2374              : 
    2375   1096199110 :   cand->fn = fn;
    2376   1096199110 :   cand->first_arg = first_arg;
    2377   1096199110 :   cand->args = args;
    2378   1096199110 :   cand->convs = convs;
    2379   1096199110 :   cand->num_convs = num_convs;
    2380   1096199110 :   cand->access_path = access_path;
    2381   1096199110 :   cand->conversion_path = conversion_path;
    2382   1096199110 :   cand->viable = viable;
    2383   1096199110 :   cand->reason = reason;
    2384   1096199110 :   cand->next = *candidates;
    2385   1096199110 :   cand->flags = flags;
    2386   1096199110 :   *candidates = cand;
    2387              : 
    2388   1096199110 :   if (convs && cand->reversed ())
    2389              :     /* Swap the conversions for comparison in joust; we'll swap them back
    2390              :        before build_over_call.  */
    2391     89782330 :     std::swap (convs[0], convs[1]);
    2392              : 
    2393   1096199110 :   return cand;
    2394              : }
    2395              : 
    2396              : /* FN is a function from the overload set that we outright didn't even
    2397              :    consider (for some reason); add it to the list as an non-viable "ignored"
    2398              :    candidate.  */
    2399              : 
    2400              : static z_candidate *
    2401    700424007 : add_ignored_candidate (z_candidate **candidates, tree fn)
    2402              : {
    2403              :   /* No need to dynamically allocate these.  */
    2404    700424007 :   static const rejection_reason reason_ignored = { rr_ignored, {} };
    2405              : 
    2406    700424007 :   struct z_candidate *cand = (struct z_candidate *)
    2407    700418550 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2408              : 
    2409    700424007 :   cand->fn = fn;
    2410    700424007 :   cand->reason = const_cast<rejection_reason *> (&reason_ignored);
    2411    700424007 :   cand->next = *candidates;
    2412    700424007 :   *candidates = cand;
    2413              : 
    2414    700424007 :   return cand;
    2415              : }
    2416              : 
    2417              : /* True iff CAND is a candidate added by add_ignored_candidate.  */
    2418              : 
    2419              : static bool
    2420    610422173 : ignored_candidate_p (const z_candidate *cand)
    2421              : {
    2422    610416066 :   return cand->reason && cand->reason->code == rr_ignored;
    2423              : }
    2424              : 
    2425              : /* Return the number of remaining arguments in the parameter list
    2426              :    beginning with ARG.  */
    2427              : 
    2428              : int
    2429    159191132 : remaining_arguments (tree arg)
    2430              : {
    2431    159191132 :   int n;
    2432              : 
    2433    276772906 :   for (n = 0; arg != NULL_TREE && arg != void_list_node;
    2434    117581774 :        arg = TREE_CHAIN (arg))
    2435    117581774 :     n++;
    2436              : 
    2437    159191132 :   return n;
    2438              : }
    2439              : 
    2440              : /* [over.match.copy]: When initializing a temporary object (12.2) to be bound
    2441              :    to the first parameter of a constructor where the parameter is of type
    2442              :    "reference to possibly cv-qualified T" and the constructor is called with a
    2443              :    single argument in the context of direct-initialization of an object of type
    2444              :    "cv2 T", explicit conversion functions are also considered.
    2445              : 
    2446              :    So set LOOKUP_COPY_PARM to let reference_binding know that
    2447              :    it's being called in that context.  */
    2448              : 
    2449              : int
    2450    456575046 : conv_flags (int i, int nargs, tree fn, tree arg, int flags)
    2451              : {
    2452    456575046 :   int lflags = flags;
    2453    456575046 :   tree t;
    2454    474201698 :   if (i == 0 && nargs == 1 && DECL_CONSTRUCTOR_P (fn)
    2455    151788773 :       && (t = FUNCTION_FIRST_USER_PARMTYPE (fn))
    2456    608363819 :       && (same_type_ignoring_top_level_qualifiers_p
    2457    151788773 :           (non_reference (TREE_VALUE (t)), DECL_CONTEXT (fn))))
    2458              :     {
    2459    118138122 :       if (!(flags & LOOKUP_ONLYCONVERTING))
    2460     35427557 :         lflags |= LOOKUP_COPY_PARM;
    2461    118138122 :       if ((flags & LOOKUP_LIST_INIT_CTOR)
    2462    118138122 :           && BRACE_ENCLOSED_INITIALIZER_P (arg))
    2463         1835 :         lflags |= LOOKUP_NO_CONVERSION;
    2464              :     }
    2465              :   else
    2466    338436924 :     lflags |= LOOKUP_ONLYCONVERTING;
    2467              : 
    2468    456575046 :   return lflags;
    2469              : }
    2470              : 
    2471              : /* Build an appropriate 'this' conversion for the method FN and class
    2472              :    type CTYPE from the value ARG (having type ARGTYPE) to the type PARMTYPE.
    2473              :    This function modifies PARMTYPE, ARGTYPE and ARG.  */
    2474              : 
    2475              : static conversion *
    2476     96280339 : build_this_conversion (tree fn, tree ctype,
    2477              :                        tree& parmtype, tree& argtype, tree& arg,
    2478              :                        int flags, tsubst_flags_t complain)
    2479              : {
    2480    192560678 :   gcc_assert (DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2481              :               && !DECL_CONSTRUCTOR_P (fn));
    2482              : 
    2483              :   /* The type of the implicit object parameter ('this') for
    2484              :      overload resolution is not always the same as for the
    2485              :      function itself; conversion functions are considered to
    2486              :      be members of the class being converted, and functions
    2487              :      introduced by a using-declaration are considered to be
    2488              :      members of the class that uses them.
    2489              : 
    2490              :      Since build_over_call ignores the ICS for the `this'
    2491              :      parameter, we can just change the parm type.  */
    2492     96280339 :   parmtype = cp_build_qualified_type (ctype,
    2493     96280339 :                                       cp_type_quals (TREE_TYPE (parmtype)));
    2494     96280339 :   bool this_p = true;
    2495     96280339 :   if (FUNCTION_REF_QUALIFIED (TREE_TYPE (fn)))
    2496              :     {
    2497              :       /* If the function has a ref-qualifier, the implicit
    2498              :          object parameter has reference type.  */
    2499       168511 :       bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
    2500       168511 :       parmtype = cp_build_reference_type (parmtype, rv);
    2501              :       /* The special handling of 'this' conversions in compare_ics
    2502              :          does not apply if there is a ref-qualifier.  */
    2503       168511 :       this_p = false;
    2504              :     }
    2505              :   else
    2506              :     {
    2507     96111828 :       parmtype = build_pointer_type (parmtype);
    2508              :       /* We don't use build_this here because we don't want to
    2509              :          capture the object argument until we've chosen a
    2510              :          non-static member function.  */
    2511     96111828 :       arg = build_address (arg);
    2512     96111828 :       argtype = lvalue_type (arg);
    2513              :     }
    2514     96280339 :   flags |= LOOKUP_ONLYCONVERTING;
    2515     96280339 :   conversion *t = implicit_conversion (parmtype, argtype, arg,
    2516              :                                        /*c_cast_p=*/false, flags, complain);
    2517     96280339 :   t->this_p = this_p;
    2518     96280339 :   return t;
    2519              : }
    2520              : 
    2521              : /* Create an overload candidate for the function or method FN called
    2522              :    with the argument list FIRST_ARG/ARGS and add it to CANDIDATES.
    2523              :    FLAGS is passed on to implicit_conversion.
    2524              : 
    2525              :    This does not change ARGS.
    2526              : 
    2527              :    CTYPE, if non-NULL, is the type we want to pretend this function
    2528              :    comes from for purposes of overload resolution.
    2529              : 
    2530              :    SHORTCUT_BAD_CONVS controls how we handle "bad" argument conversions.
    2531              :    If true, we stop computing conversions upon seeing the first bad
    2532              :    conversion.  This is used by add_candidates to avoid computing
    2533              :    more conversions than necessary in the presence of a strictly viable
    2534              :    candidate, while preserving the defacto behavior of overload resolution
    2535              :    when it turns out there are only non-strictly viable candidates.  */
    2536              : 
    2537              : static struct z_candidate *
    2538    647008716 : add_function_candidate (struct z_candidate **candidates,
    2539              :                         tree fn, tree ctype, tree first_arg,
    2540              :                         const vec<tree, va_gc> *args, tree access_path,
    2541              :                         tree conversion_path, int flags,
    2542              :                         conversion **convs,
    2543              :                         bool shortcut_bad_convs,
    2544              :                         tsubst_flags_t complain)
    2545              : {
    2546    647008716 :   tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2547    647008716 :   int i, len;
    2548    647008716 :   tree parmnode;
    2549    647008716 :   tree orig_first_arg = first_arg;
    2550    647008716 :   int skip;
    2551    647008716 :   int viable = 1;
    2552    647008716 :   struct rejection_reason *reason = NULL;
    2553              : 
    2554              :   /* The `this', `in_chrg' and VTT arguments to constructors are not
    2555              :      considered in overload resolution.  */
    2556   1294017432 :   if (DECL_CONSTRUCTOR_P (fn))
    2557              :     {
    2558    295255031 :       if (ctor_omit_inherited_parms (fn))
    2559              :         /* Bring back parameters omitted from an inherited ctor.  */
    2560          150 :         parmlist = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn));
    2561              :       else
    2562    295254956 :         parmlist = skip_artificial_parms_for (fn, parmlist);
    2563    295255031 :       skip = num_artificial_parms_for (fn);
    2564    295255031 :       if (skip > 0 && first_arg != NULL_TREE)
    2565              :         {
    2566    295255031 :           --skip;
    2567    295255031 :           first_arg = NULL_TREE;
    2568              :         }
    2569              :     }
    2570              :   else
    2571              :     skip = 0;
    2572              : 
    2573   1252428382 :   len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0);
    2574    647008716 :   if (!convs)
    2575    556451018 :     convs = alloc_conversions (len);
    2576              : 
    2577              :   /* 13.3.2 - Viable functions [over.match.viable]
    2578              :      First, to be a viable function, a candidate function shall have enough
    2579              :      parameters to agree in number with the arguments in the list.
    2580              : 
    2581              :      We need to check this first; otherwise, checking the ICSes might cause
    2582              :      us to produce an ill-formed template instantiation.  */
    2583              : 
    2584    647008716 :   parmnode = parmlist;
    2585   1322800326 :   for (i = 0; i < len; ++i)
    2586              :     {
    2587    754628339 :       if (parmnode == NULL_TREE || parmnode == void_list_node)
    2588              :         break;
    2589    675791610 :       parmnode = TREE_CHAIN (parmnode);
    2590              :     }
    2591              : 
    2592    647008716 :   if ((i < len && parmnode)
    2593    647008716 :       || !sufficient_parms_p (parmnode))
    2594              :     {
    2595    159186261 :       int remaining = remaining_arguments (parmnode);
    2596    159186261 :       viable = 0;
    2597    159186261 :       reason = arity_rejection (first_arg, i + remaining, len);
    2598              :     }
    2599              : 
    2600              :   /* An inherited constructor (12.6.3 [class.inhctor.init]) that has a first
    2601              :      parameter of type "reference to cv C" (including such a constructor
    2602              :      instantiated from a template) is excluded from the set of candidate
    2603              :      functions when used to construct an object of type D with an argument list
    2604              :      containing a single argument if C is reference-related to D.  */
    2605    589975388 :   if (viable && len == 1 && parmlist && DECL_CONSTRUCTOR_P (fn)
    2606    154254490 :       && flag_new_inheriting_ctors
    2607    801254521 :       && DECL_INHERITED_CTOR (fn))
    2608              :     {
    2609      1067484 :       tree ptype = non_reference (TREE_VALUE (parmlist));
    2610      1067484 :       tree dtype = DECL_CONTEXT (fn);
    2611      2134968 :       tree btype = DECL_INHERITED_CTOR_BASE (fn);
    2612      1067484 :       if (reference_related_p (ptype, dtype)
    2613      1067484 :           && reference_related_p (btype, ptype))
    2614              :         {
    2615       808279 :           viable = false;
    2616       808279 :           reason = inherited_ctor_rejection ();
    2617              :         }
    2618              :     }
    2619              : 
    2620              :   /* Second, for a function to be viable, its constraints must be
    2621              :      satisfied. */
    2622    647008716 :   if (flag_concepts && viable && !constraints_satisfied_p (fn))
    2623              :     {
    2624       199361 :       reason = constraint_failure ();
    2625       199361 :       viable = false;
    2626              :     }
    2627              : 
    2628              :   /* When looking for a function from a subobject from an implicit
    2629              :      copy/move constructor/operator=, don't consider anything that takes (a
    2630              :      reference to) an unrelated type.  See c++/44909 and core 1092.  */
    2631    647008716 :   if (viable && parmlist && (flags & LOOKUP_DEFAULTED))
    2632              :     {
    2633     80266522 :       if (DECL_CONSTRUCTOR_P (fn))
    2634              :         i = 1;
    2635     20900995 :       else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    2636     20900995 :                && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    2637              :         i = 2;
    2638              :       else
    2639              :         i = 0;
    2640     40133261 :       if (i && len == i)
    2641              :         {
    2642     22149226 :           parmnode = chain_index (i-1, parmlist);
    2643     22149226 :           if (!reference_related_p (non_reference (TREE_VALUE (parmnode)),
    2644              :                                     ctype))
    2645      4483776 :             viable = 0;
    2646              :         }
    2647              : 
    2648              :       /* This only applies at the top level.  */
    2649     35649485 :       flags &= ~LOOKUP_DEFAULTED;
    2650              :     }
    2651              : 
    2652    647008716 :   if (! viable)
    2653    164677677 :     goto out;
    2654              : 
    2655    482331039 :   if (shortcut_bad_convs)
    2656    482196677 :     flags |= LOOKUP_SHORTCUT_BAD_CONVS;
    2657              :   else
    2658       134362 :     flags &= ~LOOKUP_SHORTCUT_BAD_CONVS;
    2659              : 
    2660              :   /* Third, for F to be a viable function, there shall exist for each
    2661              :      argument an implicit conversion sequence that converts that argument
    2662              :      to the corresponding parameter of F.  */
    2663              : 
    2664    482331039 :   parmnode = parmlist;
    2665              : 
    2666    829000489 :   for (i = 0; i < len; ++i)
    2667              :     {
    2668    528156301 :       tree argtype, to_type;
    2669    528156301 :       tree arg;
    2670              : 
    2671    528156301 :       if (parmnode == void_list_node)
    2672              :         break;
    2673              : 
    2674    528156301 :       if (convs[i])
    2675              :         {
    2676              :           /* Already set during deduction.  */
    2677      6508431 :           parmnode = TREE_CHAIN (parmnode);
    2678      6508431 :           continue;
    2679              :         }
    2680              : 
    2681    521647870 :       if (i == 0 && first_arg != NULL_TREE)
    2682     92158907 :         arg = first_arg;
    2683              :       else
    2684    429488963 :         arg = const_cast<tree> (
    2685    822207926 :                 (*args)[i + skip - (first_arg != NULL_TREE ? 1 : 0)]);
    2686    521647870 :       argtype = lvalue_type (arg);
    2687              : 
    2688    521647870 :       conversion *t;
    2689    521647870 :       if (parmnode)
    2690              :         {
    2691    515983401 :           tree parmtype = TREE_VALUE (parmnode);
    2692    515983401 :           if (i == 0
    2693    416454983 :               && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2694   1005850697 :               && !DECL_CONSTRUCTOR_P (fn))
    2695     92145369 :             t = build_this_conversion (fn, ctype, parmtype, argtype, arg,
    2696              :                                        flags, complain);
    2697              :           else
    2698              :             {
    2699    423838032 :               int lflags = conv_flags (i, len-skip, fn, arg, flags);
    2700    423838032 :               t = implicit_conversion (parmtype, argtype, arg,
    2701              :                                        /*c_cast_p=*/false, lflags, complain);
    2702              :             }
    2703    515983401 :           to_type = parmtype;
    2704    515983401 :           parmnode = TREE_CHAIN (parmnode);
    2705              :         }
    2706              :       else
    2707              :         {
    2708      5664469 :           t = build_identity_conv (argtype, arg);
    2709      5664469 :           t->ellipsis_p = true;
    2710      5664469 :           to_type = argtype;
    2711              :         }
    2712              : 
    2713    521647870 :       convs[i] = t;
    2714    521647870 :       if (! t)
    2715              :         {
    2716    158849580 :           viable = 0;
    2717    158849580 :           reason = arg_conversion_rejection (first_arg, i, argtype, to_type,
    2718    158849580 :                                              EXPR_LOCATION (arg));
    2719    158849580 :           break;
    2720              :         }
    2721              : 
    2722    362798290 :       if (t->bad_p)
    2723              :         {
    2724     22670106 :           viable = -1;
    2725     22670106 :           reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type,
    2726     22670106 :                                                  EXPR_LOCATION (arg));
    2727     22670106 :           if (shortcut_bad_convs)
    2728              :             break;
    2729              :         }
    2730              :     }
    2731              : 
    2732    300844188 :  out:
    2733    647008716 :   return add_candidate (candidates, fn, orig_first_arg, args, len, convs,
    2734    647008716 :                         access_path, conversion_path, viable, reason, flags);
    2735              : }
    2736              : 
    2737              : /* Create an overload candidate for the conversion function FN which will
    2738              :    be invoked for expression OBJ, producing a pointer-to-function which
    2739              :    will in turn be called with the argument list FIRST_ARG/ARGLIST,
    2740              :    and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    2741              :    passed on to implicit_conversion.
    2742              : 
    2743              :    Actually, we don't really care about FN; we care about the type it
    2744              :    converts to.  There may be multiple conversion functions that will
    2745              :    convert to that type, and we rely on build_user_type_conversion_1 to
    2746              :    choose the best one; so when we create our candidate, we record the type
    2747              :    instead of the function.  */
    2748              : 
    2749              : static struct z_candidate *
    2750       119684 : add_conv_candidate (struct z_candidate **candidates, tree fn, tree obj,
    2751              :                     const vec<tree, va_gc> *arglist,
    2752              :                     tree access_path, tree conversion_path,
    2753              :                     tsubst_flags_t complain)
    2754              : {
    2755       119684 :   tree totype = TREE_TYPE (TREE_TYPE (fn));
    2756       119684 :   int i, len, viable, flags;
    2757       119684 :   tree parmlist, parmnode;
    2758       119684 :   conversion **convs;
    2759       119684 :   struct rejection_reason *reason;
    2760              : 
    2761       239589 :   for (parmlist = totype; TREE_CODE (parmlist) != FUNCTION_TYPE; )
    2762       119905 :     parmlist = TREE_TYPE (parmlist);
    2763       119684 :   parmlist = TYPE_ARG_TYPES (parmlist);
    2764              : 
    2765       119684 :   len = vec_safe_length (arglist) + 1;
    2766       119684 :   convs = alloc_conversions (len);
    2767       119684 :   parmnode = parmlist;
    2768       119684 :   viable = 1;
    2769       119684 :   flags = LOOKUP_IMPLICIT;
    2770       119684 :   reason = NULL;
    2771              : 
    2772              :   /* Don't bother looking up the same type twice.  */
    2773       119684 :   if (*candidates && (*candidates)->fn == totype)
    2774              :     return NULL;
    2775              : 
    2776       119669 :   if (!constraints_satisfied_p (fn))
    2777              :     {
    2778            9 :       reason = constraint_failure ();
    2779            9 :       viable = 0;
    2780            9 :       return add_candidate (candidates, fn, obj, arglist, len, convs,
    2781            9 :                             access_path, conversion_path, viable, reason, flags);
    2782              :     }
    2783              : 
    2784       380649 :   for (i = 0; i < len; ++i)
    2785              :     {
    2786       261289 :       tree arg, argtype, convert_type = NULL_TREE;
    2787       261289 :       conversion *t;
    2788              : 
    2789       261289 :       if (i == 0)
    2790              :         arg = obj;
    2791              :       else
    2792       141629 :         arg = (*arglist)[i - 1];
    2793       261289 :       argtype = lvalue_type (arg);
    2794              : 
    2795       261289 :       if (i == 0)
    2796              :         {
    2797       119660 :           t = build_identity_conv (argtype, NULL_TREE);
    2798       119660 :           t = build_conv (ck_user, totype, t);
    2799              :           /* Leave the 'cand' field null; we'll figure out the conversion in
    2800              :              convert_like if this candidate is chosen.  */
    2801       119660 :           convert_type = totype;
    2802              :         }
    2803       141629 :       else if (parmnode == void_list_node)
    2804              :         break;
    2805       141402 :       else if (parmnode)
    2806              :         {
    2807       141393 :           t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg,
    2808              :                                    /*c_cast_p=*/false, flags, complain);
    2809       141393 :           convert_type = TREE_VALUE (parmnode);
    2810              :         }
    2811              :       else
    2812              :         {
    2813            9 :           t = build_identity_conv (argtype, arg);
    2814            9 :           t->ellipsis_p = true;
    2815            9 :           convert_type = argtype;
    2816              :         }
    2817              : 
    2818       261062 :       convs[i] = t;
    2819       261062 :       if (! t)
    2820              :         break;
    2821              : 
    2822       260989 :       if (t->bad_p)
    2823              :         {
    2824           27 :           viable = -1;
    2825           72 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, arg, convert_type,
    2826           27 :                                                  EXPR_LOCATION (arg));
    2827              :         }
    2828              : 
    2829       260989 :       if (i == 0)
    2830       119660 :         continue;
    2831              : 
    2832       141329 :       if (parmnode)
    2833       141320 :         parmnode = TREE_CHAIN (parmnode);
    2834              :     }
    2835              : 
    2836       119660 :   if (i < len
    2837       119660 :       || ! sufficient_parms_p (parmnode))
    2838              :     {
    2839          324 :       int remaining = remaining_arguments (parmnode);
    2840          324 :       viable = 0;
    2841          324 :       reason = arity_rejection (NULL_TREE, i + remaining, len);
    2842              :     }
    2843              : 
    2844       119660 :   return add_candidate (candidates, totype, obj, arglist, len, convs,
    2845       119660 :                         access_path, conversion_path, viable, reason, flags);
    2846              : }
    2847              : 
    2848              : static void
    2849      9748743 : build_builtin_candidate (struct z_candidate **candidates, tree fnname,
    2850              :                          tree type1, tree type2, const vec<tree,va_gc> &args,
    2851              :                          tree *argtypes, int flags, tsubst_flags_t complain)
    2852              : {
    2853      9748743 :   conversion *t;
    2854      9748743 :   conversion **convs;
    2855      9748743 :   size_t num_convs;
    2856      9748743 :   int viable = 1;
    2857      9748743 :   tree types[2];
    2858      9748743 :   struct rejection_reason *reason = NULL;
    2859              : 
    2860      9748743 :   types[0] = type1;
    2861      9748743 :   types[1] = type2;
    2862              : 
    2863      9748743 :   num_convs = args.length ();
    2864      9748743 :   convs = alloc_conversions (num_convs);
    2865              : 
    2866              :   /* TRUTH_*_EXPR do "contextual conversion to bool", which means explicit
    2867              :      conversion ops are allowed.  We handle that here by just checking for
    2868              :      boolean_type_node because other operators don't ask for it.  COND_EXPR
    2869              :      also does contextual conversion to bool for the first operand, but we
    2870              :      handle that in build_conditional_expr, and type1 here is operand 2.  */
    2871      9748743 :   if (type1 != boolean_type_node)
    2872      9177146 :     flags |= LOOKUP_ONLYCONVERTING;
    2873              : 
    2874     28503592 :   for (unsigned i = 0; i < 2 && i < num_convs; ++i)
    2875              :     {
    2876     18754849 :       t = implicit_conversion (types[i], argtypes[i], args[i],
    2877              :                                /*c_cast_p=*/false, flags, complain);
    2878     18754849 :       if (! t)
    2879              :         {
    2880      1930614 :           viable = 0;
    2881              :           /* We need something for printing the candidate.  */
    2882      1930614 :           t = build_identity_conv (types[i], NULL_TREE);
    2883      1930614 :           reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i],
    2884      1930614 :                                              types[i], EXPR_LOCATION (args[i]));
    2885              :         }
    2886     16824235 :       else if (t->bad_p)
    2887              :         {
    2888          252 :           viable = 0;
    2889          252 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, args[i],
    2890              :                                                  types[i],
    2891          252 :                                                  EXPR_LOCATION (args[i]));
    2892              :         }
    2893     18754849 :       convs[i] = t;
    2894              :     }
    2895              : 
    2896              :   /* For COND_EXPR we rearranged the arguments; undo that now.  */
    2897      9748743 :   if (num_convs == 3)
    2898              :     {
    2899          159 :       convs[2] = convs[1];
    2900          159 :       convs[1] = convs[0];
    2901          159 :       t = implicit_conversion (boolean_type_node, argtypes[2], args[2],
    2902              :                                /*c_cast_p=*/false, flags,
    2903              :                                complain);
    2904          159 :       if (t)
    2905          159 :         convs[0] = t;
    2906              :       else
    2907              :         {
    2908            0 :           viable = 0;
    2909            0 :           reason = arg_conversion_rejection (NULL_TREE, 0, argtypes[2],
    2910              :                                              boolean_type_node,
    2911            0 :                                              EXPR_LOCATION (args[2]));
    2912              :         }
    2913              :     }
    2914              : 
    2915      9748743 :   add_candidate (candidates, fnname, /*first_arg=*/NULL_TREE, /*args=*/NULL,
    2916              :                  num_convs, convs,
    2917              :                  /*access_path=*/NULL_TREE,
    2918              :                  /*conversion_path=*/NULL_TREE,
    2919              :                  viable, reason, flags);
    2920      9748743 : }
    2921              : 
    2922              : static bool
    2923           12 : is_complete (tree t)
    2924              : {
    2925           12 :   return COMPLETE_TYPE_P (complete_type (t));
    2926              : }
    2927              : 
    2928              : /* Returns nonzero if TYPE is a promoted arithmetic type.  */
    2929              : 
    2930              : static bool
    2931         3139 : promoted_arithmetic_type_p (tree type)
    2932              : {
    2933              :   /* [over.built]
    2934              : 
    2935              :      In this section, the term promoted integral type is used to refer
    2936              :      to those integral types which are preserved by integral promotion
    2937              :      (including e.g.  int and long but excluding e.g.  char).
    2938              :      Similarly, the term promoted arithmetic type refers to promoted
    2939              :      integral types plus floating types.  */
    2940         3139 :   return ((CP_INTEGRAL_TYPE_P (type)
    2941          239 :            && same_type_p (type_promotes_to (type), type))
    2942         3139 :           || SCALAR_FLOAT_TYPE_P (type));
    2943              : }
    2944              : 
    2945              : /* Create any builtin operator overload candidates for the operator in
    2946              :    question given the converted operand types TYPE1 and TYPE2.  The other
    2947              :    args are passed through from add_builtin_candidates to
    2948              :    build_builtin_candidate.
    2949              : 
    2950              :    TYPE1 and TYPE2 may not be permissible, and we must filter them.
    2951              :    If CODE is requires candidates operands of the same type of the kind
    2952              :    of which TYPE1 and TYPE2 are, we add both candidates
    2953              :    CODE (TYPE1, TYPE1) and CODE (TYPE2, TYPE2).  */
    2954              : 
    2955              : static void
    2956     14310708 : add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
    2957              :                        enum tree_code code2, tree fnname, tree type1,
    2958              :                        tree type2, vec<tree,va_gc> &args, tree *argtypes,
    2959              :                        int flags, tsubst_flags_t complain)
    2960              : {
    2961     14310708 :   switch (code)
    2962              :     {
    2963           21 :     case POSTINCREMENT_EXPR:
    2964           21 :     case POSTDECREMENT_EXPR:
    2965           21 :       args[1] = integer_zero_node;
    2966           21 :       type2 = integer_type_node;
    2967           21 :       break;
    2968              :     default:
    2969              :       break;
    2970              :     }
    2971              : 
    2972     14310708 :   switch (code)
    2973              :     {
    2974              : 
    2975              : /* 4 For every pair (T, VQ), where T is an arithmetic type other than bool,
    2976              :      and  VQ  is  either  volatile or empty, there exist candidate operator
    2977              :      functions of the form
    2978              :              VQ T&   operator++(VQ T&);
    2979              :              T       operator++(VQ T&, int);
    2980              :    5 For every pair (T, VQ), where T is an arithmetic type other than bool,
    2981              :      and VQ is either volatile or empty, there exist candidate operator
    2982              :      functions of the form
    2983              :              VQ T&   operator--(VQ T&);
    2984              :              T       operator--(VQ T&, int);
    2985              :    6 For every pair (T, VQ), where T is a cv-qualified or cv-unqualified object
    2986              :      type, and VQ is either volatile or empty, there exist candidate operator
    2987              :      functions of the form
    2988              :              T*VQ&   operator++(T*VQ&);
    2989              :              T*VQ&   operator--(T*VQ&);
    2990              :              T*      operator++(T*VQ&, int);
    2991              :              T*      operator--(T*VQ&, int);  */
    2992              : 
    2993           18 :     case POSTDECREMENT_EXPR:
    2994           18 :     case PREDECREMENT_EXPR:
    2995           18 :       if (TREE_CODE (type1) == BOOLEAN_TYPE)
    2996              :         return;
    2997              :       /* FALLTHRU */
    2998           39 :     case POSTINCREMENT_EXPR:
    2999           39 :     case PREINCREMENT_EXPR:
    3000              :       /* P0002R1, Remove deprecated operator++(bool) added "other than bool"
    3001              :          to p4.  */
    3002           39 :       if (TREE_CODE (type1) == BOOLEAN_TYPE && cxx_dialect >= cxx17)
    3003              :         return;
    3004           33 :       if (ARITHMETIC_TYPE_P (type1) || TYPE_PTROB_P (type1))
    3005              :         {
    3006           24 :           type1 = build_reference_type (type1);
    3007           24 :           break;
    3008              :         }
    3009              :       return;
    3010              : 
    3011              : /* 7 For every cv-qualified or cv-unqualified object type T, there
    3012              :      exist candidate operator functions of the form
    3013              : 
    3014              :              T&      operator*(T*);
    3015              : 
    3016              : 
    3017              :    8 For every function type T that does not have cv-qualifiers or
    3018              :      a ref-qualifier, there exist candidate operator functions of the form
    3019              :              T&      operator*(T*);  */
    3020              : 
    3021       113361 :     case INDIRECT_REF:
    3022       113361 :       if (TYPE_PTR_P (type1)
    3023       113361 :           && (TYPE_PTROB_P (type1)
    3024           12 :               || TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE))
    3025              :         break;
    3026              :       return;
    3027              : 
    3028              : /* 9 For every type T, there exist candidate operator functions of the form
    3029              :              T*      operator+(T*);
    3030              : 
    3031              :    10 For every floating-point or promoted integral type T, there exist
    3032              :       candidate operator functions of the form
    3033              :              T       operator+(T);
    3034              :              T       operator-(T);  */
    3035              : 
    3036          481 :     case UNARY_PLUS_EXPR: /* unary + */
    3037          481 :       if (TYPE_PTR_P (type1))
    3038              :         break;
    3039              :       /* FALLTHRU */
    3040       212165 :     case NEGATE_EXPR:
    3041       212165 :       if (ARITHMETIC_TYPE_P (type1))
    3042              :         break;
    3043              :       return;
    3044              : 
    3045              : /* 11 For every promoted integral type T,  there  exist  candidate  operator
    3046              :       functions of the form
    3047              :              T       operator~(T);  */
    3048              : 
    3049       160905 :     case BIT_NOT_EXPR:
    3050       160905 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1))
    3051              :         break;
    3052              :       return;
    3053              : 
    3054              : /* 12 For every quintuple (C1, C2, T, CV1, CV2), where C2 is a class type, C1
    3055              :      is the same type as C2 or is a derived class of C2, and T is an object
    3056              :      type or a function type there exist candidate operator functions of the
    3057              :      form
    3058              :              CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
    3059              :      where CV12 is the union of CV1 and CV2.  */
    3060              : 
    3061           34 :     case MEMBER_REF:
    3062           34 :       if (TYPE_PTR_P (type1) && TYPE_PTRMEM_P (type2))
    3063              :         {
    3064           34 :           tree c1 = TREE_TYPE (type1);
    3065           34 :           tree c2 = TYPE_PTRMEM_CLASS_TYPE (type2);
    3066              : 
    3067           31 :           if (CLASS_TYPE_P (c1) && DERIVED_FROM_P (c2, c1)
    3068           62 :               && (TYPE_PTRMEMFUNC_P (type2)
    3069           12 :                   || is_complete (TYPE_PTRMEM_POINTED_TO_TYPE (type2))))
    3070              :             break;
    3071              :         }
    3072              :       return;
    3073              : 
    3074              : /* 13 For every pair of types L and R, where each of L and R is a floating-point
    3075              :       or promoted integral type, there exist candidate operator functions of the
    3076              :       form
    3077              :              LR      operator*(L, R);
    3078              :              LR      operator/(L, R);
    3079              :              LR      operator+(L, R);
    3080              :              LR      operator-(L, R);
    3081              :              bool    operator<(L, R);
    3082              :              bool    operator>(L, R);
    3083              :              bool    operator<=(L, R);
    3084              :              bool    operator>=(L, R);
    3085              :              bool    operator==(L, R);
    3086              :              bool    operator!=(L, R);
    3087              :       where  LR  is  the  result of the usual arithmetic conversions between
    3088              :       types L and R.
    3089              : 
    3090              :    14 For every integral type T there exists a candidate operator function of
    3091              :       the form
    3092              : 
    3093              :        std::strong_ordering operator<=>(T, T);
    3094              : 
    3095              :    15 For every pair of floating-point types L and R, there exists a candidate
    3096              :       operator function of the form
    3097              : 
    3098              :        std::partial_ordering operator<=>(L, R);
    3099              : 
    3100              :    16 For every cv-qualified or cv-unqualified object type T there exist
    3101              :       candidate operator functions of the form
    3102              :              T*      operator+(T*, std::ptrdiff_t);
    3103              :              T&      operator[](T*, std::ptrdiff_t);
    3104              :              T*      operator-(T*, std::ptrdiff_t);
    3105              :              T*      operator+(std::ptrdiff_t, T*);
    3106              :              T&      operator[](std::ptrdiff_t, T*);
    3107              : 
    3108              :    17 For every T, where T is a pointer to object type, there exist candidate
    3109              :       operator functions of the form
    3110              :              std::ptrdiff_t operator-(T, T);
    3111              : 
    3112              :    18 For every T, where T is an enumeration type or a pointer type, there
    3113              :       exist candidate operator functions of the form
    3114              :              bool    operator<(T, T);
    3115              :              bool    operator>(T, T);
    3116              :              bool    operator<=(T, T);
    3117              :              bool    operator>=(T, T);
    3118              :              bool    operator==(T, T);
    3119              :              bool    operator!=(T, T);
    3120              :              R       operator<=>(T, T);
    3121              : 
    3122              :       where R is the result type specified in [expr.spaceship].
    3123              : 
    3124              :    19 For every T, where T is a pointer-to-member type or std::nullptr_t,
    3125              :       there exist candidate operator functions of the form
    3126              :              bool    operator==(T, T);
    3127              :              bool    operator!=(T, T);  */
    3128              : 
    3129       207265 :     case MINUS_EXPR:
    3130       207265 :       if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
    3131              :         break;
    3132           13 :       if (TYPE_PTROB_P (type1)
    3133       207251 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3134              :         {
    3135            4 :           type2 = ptrdiff_type_node;
    3136            4 :           break;
    3137              :         }
    3138              :       /* FALLTHRU */
    3139       901379 :     case MULT_EXPR:
    3140       901379 :     case TRUNC_DIV_EXPR:
    3141       901379 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3142              :         break;
    3143              :       return;
    3144              : 
    3145              :       /* This isn't exactly what's specified above for operator<=>, but it's
    3146              :          close enough.  In particular, we don't care about the return type
    3147              :          specified above; it doesn't participate in overload resolution and it
    3148              :          doesn't affect the semantics of the built-in operator.  */
    3149      6969006 :     case SPACESHIP_EXPR:
    3150      6969006 :     case EQ_EXPR:
    3151      6969006 :     case NE_EXPR:
    3152       222487 :       if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3153      7191493 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)))
    3154              :         break;
    3155      6968972 :       if (NULLPTR_TYPE_P (type1) && NULLPTR_TYPE_P (type2))
    3156              :         break;
    3157      6968966 :       if (TYPE_PTRMEM_P (type1) && null_ptr_cst_p (args[1]))
    3158              :         {
    3159              :           type2 = type1;
    3160              :           break;
    3161              :         }
    3162      6968963 :       if (TYPE_PTRMEM_P (type2) && null_ptr_cst_p (args[0]))
    3163              :         {
    3164              :           type1 = type2;
    3165              :           break;
    3166              :         }
    3167              :       /* Fall through.  */
    3168      7703745 :     case LT_EXPR:
    3169      7703745 :     case GT_EXPR:
    3170      7703745 :     case LE_EXPR:
    3171      7703745 :     case GE_EXPR:
    3172      7703745 :     case MAX_EXPR:
    3173      7703745 :     case MIN_EXPR:
    3174      7703745 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3175              :         break;
    3176      5982977 :       if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3177              :         break;
    3178      5979264 :       if (TREE_CODE (type1) == ENUMERAL_TYPE
    3179      4324695 :           && TREE_CODE (type2) == ENUMERAL_TYPE)
    3180              :         break;
    3181      2815477 :       if (TYPE_PTR_P (type1)
    3182      2815477 :           && null_ptr_cst_p (args[1]))
    3183              :         {
    3184              :           type2 = type1;
    3185              :           break;
    3186              :         }
    3187      2815458 :       if (null_ptr_cst_p (args[0])
    3188      2815458 :           && TYPE_PTR_P (type2))
    3189              :         {
    3190              :           type1 = type2;
    3191              :           break;
    3192              :         }
    3193              :       return;
    3194              : 
    3195       249530 :     case PLUS_EXPR:
    3196       249530 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3197              :         break;
    3198              :       /* FALLTHRU */
    3199       183533 :     case ARRAY_REF:
    3200       183533 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && TYPE_PTROB_P (type2))
    3201              :         {
    3202            6 :           type1 = ptrdiff_type_node;
    3203            6 :           break;
    3204              :         }
    3205       183527 :       if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3206              :         {
    3207        37745 :           type2 = ptrdiff_type_node;
    3208        37745 :           break;
    3209              :         }
    3210              :       return;
    3211              : 
    3212              : /* 18For  every pair of promoted integral types L and R, there exist candi-
    3213              :      date operator functions of the form
    3214              :              LR      operator%(L, R);
    3215              :              LR      operator&(L, R);
    3216              :              LR      operator^(L, R);
    3217              :              LR      operator|(L, R);
    3218              :              L       operator<<(L, R);
    3219              :              L       operator>>(L, R);
    3220              :      where LR is the result of the  usual  arithmetic  conversions  between
    3221              :      types L and R.  */
    3222              : 
    3223      3108270 :     case TRUNC_MOD_EXPR:
    3224      3108270 :     case BIT_AND_EXPR:
    3225      3108270 :     case BIT_IOR_EXPR:
    3226      3108270 :     case BIT_XOR_EXPR:
    3227      3108270 :     case LSHIFT_EXPR:
    3228      3108270 :     case RSHIFT_EXPR:
    3229      3108270 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3230              :         break;
    3231              :       return;
    3232              : 
    3233              : /* 19For  every  triple  L, VQ, R), where L is an arithmetic or enumeration
    3234              :      type, VQ is either volatile or empty, and R is a  promoted  arithmetic
    3235              :      type, there exist candidate operator functions of the form
    3236              :              VQ L&   operator=(VQ L&, R);
    3237              :              VQ L&   operator*=(VQ L&, R);
    3238              :              VQ L&   operator/=(VQ L&, R);
    3239              :              VQ L&   operator+=(VQ L&, R);
    3240              :              VQ L&   operator-=(VQ L&, R);
    3241              : 
    3242              :    20For  every  pair T, VQ), where T is any type and VQ is either volatile
    3243              :      or empty, there exist candidate operator functions of the form
    3244              :              T*VQ&   operator=(T*VQ&, T*);
    3245              : 
    3246              :    21For every pair T, VQ), where T is a pointer to member type and  VQ  is
    3247              :      either  volatile or empty, there exist candidate operator functions of
    3248              :      the form
    3249              :              VQ T&   operator=(VQ T&, T);
    3250              : 
    3251              :    22For every triple  T,  VQ,  I),  where  T  is  a  cv-qualified  or  cv-
    3252              :      unqualified  complete object type, VQ is either volatile or empty, and
    3253              :      I is a promoted integral type, there exist  candidate  operator  func-
    3254              :      tions of the form
    3255              :              T*VQ&   operator+=(T*VQ&, I);
    3256              :              T*VQ&   operator-=(T*VQ&, I);
    3257              : 
    3258              :    23For  every  triple  L,  VQ,  R), where L is an integral or enumeration
    3259              :      type, VQ is either volatile or empty, and R  is  a  promoted  integral
    3260              :      type, there exist candidate operator functions of the form
    3261              : 
    3262              :              VQ L&   operator%=(VQ L&, R);
    3263              :              VQ L&   operator<<=(VQ L&, R);
    3264              :              VQ L&   operator>>=(VQ L&, R);
    3265              :              VQ L&   operator&=(VQ L&, R);
    3266              :              VQ L&   operator^=(VQ L&, R);
    3267              :              VQ L&   operator|=(VQ L&, R);  */
    3268              : 
    3269      1805787 :     case MODIFY_EXPR:
    3270      1805787 :       switch (code2)
    3271              :         {
    3272       103954 :         case PLUS_EXPR:
    3273       103954 :         case MINUS_EXPR:
    3274       103954 :           if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3275              :             {
    3276            0 :               type2 = ptrdiff_type_node;
    3277            0 :               break;
    3278              :             }
    3279              :           /* FALLTHRU */
    3280       103982 :         case MULT_EXPR:
    3281       103982 :         case TRUNC_DIV_EXPR:
    3282       103982 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3283              :             break;
    3284              :           return;
    3285              : 
    3286      1701805 :         case TRUNC_MOD_EXPR:
    3287      1701805 :         case BIT_AND_EXPR:
    3288      1701805 :         case BIT_IOR_EXPR:
    3289      1701805 :         case BIT_XOR_EXPR:
    3290      1701805 :         case LSHIFT_EXPR:
    3291      1701805 :         case RSHIFT_EXPR:
    3292      1701805 :           if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3293              :             break;
    3294              :           return;
    3295              : 
    3296            0 :         case NOP_EXPR:
    3297            0 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3298              :             break;
    3299            0 :           if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3300            0 :               || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3301            0 :               || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3302            0 :               || ((TYPE_PTRMEMFUNC_P (type1)
    3303            0 :                    || TYPE_PTR_P (type1))
    3304            0 :                   && null_ptr_cst_p (args[1])))
    3305              :             {
    3306              :               type2 = type1;
    3307              :               break;
    3308              :             }
    3309              :           return;
    3310              : 
    3311            0 :         default:
    3312            0 :           gcc_unreachable ();
    3313              :         }
    3314      1456701 :       type1 = build_reference_type (type1);
    3315      1456701 :       break;
    3316              : 
    3317         2925 :     case COND_EXPR:
    3318              :       /* [over.built]
    3319              : 
    3320              :          For every pair of promoted arithmetic types L and R, there
    3321              :          exist candidate operator functions of the form
    3322              : 
    3323              :          LR operator?(bool, L, R);
    3324              : 
    3325              :          where LR is the result of the usual arithmetic conversions
    3326              :          between types L and R.
    3327              : 
    3328              :          For every type T, where T is a pointer or pointer-to-member
    3329              :          type, there exist candidate operator functions of the form T
    3330              :          operator?(bool, T, T);  */
    3331              : 
    3332         2925 :       if (promoted_arithmetic_type_p (type1)
    3333         2925 :           && promoted_arithmetic_type_p (type2))
    3334              :         /* That's OK.  */
    3335              :         break;
    3336              : 
    3337              :       /* Otherwise, the types should be pointers.  */
    3338         2900 :       if (!((TYPE_PTR_OR_PTRMEM_P (type1) || null_ptr_cst_p (args[0]))
    3339          369 :             && (TYPE_PTR_OR_PTRMEM_P (type2) || null_ptr_cst_p (args[1]))))
    3340              :         return;
    3341              : 
    3342              :       /* We don't check that the two types are the same; the logic
    3343              :          below will actually create two candidates; one in which both
    3344              :          parameter types are TYPE1, and one in which both parameter
    3345              :          types are TYPE2.  */
    3346              :       break;
    3347              : 
    3348            3 :     case REALPART_EXPR:
    3349            3 :     case IMAGPART_EXPR:
    3350            3 :       if (ARITHMETIC_TYPE_P (type1))
    3351              :         break;
    3352              :       return;
    3353              : 
    3354            0 :     default:
    3355            0 :       gcc_unreachable ();
    3356              :     }
    3357              : 
    3358              :   /* Make sure we don't create builtin candidates with dependent types.  */
    3359      9177021 :   bool u1 = uses_template_parms (type1);
    3360      9177021 :   bool u2 = type2 ? uses_template_parms (type2) : false;
    3361      9177008 :   if (u1 || u2)
    3362              :     {
    3363              :       /* Try to recover if one of the types is non-dependent.  But if
    3364              :          there's only one type, there's nothing we can do.  */
    3365           19 :       if (!type2)
    3366              :         return;
    3367              :       /* And we lose if both are dependent.  */
    3368           16 :       if (u1 && u2)
    3369              :         return;
    3370              :       /* Or if they have different forms.  */
    3371            9 :       if (TREE_CODE (type1) != TREE_CODE (type2))
    3372              :         return;
    3373              : 
    3374            9 :       if (u1 && !u2)
    3375              :         type1 = type2;
    3376            6 :       else if (u2 && !u1)
    3377      9177011 :         type2 = type1;
    3378              :     }
    3379              : 
    3380              :   /* If we're dealing with two pointer types or two enumeral types,
    3381              :      we need candidates for both of them.  */
    3382      8937125 :   if (type2 && !same_type_p (type1, type2)
    3383      1946587 :       && TREE_CODE (type1) == TREE_CODE (type2)
    3384      9628853 :       && (TYPE_REF_P (type1)
    3385       451842 :           || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3386       451726 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3387       451708 :           || TYPE_PTRMEMFUNC_P (type1)
    3388       451708 :           || MAYBE_CLASS_TYPE_P (type1)
    3389       451708 :           || TREE_CODE (type1) == ENUMERAL_TYPE))
    3390              :     {
    3391          229 :       if (TYPE_PTR_OR_PTRMEM_P (type1))
    3392              :         {
    3393          134 :           tree cptype = composite_pointer_type (input_location,
    3394              :                                                 type1, type2,
    3395              :                                                 error_mark_node,
    3396              :                                                 error_mark_node,
    3397              :                                                 CPO_CONVERSION,
    3398              :                                                 tf_none);
    3399          134 :           if (cptype != error_mark_node)
    3400              :             {
    3401           94 :               build_builtin_candidate
    3402           94 :                 (candidates, fnname, cptype, cptype, args, argtypes,
    3403              :                  flags, complain);
    3404           94 :               return;
    3405              :             }
    3406              :         }
    3407              : 
    3408          135 :       build_builtin_candidate
    3409          135 :         (candidates, fnname, type1, type1, args, argtypes, flags, complain);
    3410          135 :       build_builtin_candidate
    3411          135 :         (candidates, fnname, type2, type2, args, argtypes, flags, complain);
    3412          135 :       return;
    3413              :     }
    3414              : 
    3415      9176782 :   build_builtin_candidate
    3416      9176782 :     (candidates, fnname, type1, type2, args, argtypes, flags, complain);
    3417              : }
    3418              : 
    3419              : tree
    3420    864289724 : type_decays_to (tree type)
    3421              : {
    3422    864289724 :   if (TREE_CODE (type) == ARRAY_TYPE)
    3423      7274579 :     return build_pointer_type (TREE_TYPE (type));
    3424    857015145 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    3425        37687 :     return build_pointer_type (type);
    3426              :   return type;
    3427              : }
    3428              : 
    3429              : /* There are three conditions of builtin candidates:
    3430              : 
    3431              :    1) bool-taking candidates.  These are the same regardless of the input.
    3432              :    2) pointer-pair taking candidates.  These are generated for each type
    3433              :       one of the input types converts to.
    3434              :    3) arithmetic candidates.  According to the standard, we should generate
    3435              :       all of these, but I'm trying not to...
    3436              : 
    3437              :    Here we generate a superset of the possible candidates for this particular
    3438              :    case.  That is a subset of the full set the standard defines, plus some
    3439              :    other cases which the standard disallows. add_builtin_candidate will
    3440              :    filter out the invalid set.  */
    3441              : 
    3442              : static void
    3443     24843977 : add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
    3444              :                         enum tree_code code2, tree fnname,
    3445              :                         vec<tree, va_gc> *argv,
    3446              :                         int flags, tsubst_flags_t complain)
    3447              : {
    3448     24843977 :   int ref1;
    3449     24843977 :   int enum_p = 0;
    3450     24843977 :   tree type, argtypes[3], t;
    3451              :   /* TYPES[i] is the set of possible builtin-operator parameter types
    3452              :      we will consider for the Ith argument.  */
    3453     24843977 :   vec<tree, va_gc> *types[2];
    3454     24843977 :   unsigned ix;
    3455     24843977 :   vec<tree, va_gc> &args = *argv;
    3456     24843977 :   unsigned len = args.length ();
    3457              : 
    3458     69473097 :   for (unsigned i = 0; i < len; ++i)
    3459              :     {
    3460     44629120 :       if (args[i])
    3461     44629120 :         argtypes[i] = unlowered_expr_type (args[i]);
    3462              :       else
    3463              :         argtypes[i] = NULL_TREE;
    3464              :     }
    3465              : 
    3466     24843977 :   switch (code)
    3467              :     {
    3468              : /* 4 For every pair T, VQ), where T is an arithmetic or  enumeration  type,
    3469              :      and  VQ  is  either  volatile or empty, there exist candidate operator
    3470              :      functions of the form
    3471              :                  VQ T&   operator++(VQ T&);  */
    3472              : 
    3473              :     case POSTINCREMENT_EXPR:
    3474              :     case PREINCREMENT_EXPR:
    3475              :     case POSTDECREMENT_EXPR:
    3476              :     case PREDECREMENT_EXPR:
    3477              :     case MODIFY_EXPR:
    3478              :       ref1 = 1;
    3479              :       break;
    3480              : 
    3481              : /* 24There also exist candidate operator functions of the form
    3482              :              bool    operator!(bool);
    3483              :              bool    operator&&(bool, bool);
    3484              :              bool    operator||(bool, bool);  */
    3485              : 
    3486       502751 :     case TRUTH_NOT_EXPR:
    3487       502751 :       build_builtin_candidate
    3488       502751 :         (candidates, fnname, boolean_type_node,
    3489              :          NULL_TREE, args, argtypes, flags, complain);
    3490     13927666 :       return;
    3491              : 
    3492        68846 :     case TRUTH_ORIF_EXPR:
    3493        68846 :     case TRUTH_ANDIF_EXPR:
    3494        68846 :       build_builtin_candidate
    3495        68846 :         (candidates, fnname, boolean_type_node,
    3496              :          boolean_type_node, args, argtypes, flags, complain);
    3497        68846 :       return;
    3498              : 
    3499              :     case ADDR_EXPR:
    3500              :     case COMPOUND_EXPR:
    3501              :     case COMPONENT_REF:
    3502              :     case CO_AWAIT_EXPR:
    3503              :       return;
    3504              : 
    3505      6545047 :     case COND_EXPR:
    3506      6545047 :     case EQ_EXPR:
    3507      6545047 :     case NE_EXPR:
    3508      6545047 :     case LT_EXPR:
    3509      6545047 :     case LE_EXPR:
    3510      6545047 :     case GT_EXPR:
    3511      6545047 :     case GE_EXPR:
    3512      6545047 :     case SPACESHIP_EXPR:
    3513      6545047 :       enum_p = 1;
    3514              :       /* Fall through.  */
    3515              : 
    3516              :     default:
    3517              :       ref1 = 0;
    3518              :     }
    3519              : 
    3520     22087392 :   types[0] = make_tree_vector ();
    3521     22087392 :   types[1] = make_tree_vector ();
    3522              : 
    3523     22087392 :   if (len == 3)
    3524          738 :     len = 2;
    3525     45268285 :   for (unsigned i = 0; i < len; ++i)
    3526              :     {
    3527     33849223 :       if (MAYBE_CLASS_TYPE_P (argtypes[i]))
    3528              :         {
    3529     15276769 :           tree convs;
    3530              : 
    3531     15276769 :           if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
    3532              :             return;
    3533              : 
    3534     11673442 :           convs = lookup_conversions (argtypes[i]);
    3535              : 
    3536     11673442 :           if (code == COND_EXPR)
    3537              :             {
    3538         1295 :               if (lvalue_p (args[i]))
    3539          940 :                 vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3540              : 
    3541         1295 :               vec_safe_push (types[i], TYPE_MAIN_VARIANT (argtypes[i]));
    3542              :             }
    3543              : 
    3544     11672147 :           else if (! convs)
    3545              :             return;
    3546              : 
    3547     11357576 :           for (; convs; convs = TREE_CHAIN (convs))
    3548              :             {
    3549      6749137 :               type = TREE_TYPE (convs);
    3550              : 
    3551      8352701 :               if (i == 0 && ref1
    3552      6749137 :                   && (!TYPE_REF_P (type)
    3553         2599 :                       || CP_TYPE_CONST_P (TREE_TYPE (type))))
    3554      1603564 :                 continue;
    3555              : 
    3556      5145573 :               if (code == COND_EXPR && TYPE_REF_P (type))
    3557           24 :                 vec_safe_push (types[i], type);
    3558              : 
    3559      5145573 :               type = non_reference (type);
    3560      5145573 :               if (i != 0 || ! ref1)
    3561              :                 {
    3562      5145534 :                   type = cv_unqualified (type_decays_to (type));
    3563      5145534 :                   if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
    3564          656 :                     vec_safe_push (types[i], type);
    3565      5145534 :                   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3566      2901789 :                     type = type_promotes_to (type);
    3567              :                 }
    3568              : 
    3569      5145573 :               if (! vec_member (type, types[i]))
    3570      5137298 :                 vec_safe_push (types[i], type);
    3571              :             }
    3572              :         }
    3573              :       else
    3574              :         {
    3575     18572454 :           if (code == COND_EXPR && lvalue_p (args[i]))
    3576           95 :             vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3577     18572454 :           type = non_reference (argtypes[i]);
    3578     18572454 :           if (i != 0 || ! ref1)
    3579              :             {
    3580     16766792 :               type = cv_unqualified (type_decays_to (type));
    3581     16766792 :               if (enum_p && UNSCOPED_ENUM_P (type))
    3582      1958191 :                 vec_safe_push (types[i], type);
    3583     16766792 :               if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3584      9282005 :                 type = type_promotes_to (type);
    3585              :             }
    3586     18572454 :           vec_safe_push (types[i], type);
    3587              :         }
    3588              :     }
    3589              : 
    3590              :   /* Run through the possible parameter types of both arguments,
    3591              :      creating candidates with those parameter types.  */
    3592     23400832 :   FOR_EACH_VEC_ELT_REVERSE (*(types[0]), ix, t)
    3593              :     {
    3594     11981770 :       unsigned jx;
    3595     11981770 :       tree u;
    3596              : 
    3597     11981770 :       if (!types[1]->is_empty ())
    3598     25805963 :         FOR_EACH_VEC_ELT_REVERSE (*(types[1]), jx, u)
    3599     13824193 :           add_builtin_candidate
    3600     13824193 :             (candidates, code, code2, fnname, t,
    3601              :              u, args, argtypes, flags, complain);
    3602              :       else
    3603       486515 :         add_builtin_candidate
    3604       486515 :           (candidates, code, code2, fnname, t,
    3605              :            NULL_TREE, args, argtypes, flags, complain);
    3606              :     }
    3607              : 
    3608     11419062 :   release_tree_vector (types[0]);
    3609     11419062 :   release_tree_vector (types[1]);
    3610              : }
    3611              : 
    3612              : 
    3613              : /* If TMPL can be successfully instantiated as indicated by
    3614              :    EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
    3615              : 
    3616              :    TMPL is the template.  EXPLICIT_TARGS are any explicit template
    3617              :    arguments.  ARGLIST is the arguments provided at the call-site.
    3618              :    This does not change ARGLIST.  The RETURN_TYPE is the desired type
    3619              :    for conversion operators.  If OBJ is NULL_TREE, FLAGS and CTYPE are
    3620              :    as for add_function_candidate.  If an OBJ is supplied, FLAGS and
    3621              :    CTYPE are ignored, and OBJ is as for add_conv_candidate.
    3622              : 
    3623              :    SHORTCUT_BAD_CONVS is as in add_function_candidate.  */
    3624              : 
    3625              : static struct z_candidate*
    3626    529898697 : add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
    3627              :                              tree ctype, tree explicit_targs, tree first_arg,
    3628              :                              const vec<tree, va_gc> *arglist, tree return_type,
    3629              :                              tree access_path, tree conversion_path,
    3630              :                              int flags, tree obj, unification_kind_t strict,
    3631              :                              bool shortcut_bad_convs, tsubst_flags_t complain)
    3632              : {
    3633    529898697 :   int ntparms = DECL_NTPARMS (tmpl);
    3634    529898697 :   tree targs = make_tree_vec (ntparms);
    3635    529898697 :   unsigned int len = vec_safe_length (arglist);
    3636    529898697 :   unsigned int nargs = (first_arg == NULL_TREE ? 0 : 1) + len;
    3637    529898697 :   unsigned int skip_without_in_chrg = 0;
    3638    529898697 :   tree first_arg_without_in_chrg = first_arg;
    3639    529898697 :   tree *args_without_in_chrg;
    3640    529898697 :   unsigned int nargs_without_in_chrg;
    3641    529898697 :   unsigned int ia, ix;
    3642    529898697 :   tree arg;
    3643    529898697 :   struct z_candidate *cand;
    3644    529898697 :   tree fn;
    3645    529898697 :   struct rejection_reason *reason = NULL;
    3646    529898697 :   int errs;
    3647    529898697 :   conversion **convs = NULL;
    3648              : 
    3649              :   /* We don't do deduction on the in-charge parameter, the VTT
    3650              :      parameter or 'this'.  */
    3651    529898697 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (tmpl))
    3652              :     {
    3653     53933295 :       if (first_arg_without_in_chrg != NULL_TREE)
    3654              :         first_arg_without_in_chrg = NULL_TREE;
    3655           12 :       else if (return_type && strict == DEDUCE_CALL)
    3656              :         /* We're deducing for a call to the result of a template conversion
    3657              :            function, so the args don't contain 'this'; leave them alone.  */;
    3658              :       else
    3659    529898697 :         ++skip_without_in_chrg;
    3660              :     }
    3661              : 
    3662    529898697 :   if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
    3663    529898697 :        || DECL_BASE_CONSTRUCTOR_P (tmpl))
    3664    530902780 :       && CLASSTYPE_VBASECLASSES (DECL_CONTEXT (tmpl)))
    3665              :     {
    3666          261 :       if (first_arg_without_in_chrg != NULL_TREE)
    3667              :         first_arg_without_in_chrg = NULL_TREE;
    3668              :       else
    3669          261 :         ++skip_without_in_chrg;
    3670              :     }
    3671              : 
    3672    529898697 :   if (len < skip_without_in_chrg)
    3673            0 :     return add_ignored_candidate (candidates, tmpl);
    3674              : 
    3675    579123963 :   if (DECL_CONSTRUCTOR_P (tmpl) && nargs == 2
    3676    573752509 :       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (first_arg),
    3677     43853812 :                                                     TREE_TYPE ((*arglist)[0])))
    3678              :     {
    3679              :       /* 12.8/6 says, "A declaration of a constructor for a class X is
    3680              :          ill-formed if its first parameter is of type (optionally cv-qualified)
    3681              :          X and either there are no other parameters or else all other
    3682              :          parameters have default arguments. A member function template is never
    3683              :          instantiated to produce such a constructor signature."
    3684              : 
    3685              :          So if we're trying to copy an object of the containing class, don't
    3686              :          consider a template constructor that has a first parameter type that
    3687              :          is just a template parameter, as we would deduce a signature that we
    3688              :          would then reject in the code below.  */
    3689      2370010 :       if (tree firstparm = FUNCTION_FIRST_USER_PARMTYPE (tmpl))
    3690              :         {
    3691      2370010 :           firstparm = TREE_VALUE (firstparm);
    3692      2370010 :           if (PACK_EXPANSION_P (firstparm))
    3693         2122 :             firstparm = PACK_EXPANSION_PATTERN (firstparm);
    3694      2370010 :           if (TREE_CODE (firstparm) == TEMPLATE_TYPE_PARM)
    3695              :             {
    3696       759651 :               gcc_assert (!explicit_targs);
    3697       759651 :               reason = invalid_copy_with_fn_template_rejection ();
    3698       759651 :               goto fail;
    3699              :             }
    3700              :         }
    3701              :     }
    3702              : 
    3703    529139046 :   nargs_without_in_chrg = ((first_arg_without_in_chrg != NULL_TREE ? 1 : 0)
    3704    529139046 :                            + (len - skip_without_in_chrg));
    3705    529139046 :   args_without_in_chrg = XALLOCAVEC (tree, nargs_without_in_chrg);
    3706    529139046 :   ia = 0;
    3707    529139046 :   if (first_arg_without_in_chrg != NULL_TREE)
    3708              :     {
    3709        10152 :       args_without_in_chrg[ia] = first_arg_without_in_chrg;
    3710        10152 :       ++ia;
    3711              :     }
    3712    529139046 :   for (ix = skip_without_in_chrg;
    3713   1416495417 :        vec_safe_iterate (arglist, ix, &arg);
    3714              :        ++ix)
    3715              :     {
    3716    887356371 :       args_without_in_chrg[ia] = arg;
    3717    887356371 :       ++ia;
    3718              :     }
    3719    529139046 :   gcc_assert (ia == nargs_without_in_chrg);
    3720              : 
    3721    529139046 :   if (!obj)
    3722              :     {
    3723              :       /* Check that there's no obvious arity mismatch before proceeding with
    3724              :          deduction.  This avoids substituting explicit template arguments
    3725              :          into the template or e.g. derived-to-base parm/arg unification
    3726              :          (which could result in an error outside the immediate context) when
    3727              :          the resulting candidate would be unviable anyway.  */
    3728    529139034 :       int min_arity = 0, max_arity = 0;
    3729    529139034 :       tree parms = TYPE_ARG_TYPES (TREE_TYPE (tmpl));
    3730    529139034 :       parms = skip_artificial_parms_for (tmpl, parms);
    3731   1987633815 :       for (; parms != void_list_node; parms = TREE_CHAIN (parms))
    3732              :         {
    3733   1864908238 :           if (!parms || PACK_EXPANSION_P (TREE_VALUE (parms)))
    3734              :             {
    3735              :               max_arity = -1;
    3736              :               break;
    3737              :             }
    3738    929355747 :           if (TREE_PURPOSE (parms))
    3739              :             /* A parameter with a default argument.  */
    3740     10336507 :             ++max_arity;
    3741              :           else
    3742    919019240 :             ++min_arity, ++max_arity;
    3743              :         }
    3744    529139034 :       if (ia < (unsigned)min_arity)
    3745              :         {
    3746              :           /* Too few arguments.  */
    3747     35005181 :           reason = arity_rejection (NULL_TREE, min_arity, ia,
    3748              :                                     /*least_p=*/(max_arity == -1));
    3749     35005181 :           goto fail;
    3750              :         }
    3751    494133853 :       else if (max_arity != -1 && ia > (unsigned)max_arity)
    3752              :         {
    3753              :           /* Too many arguments.  */
    3754      5183113 :           reason = arity_rejection (NULL_TREE, max_arity, ia);
    3755      5183113 :           goto fail;
    3756              :         }
    3757              : 
    3758    488950740 :       convs = alloc_conversions (nargs);
    3759              : 
    3760    488950740 :       if (shortcut_bad_convs
    3761    488941280 :           && DECL_IOBJ_MEMBER_FUNCTION_P (tmpl)
    3762    564498810 :           && !DECL_CONSTRUCTOR_P (tmpl))
    3763              :         {
    3764              :           /* Check the 'this' conversion before proceeding with deduction.
    3765              :              This is effectively an extension of the DR 1391 resolution
    3766              :              that we perform in check_non_deducible_conversions, though it's
    3767              :              convenient to do this extra check here instead of there.  */
    3768      4134970 :           tree parmtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (tmpl)));
    3769      4134970 :           tree argtype = lvalue_type (first_arg);
    3770      4134970 :           tree arg = first_arg;
    3771      4134970 :           conversion *t = build_this_conversion (tmpl, ctype,
    3772              :                                                  parmtype, argtype, arg,
    3773              :                                                  flags, complain);
    3774      4134970 :           convs[0] = t;
    3775      4134970 :           if (t->bad_p)
    3776              :             {
    3777        39699 :               reason = bad_arg_conversion_rejection (first_arg, 0,
    3778              :                                                      arg, parmtype,
    3779        39699 :                                                      EXPR_LOCATION (arg));
    3780        39699 :               goto fail;
    3781              :             }
    3782              :         }
    3783              :     }
    3784              : 
    3785    488911053 :   errs = errorcount+sorrycount;
    3786    977808555 :   fn = fn_type_unification (tmpl, explicit_targs, targs,
    3787              :                             args_without_in_chrg,
    3788              :                             nargs_without_in_chrg,
    3789              :                             return_type, strict, flags, convs,
    3790    488911053 :                             false, complain & tf_decltype);
    3791              : 
    3792    488897502 :   if (fn == error_mark_node)
    3793              :     {
    3794              :       /* Don't repeat unification later if it already resulted in errors.  */
    3795    398333494 :       if (errorcount+sorrycount == errs)
    3796    398333378 :         reason = template_unification_rejection (tmpl, explicit_targs,
    3797              :                                                  targs, args_without_in_chrg,
    3798              :                                                  nargs_without_in_chrg,
    3799              :                                                  return_type, strict, flags);
    3800              :       else
    3801          116 :         reason = template_unification_error_rejection ();
    3802    398333494 :       goto fail;
    3803              :     }
    3804              : 
    3805              :   /* Now the explicit specifier might have been deduced; check if this
    3806              :      declaration is explicit.  If it is and we're ignoring non-converting
    3807              :      constructors, don't add this function to the set of candidates.  */
    3808     90564008 :   if (((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    3809              :        == LOOKUP_ONLYCONVERTING)
    3810     90564008 :       && DECL_NONCONVERTING_P (fn))
    3811         5457 :     return add_ignored_candidate (candidates, fn);
    3812              : 
    3813    181117102 :   if (DECL_CONSTRUCTOR_P (fn) && nargs == 2)
    3814              :     {
    3815      4848091 :       tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3816      9696155 :       if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
    3817              :                                     ctype))
    3818              :         {
    3819              :           /* We're trying to produce a constructor with a prohibited signature,
    3820              :              as discussed above; handle here any cases we didn't catch then,
    3821              :              such as X(X<T>).  */
    3822          844 :           reason = invalid_copy_with_fn_template_rejection ();
    3823          844 :           goto fail;
    3824              :         }
    3825              :     }
    3826              : 
    3827     90557707 :   if (obj != NULL_TREE)
    3828              :     /* Aha, this is a conversion function.  */
    3829            9 :     cand = add_conv_candidate (candidates, fn, obj, arglist,
    3830              :                                access_path, conversion_path, complain);
    3831              :   else
    3832     90557698 :     cand = add_function_candidate (candidates, fn, ctype,
    3833              :                                    first_arg, arglist, access_path,
    3834              :                                    conversion_path, flags, convs,
    3835              :                                    shortcut_bad_convs, complain);
    3836     90557707 :   if (DECL_TI_TEMPLATE (fn) != tmpl)
    3837              :     /* This situation can occur if a member template of a template
    3838              :        class is specialized.  Then, instantiate_template might return
    3839              :        an instantiation of the specialization, in which case the
    3840              :        DECL_TI_TEMPLATE field will point at the original
    3841              :        specialization.  For example:
    3842              : 
    3843              :          template <class T> struct S { template <class U> void f(U);
    3844              :                                        template <> void f(int) {}; };
    3845              :          S<double> sd;
    3846              :          sd.f(3);
    3847              : 
    3848              :        Here, TMPL will be template <class U> S<double>::f(U).
    3849              :        And, instantiate template will give us the specialization
    3850              :        template <> S<double>::f(int).  But, the DECL_TI_TEMPLATE field
    3851              :        for this will point at template <class T> template <> S<T>::f(int),
    3852              :        so that we can find the definition.  For the purposes of
    3853              :        overload resolution, however, we want the original TMPL.  */
    3854      5580322 :     cand->template_decl = build_template_info (tmpl, targs);
    3855              :   else
    3856     84977385 :     cand->template_decl = DECL_TEMPLATE_INFO (fn);
    3857     90557707 :   cand->explicit_targs = explicit_targs;
    3858              : 
    3859     90557707 :   return cand;
    3860    439321982 :  fail:
    3861    439321982 :   int viable = (reason->code == rr_bad_arg_conversion ? -1 : 0);
    3862    439321982 :   return add_candidate (candidates, tmpl, first_arg, arglist, nargs, convs,
    3863    439321982 :                         access_path, conversion_path, viable, reason, flags);
    3864              : }
    3865              : 
    3866              : 
    3867              : static struct z_candidate *
    3868    529898685 : add_template_candidate (struct z_candidate **candidates, tree tmpl, tree ctype,
    3869              :                         tree explicit_targs, tree first_arg,
    3870              :                         const vec<tree, va_gc> *arglist, tree return_type,
    3871              :                         tree access_path, tree conversion_path, int flags,
    3872              :                         unification_kind_t strict, bool shortcut_bad_convs,
    3873              :                         tsubst_flags_t complain)
    3874              : {
    3875    529898685 :   return
    3876            0 :     add_template_candidate_real (candidates, tmpl, ctype,
    3877              :                                  explicit_targs, first_arg, arglist,
    3878              :                                  return_type, access_path, conversion_path,
    3879              :                                  flags, NULL_TREE, strict, shortcut_bad_convs,
    3880            0 :                                  complain);
    3881              : }
    3882              : 
    3883              : /* Create an overload candidate for the conversion function template TMPL,
    3884              :    returning RETURN_TYPE, which will be invoked for expression OBJ to produce a
    3885              :    pointer-to-function which will in turn be called with the argument list
    3886              :    ARGLIST, and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    3887              :    passed on to implicit_conversion.  */
    3888              : 
    3889              : static struct z_candidate *
    3890           12 : add_template_conv_candidate (struct z_candidate **candidates, tree tmpl,
    3891              :                              tree obj,
    3892              :                              const vec<tree, va_gc> *arglist,
    3893              :                              tree return_type, tree access_path,
    3894              :                              tree conversion_path, tsubst_flags_t complain)
    3895              : {
    3896           12 :   return
    3897           12 :     add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE,
    3898              :                                  NULL_TREE, arglist, return_type, access_path,
    3899              :                                  conversion_path, 0, obj, DEDUCE_CALL,
    3900           12 :                                  /*shortcut_bad_convs=*/false, complain);
    3901              : }
    3902              : 
    3903              : /* The CANDS are the set of candidates that were considered for
    3904              :    overload resolution.  Sort CANDS so that the strictly viable
    3905              :    candidates appear first, followed by non-strictly viable candidates,
    3906              :    followed by non-viable candidates.  Returns the first candidate
    3907              :    in this sorted list.  If any of the candidates were viable, set
    3908              :    *ANY_VIABLE_P to true.  STRICT_P is true if a candidate should be
    3909              :    considered viable only if it is strictly viable when setting
    3910              :    *ANY_VIABLE_P.  */
    3911              : 
    3912              : static struct z_candidate*
    3913    330605717 : splice_viable (struct z_candidate *cands,
    3914              :                bool strict_p,
    3915              :                bool *any_viable_p)
    3916              : {
    3917    330605717 :   z_candidate *strictly_viable = nullptr;
    3918    330605717 :   z_candidate **strictly_viable_tail = &strictly_viable;
    3919              : 
    3920    330605717 :   z_candidate *non_strictly_viable = nullptr;
    3921    330605717 :   z_candidate **non_strictly_viable_tail = &non_strictly_viable;
    3922              : 
    3923    330605717 :   z_candidate *non_viable = nullptr;
    3924    330605717 :   z_candidate **non_viable_tail = &non_viable;
    3925              : 
    3926    330605717 :   z_candidate *non_viable_ignored = nullptr;
    3927    330605717 :   z_candidate **non_viable_ignored_tail = &non_viable_ignored;
    3928              : 
    3929              :   /* Be strict inside templates, since build_over_call won't actually
    3930              :      do the conversions to get pedwarns.  */
    3931    330605717 :   if (processing_template_decl)
    3932     58497266 :     strict_p = true;
    3933              : 
    3934   1259265283 :   for (z_candidate *cand = cands; cand; cand = cand->next)
    3935              :     {
    3936    928659566 :       if (!strict_p
    3937    324346311 :           && (cand->viable == 1 || TREE_CODE (cand->fn) == TEMPLATE_DECL))
    3938              :         /* Be strict in the presence of a viable candidate.  Also if
    3939              :            there are template candidates, so that we get deduction errors
    3940              :            for them instead of silently preferring a bad conversion.  */
    3941    828889503 :         strict_p = true;
    3942              : 
    3943              :       /* Move this candidate to the appropriate list according to
    3944              :          its viability.  */
    3945    928659566 :       auto& tail = (cand->viable == 1 ? strictly_viable_tail
    3946              :                     : cand->viable == -1 ? non_strictly_viable_tail
    3947   1481511250 :                     : ignored_candidate_p (cand) ? non_viable_ignored_tail
    3948   1539059804 :                     : non_viable_tail);
    3949    928659566 :       *tail = cand;
    3950    928659566 :       tail = &cand->next;
    3951              :     }
    3952              : 
    3953    661211434 :   *any_viable_p = (strictly_viable != nullptr
    3954    330605717 :                    || (!strict_p && non_strictly_viable != nullptr));
    3955              : 
    3956              :   /* Combine the lists.  */
    3957    330605717 :   *non_viable_ignored_tail = nullptr;
    3958    330605717 :   *non_viable_tail = non_viable_ignored;
    3959    330605717 :   *non_strictly_viable_tail = non_viable;
    3960    330605717 :   *strictly_viable_tail = non_strictly_viable;
    3961              : 
    3962    330605717 :   return strictly_viable;
    3963              : }
    3964              : 
    3965              : static bool
    3966    316725210 : any_strictly_viable (struct z_candidate *cands)
    3967              : {
    3968    433206243 :   for (; cands; cands = cands->next)
    3969    125662377 :     if (cands->viable == 1)
    3970              :       return true;
    3971              :   return false;
    3972              : }
    3973              : 
    3974              : /* OBJ is being used in an expression like "OBJ.f (...)".  In other
    3975              :    words, it is about to become the "this" pointer for a member
    3976              :    function call.  Take the address of the object.  */
    3977              : 
    3978              : static tree
    3979     69009159 : build_this (tree obj)
    3980              : {
    3981              :   /* In a template, we are only concerned about the type of the
    3982              :      expression, so we can take a shortcut.  */
    3983     69009159 :   if (processing_template_decl)
    3984        76851 :     return build_address (obj);
    3985              : 
    3986     68932308 :   return cp_build_addr_expr (obj, tf_warning_or_error);
    3987              : }
    3988              : 
    3989              : /* Returns true iff functions are equivalent. Equivalent functions are
    3990              :    not '==' only if one is a function-local extern function or if
    3991              :    both are extern "C".  */
    3992              : 
    3993              : static inline int
    3994      4903929 : equal_functions (tree fn1, tree fn2)
    3995              : {
    3996      4903929 :   if (TREE_CODE (fn1) != TREE_CODE (fn2))
    3997              :     return 0;
    3998      4888568 :   if (TREE_CODE (fn1) == TEMPLATE_DECL)
    3999        36051 :     return fn1 == fn2;
    4000      9705016 :   if (DECL_LOCAL_DECL_P (fn1) || DECL_LOCAL_DECL_P (fn2)
    4001      9705013 :       || DECL_EXTERN_C_FUNCTION_P (fn1))
    4002      3026613 :     return decls_match (fn1, fn2);
    4003      1825904 :   return fn1 == fn2;
    4004              : }
    4005              : 
    4006              : /* Print information about a candidate FN being rejected due to INFO.  */
    4007              : 
    4008              : static void
    4009         5325 : print_conversion_rejection (location_t loc, struct conversion_info *info,
    4010              :                             tree fn)
    4011              : {
    4012         5325 :   tree from = info->from;
    4013         5325 :   if (!TYPE_P (from))
    4014         4385 :     from = lvalue_type (from);
    4015         5325 :   if (info->n_arg == -1)
    4016              :     {
    4017              :       /* Conversion of implicit `this' argument failed.  */
    4018           32 :       if (!TYPE_P (info->from))
    4019              :         /* A bad conversion for 'this' must be discarding cv-quals.  */
    4020           32 :         inform (loc, "passing %qT as %<this%> "
    4021              :                 "argument discards qualifiers",
    4022              :                 from);
    4023              :       else
    4024            0 :         inform (loc, "no known conversion for implicit "
    4025              :                 "%<this%> parameter from %qH to %qI",
    4026              :                 from, info->to_type);
    4027              :     }
    4028         5293 :   else if (!TYPE_P (info->from))
    4029              :     {
    4030         4353 :       if (info->n_arg >= 0)
    4031         4353 :         inform (loc, "conversion of argument %d would be ill-formed:",
    4032              :                 info->n_arg + 1);
    4033         4353 :       iloc_sentinel ils = loc;
    4034         4353 :       perform_implicit_conversion (info->to_type, info->from,
    4035              :                                    tf_warning_or_error);
    4036         4353 :     }
    4037          940 :   else if (info->n_arg == -2)
    4038              :     /* Conversion of conversion function return value failed.  */
    4039           33 :     inform (loc, "no known conversion from %qH to %qI",
    4040              :             from, info->to_type);
    4041              :   else
    4042              :     {
    4043          907 :       if (TREE_CODE (fn) == FUNCTION_DECL)
    4044          751 :         loc = get_fndecl_argument_location (fn, info->n_arg);
    4045          907 :       inform (loc, "no known conversion for argument %d from %qH to %qI",
    4046          907 :               info->n_arg + 1, from, info->to_type);
    4047              :     }
    4048         5325 : }
    4049              : 
    4050              : /* Print information about a candidate with WANT parameters and we found
    4051              :    HAVE.  */
    4052              : 
    4053              : static void
    4054         1469 : print_arity_information (location_t loc, unsigned int have, unsigned int want,
    4055              :                          bool least_p)
    4056              : {
    4057         1469 :   if (least_p)
    4058           41 :     inform_n (loc, want,
    4059              :               "candidate expects at least %d argument, %d provided",
    4060              :               "candidate expects at least %d arguments, %d provided",
    4061              :               want, have);
    4062              :   else
    4063         1428 :     inform_n (loc, want,
    4064              :               "candidate expects %d argument, %d provided",
    4065              :               "candidate expects %d arguments, %d provided",
    4066              :               want, have);
    4067         1469 : }
    4068              : 
    4069              : /* Print information about one overload candidate CANDIDATE.  MSGSTR
    4070              :    is the text to print before the candidate itself.
    4071              : 
    4072              :    NOTE: Unlike most diagnostic functions in GCC, MSGSTR is expected
    4073              :    to have been run through gettext by the caller.  This wart makes
    4074              :    life simpler in print_z_candidates and for the translators.  */
    4075              : 
    4076              : static void
    4077        13335 : print_z_candidate (location_t loc, const char *msgstr,
    4078              :                    struct z_candidate *candidate)
    4079              : {
    4080        13335 :   const char *msg = (msgstr == NULL
    4081        13335 :                      ? ""
    4082        13335 :                      : ACONCAT ((_(msgstr), " ", NULL)));
    4083        13335 :   tree fn = candidate->fn;
    4084        13335 :   if (flag_new_inheriting_ctors)
    4085        13308 :     fn = strip_inheriting_ctors (fn);
    4086        13335 :   location_t cloc = location_of (fn);
    4087              : 
    4088        13335 :   if (identifier_p (fn))
    4089              :     {
    4090          214 :       cloc = loc;
    4091          214 :       if (candidate->num_convs == 3)
    4092            0 :         inform (cloc, "%s%<%D(%T, %T, %T)%> (built-in)", msg, fn,
    4093            0 :                 candidate->convs[0]->type,
    4094            0 :                 candidate->convs[1]->type,
    4095            0 :                 candidate->convs[2]->type);
    4096          214 :       else if (candidate->num_convs == 2)
    4097          190 :         inform (cloc, "%s%<%D(%T, %T)%> (built-in)", msg, fn,
    4098          190 :                 candidate->convs[0]->type,
    4099          190 :                 candidate->convs[1]->type);
    4100              :       else
    4101           24 :         inform (cloc, "%s%<%D(%T)%> (built-in)", msg, fn,
    4102           24 :                 candidate->convs[0]->type);
    4103              :     }
    4104        13121 :   else if (TYPE_P (fn))
    4105           15 :     inform (cloc, "%s%qT (conversion)", msg, fn);
    4106        13106 :   else if (candidate->viable == -1)
    4107         4392 :     inform (cloc, "%s%#qD (near match)", msg, fn);
    4108         8714 :   else if (ignored_candidate_p (candidate))
    4109            6 :     inform (cloc, "%s%#qD (ignored)", msg, fn);
    4110         8708 :   else if (DECL_DELETED_FN (fn))
    4111           60 :     inform (cloc, "%s%#qD (deleted)", msg, fn);
    4112         8648 :   else if (candidate->reversed ())
    4113          300 :     inform (cloc, "%s%#qD (reversed)", msg, fn);
    4114         8348 :   else if (candidate->rewritten ())
    4115          150 :     inform (cloc, "%s%#qD (rewritten)", msg, fn);
    4116              :   else
    4117         8198 :     inform (cloc, "%s%#qD", msg, fn);
    4118              : 
    4119        13335 :   auto_diagnostic_nesting_level sentinel;
    4120              : 
    4121        13335 :   if (fn != candidate->fn)
    4122              :     {
    4123           57 :       cloc = location_of (candidate->fn);
    4124           57 :       inform (cloc, "inherited here");
    4125              :     }
    4126              : 
    4127              :   /* Give the user some information about why this candidate failed.  */
    4128        13335 :   if (candidate->reason != NULL)
    4129              :     {
    4130        10220 :       struct rejection_reason *r = candidate->reason;
    4131              : 
    4132        10220 :       switch (r->code)
    4133              :         {
    4134         1469 :         case rr_arity:
    4135         1469 :           print_arity_information (cloc, r->u.arity.actual,
    4136         1469 :                                    r->u.arity.expected,
    4137              :                                    r->u.arity.least_p);
    4138         1469 :           break;
    4139          913 :         case rr_arg_conversion:
    4140          913 :           print_conversion_rejection (cloc, &r->u.conversion, fn);
    4141          913 :           break;
    4142         4412 :         case rr_bad_arg_conversion:
    4143         4412 :           print_conversion_rejection (cloc, &r->u.bad_conversion, fn);
    4144         4412 :           break;
    4145           11 :         case rr_explicit_conversion:
    4146           11 :           inform (cloc, "return type %qT of explicit conversion function "
    4147              :                   "cannot be converted to %qT with a qualification "
    4148              :                   "conversion", r->u.conversion.from,
    4149              :                   r->u.conversion.to_type);
    4150           11 :           break;
    4151            6 :         case rr_template_conversion:
    4152            6 :           inform (cloc, "conversion from return type %qT of template "
    4153              :                   "conversion function specialization to %qT is not an "
    4154              :                   "exact match", r->u.conversion.from,
    4155              :                   r->u.conversion.to_type);
    4156            6 :           break;
    4157         3276 :         case rr_template_unification:
    4158              :           /* We use template_unification_error_rejection if unification caused
    4159              :              actual non-SFINAE errors, in which case we don't need to repeat
    4160              :              them here.  */
    4161         3276 :           if (r->u.template_unification.tmpl == NULL_TREE)
    4162              :             {
    4163           45 :               inform (cloc, "substitution of deduced template arguments "
    4164              :                       "resulted in errors seen above");
    4165           45 :               break;
    4166              :             }
    4167              :           /* Re-run template unification with diagnostics.  */
    4168         3231 :           inform (cloc, "template argument deduction/substitution failed:");
    4169         3231 :           {
    4170         3231 :             auto_diagnostic_nesting_level sentinel;
    4171         3231 :             fn_type_unification (r->u.template_unification.tmpl,
    4172              :                                  r->u.template_unification.explicit_targs,
    4173              :                                  (make_tree_vec
    4174              :                                   (r->u.template_unification.num_targs)),
    4175              :                                  r->u.template_unification.args,
    4176              :                                  r->u.template_unification.nargs,
    4177              :                                  r->u.template_unification.return_type,
    4178              :                                  r->u.template_unification.strict,
    4179              :                                  r->u.template_unification.flags,
    4180              :                                  NULL, true, false);
    4181         3231 :           }
    4182         3231 :           break;
    4183            2 :         case rr_invalid_copy:
    4184            2 :           inform (cloc,
    4185              :                   "a constructor taking a single argument of its own "
    4186              :                   "class type is invalid");
    4187            2 :           break;
    4188           93 :         case rr_constraint_failure:
    4189           93 :           diagnose_constraints (cloc, fn, NULL_TREE);
    4190           93 :           break;
    4191           32 :         case rr_inherited_ctor:
    4192           32 :           inform (cloc, "an inherited constructor is not a candidate for "
    4193              :                   "initialization from an expression of the same or derived "
    4194              :                   "type");
    4195           32 :           break;
    4196              :         case rr_ignored:
    4197              :           break;
    4198            0 :         case rr_none:
    4199            0 :         default:
    4200              :           /* This candidate didn't have any issues or we failed to
    4201              :              handle a particular code.  Either way...  */
    4202            0 :           gcc_unreachable ();
    4203              :         }
    4204              :     }
    4205        13335 : }
    4206              : 
    4207              : /* Print information about each overload candidate in CANDIDATES,
    4208              :    which is assumed to have gone through splice_viable and tourney
    4209              :    (if splice_viable succeeded).  */
    4210              : 
    4211              : static void
    4212         5576 : print_z_candidates (location_t loc, struct z_candidate *candidates,
    4213              :                     tristate only_viable_p /* = tristate::unknown () */)
    4214              : {
    4215         5576 :   struct z_candidate *cand1;
    4216         5576 :   struct z_candidate **cand2;
    4217              : 
    4218         5576 :   if (!candidates)
    4219         1011 :     return;
    4220              : 
    4221              :   /* Remove non-viable deleted candidates.  */
    4222         4565 :   cand1 = candidates;
    4223        20477 :   for (cand2 = &cand1; *cand2; )
    4224              :     {
    4225        15912 :       if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
    4226        11447 :           && !(*cand2)->viable
    4227        19673 :           && DECL_DELETED_FN ((*cand2)->fn))
    4228          102 :         *cand2 = (*cand2)->next;
    4229              :       else
    4230        15810 :         cand2 = &(*cand2)->next;
    4231              :     }
    4232              :   /* ...if there are any non-deleted ones.  */
    4233         4565 :   if (cand1)
    4234         4559 :     candidates = cand1;
    4235              : 
    4236              :   /* There may be duplicates in the set of candidates.  We put off
    4237              :      checking this condition as long as possible, since we have no way
    4238              :      to eliminate duplicates from a set of functions in less than n^2
    4239              :      time.  Now we are about to emit an error message, so it is more
    4240              :      permissible to go slowly.  */
    4241        20075 :   for (cand1 = candidates; cand1; cand1 = cand1->next)
    4242              :     {
    4243        15510 :       tree fn = cand1->fn;
    4244              :       /* Skip builtin candidates and conversion functions.  */
    4245        15510 :       if (!DECL_P (fn))
    4246          289 :         continue;
    4247        15221 :       cand2 = &cand1->next;
    4248       143379 :       while (*cand2)
    4249              :         {
    4250       128158 :           if (DECL_P ((*cand2)->fn)
    4251       128158 :               && equal_functions (fn, (*cand2)->fn))
    4252          306 :             *cand2 = (*cand2)->next;
    4253              :           else
    4254       127852 :             cand2 = &(*cand2)->next;
    4255              :         }
    4256              :     }
    4257              : 
    4258              :   /* Unless otherwise specified, if there's a (strictly) viable candidate
    4259              :      then we assume we're being called as part of diagnosing ambiguity, in
    4260              :      which case we want to print only viable candidates since non-viable
    4261              :      candidates couldn't have contributed to the ambiguity.  */
    4262         4565 :   if (only_viable_p.is_unknown ())
    4263         4556 :     only_viable_p = candidates->viable == 1;
    4264              : 
    4265         4565 :   auto_diagnostic_nesting_level sentinel;
    4266              : 
    4267         4565 :   int num_candidates = 0;
    4268        22355 :   for (auto iter = candidates; iter; iter = iter->next)
    4269              :     {
    4270        13566 :       if (only_viable_p.is_true () && iter->viable != 1)
    4271              :         break;
    4272        13225 :       ++num_candidates;
    4273              :     }
    4274              : 
    4275         4565 :   inform_num_candidates (loc, num_candidates);
    4276              : 
    4277         4565 :   auto_diagnostic_nesting_level sentinel2;
    4278              : 
    4279         4565 :   int candidate_idx = 0;
    4280        22320 :   for (; candidates; candidates = candidates->next)
    4281              :     {
    4282        13562 :       if (only_viable_p.is_true () && candidates->viable != 1)
    4283              :         break;
    4284        13258 :       if (ignored_candidate_p (candidates) && !flag_diagnostics_all_candidates)
    4285              :         {
    4286           31 :           inform (loc, "some candidates omitted; "
    4287              :                        "use %<-fdiagnostics-all-candidates%> to display them");
    4288           31 :           break;
    4289              :         }
    4290        13190 :       pretty_printer pp;
    4291        13190 :       pp_printf (&pp, N_("candidate %i:"), candidate_idx + 1);
    4292        13190 :       const char *const msgstr = pp_formatted_text (&pp);
    4293        13190 :       print_z_candidate (loc, msgstr, candidates);
    4294        13190 :       ++candidate_idx;
    4295        13190 :     }
    4296         4565 : }
    4297              : 
    4298              : /* USER_SEQ is a user-defined conversion sequence, beginning with a
    4299              :    USER_CONV.  STD_SEQ is the standard conversion sequence applied to
    4300              :    the result of the conversion function to convert it to the final
    4301              :    desired type.  Merge the two sequences into a single sequence,
    4302              :    and return the merged sequence.  */
    4303              : 
    4304              : static conversion *
    4305     15517733 : merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
    4306              : {
    4307     15517733 :   conversion **t;
    4308     15517733 :   bool bad = user_seq->bad_p;
    4309              : 
    4310     15517733 :   gcc_assert (user_seq->kind == ck_user);
    4311              : 
    4312              :   /* Find the end of the second conversion sequence.  */
    4313     16301297 :   for (t = &std_seq; (*t)->kind != ck_identity; t = &((*t)->u.next))
    4314              :     {
    4315              :       /* The entire sequence is a user-conversion sequence.  */
    4316       783564 :       (*t)->user_conv_p = true;
    4317       783564 :       if (bad)
    4318         3506 :         (*t)->bad_p = true;
    4319              :     }
    4320              : 
    4321     15517733 :   if ((*t)->rvaluedness_matches_p)
    4322              :     /* We're binding a reference directly to the result of the conversion.
    4323              :        build_user_type_conversion_1 stripped the REFERENCE_TYPE from the return
    4324              :        type, but we want it back.  */
    4325       467654 :     user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
    4326              : 
    4327              :   /* Replace the identity conversion with the user conversion
    4328              :      sequence.  */
    4329     15517733 :   *t = user_seq;
    4330              : 
    4331     15517733 :   return std_seq;
    4332              : }
    4333              : 
    4334              : /* Handle overload resolution for initializing an object of class type from
    4335              :    an initializer list.  First we look for a suitable constructor that
    4336              :    takes a std::initializer_list; if we don't find one, we then look for a
    4337              :    non-list constructor.
    4338              : 
    4339              :    Parameters are as for add_candidates, except that the arguments are in
    4340              :    the form of a CONSTRUCTOR (the initializer list) rather than a vector, and
    4341              :    the RETURN_TYPE parameter is replaced by TOTYPE, the desired type.  */
    4342              : 
    4343              : static void
    4344      2555987 : add_list_candidates (tree fns, tree first_arg,
    4345              :                      const vec<tree, va_gc> *args, tree totype,
    4346              :                      tree explicit_targs, bool template_only,
    4347              :                      tree conversion_path, tree access_path,
    4348              :                      int flags,
    4349              :                      struct z_candidate **candidates,
    4350              :                      tsubst_flags_t complain)
    4351              : {
    4352      2555987 :   gcc_assert (*candidates == NULL);
    4353              : 
    4354              :   /* We're looking for a ctor for list-initialization.  */
    4355      2555987 :   flags |= LOOKUP_LIST_INIT_CTOR;
    4356              :   /* And we don't allow narrowing conversions.  We also use this flag to
    4357              :      avoid the copy constructor call for copy-list-initialization.  */
    4358      2555987 :   flags |= LOOKUP_NO_NARROWING;
    4359              : 
    4360      5111974 :   unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1;
    4361      2555987 :   tree init_list = (*args)[nart];
    4362              : 
    4363              :   /* Always use the default constructor if the list is empty (DR 990).  */
    4364      2555987 :   if (CONSTRUCTOR_NELTS (init_list) == 0
    4365      2555987 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
    4366              :     ;
    4367      2311626 :   else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list)
    4368      2311626 :            && !CP_AGGREGATE_TYPE_P (totype))
    4369              :     {
    4370           53 :       if (complain & tf_error)
    4371           15 :         error ("designated initializers cannot be used with a "
    4372              :                "non-aggregate type %qT", totype);
    4373        10347 :       return;
    4374              :     }
    4375              :   /* If the class has a list ctor, try passing the list as a single
    4376              :      argument first, but only consider list ctors.  */
    4377      2311573 :   else if (TYPE_HAS_LIST_CTOR (totype))
    4378              :     {
    4379        87270 :       flags |= LOOKUP_LIST_ONLY;
    4380        87270 :       add_candidates (fns, first_arg, args, NULL_TREE,
    4381              :                       explicit_targs, template_only, conversion_path,
    4382              :                       access_path, flags, candidates, complain);
    4383       174540 :       if (any_strictly_viable (*candidates))
    4384              :         return;
    4385              :     }
    4386              : 
    4387              :   /* Expand the CONSTRUCTOR into a new argument vec.  */
    4388      2545640 :   vec<tree, va_gc> *new_args;
    4389      4846165 :   vec_alloc (new_args, nart + CONSTRUCTOR_NELTS (init_list));
    4390      5091283 :   for (unsigned i = 0; i < nart; ++i)
    4391            3 :     new_args->quick_push ((*args)[i]);
    4392      2545640 :   new_args = append_ctor_to_tree_vector (new_args, init_list);
    4393              : 
    4394              :   /* We aren't looking for list-ctors anymore.  */
    4395      2545640 :   flags &= ~LOOKUP_LIST_ONLY;
    4396              :   /* We allow more user-defined conversions within an init-list.  */
    4397      2545640 :   flags &= ~LOOKUP_NO_CONVERSION;
    4398              : 
    4399      2545640 :   add_candidates (fns, first_arg, new_args, NULL_TREE,
    4400              :                   explicit_targs, template_only, conversion_path,
    4401              :                   access_path, flags, candidates, complain);
    4402              : }
    4403              : 
    4404              : /* Given C(std::initializer_list<A>), return A.  */
    4405              : 
    4406              : static tree
    4407         1511 : list_ctor_element_type (tree fn)
    4408              : {
    4409         1511 :   gcc_checking_assert (is_list_ctor (fn));
    4410              : 
    4411         1511 :   tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    4412         1511 :   parm = non_reference (TREE_VALUE (parm));
    4413         1511 :   return TREE_VEC_ELT (CLASSTYPE_TI_ARGS (parm), 0);
    4414              : }
    4415              : 
    4416              : /* If EXPR is a braced-init-list where the elements all decay to the same type,
    4417              :    return that type.  */
    4418              : 
    4419              : static tree
    4420         1585 : braced_init_element_type (tree expr)
    4421              : {
    4422         1585 :   if (TREE_CODE (expr) == CONSTRUCTOR
    4423         1585 :       && TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE)
    4424            0 :     return TREE_TYPE (TREE_TYPE (expr));
    4425         1585 :   if (!BRACE_ENCLOSED_INITIALIZER_P (expr))
    4426              :     return NULL_TREE;
    4427              : 
    4428         1585 :   tree elttype = NULL_TREE;
    4429        15382 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (expr))
    4430              :     {
    4431        10829 :       tree type = TREE_TYPE (e.value);
    4432        10829 :       type = type_decays_to (type);
    4433        10829 :       if (!elttype)
    4434              :         elttype = type;
    4435         9272 :       else if (!same_type_p (type, elttype))
    4436              :         return NULL_TREE;
    4437              :     }
    4438              :   return elttype;
    4439              : }
    4440              : 
    4441              : /* True iff EXPR contains any temporaries with non-trivial destruction.
    4442              : 
    4443              :    ??? Also ignore classes with non-trivial but no-op destruction other than
    4444              :    std::allocator?  */
    4445              : 
    4446              : static bool
    4447          193 : has_non_trivial_temporaries (tree expr)
    4448              : {
    4449          193 :   auto_vec<tree*> temps;
    4450          193 :   cp_walk_tree_without_duplicates (&expr, find_temps_r, &temps);
    4451          388 :   for (tree *p : temps)
    4452              :     {
    4453           65 :       tree t = TREE_TYPE (*p);
    4454           65 :       if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (t)
    4455           65 :           && !is_std_allocator (t))
    4456              :         return true;
    4457              :     }
    4458              :   return false;
    4459          193 : }
    4460              : 
    4461              : /* Return number of initialized elements in CTOR.  */
    4462              : 
    4463              : unsigned HOST_WIDE_INT
    4464          263 : count_ctor_elements (tree ctor)
    4465              : {
    4466          263 :   unsigned HOST_WIDE_INT len = 0;
    4467         2194 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (ctor))
    4468         1405 :     if (TREE_CODE (e.value) == RAW_DATA_CST)
    4469            9 :       len += RAW_DATA_LENGTH (e.value);
    4470              :     else
    4471         1396 :       ++len;
    4472          263 :   return len;
    4473              : }
    4474              : 
    4475              : /* We're initializing an array of ELTTYPE from INIT.  If it seems useful,
    4476              :    return INIT as an array (of its own type) so the caller can initialize the
    4477              :    target array in a loop.  */
    4478              : 
    4479              : static tree
    4480        17704 : maybe_init_list_as_array (tree elttype, tree init)
    4481              : {
    4482              :   /* Only do this if the array can go in rodata but not once converted.  */
    4483        17704 :   if (!TYPE_NON_AGGREGATE_CLASS (elttype))
    4484              :     return NULL_TREE;
    4485         1585 :   tree init_elttype = braced_init_element_type (init);
    4486         1585 :   if (!init_elttype || !SCALAR_TYPE_P (init_elttype) || !TREE_CONSTANT (init))
    4487              :     return NULL_TREE;
    4488              : 
    4489              :   /* Check with a stub expression to weed out special cases, and check whether
    4490              :      we call the same function for direct-init as copy-list-init.  */
    4491          375 :   conversion_obstack_sentinel cos;
    4492          375 :   init_elttype = cp_build_qualified_type (init_elttype, TYPE_QUAL_CONST);
    4493          375 :   tree arg = build_stub_object (init_elttype);
    4494          375 :   conversion *c = implicit_conversion (elttype, init_elttype, arg, false,
    4495              :                                        LOOKUP_NORMAL, tf_none);
    4496          375 :   if (c && c->kind == ck_rvalue)
    4497            0 :     c = next_conversion (c);
    4498          369 :   if (!c || c->kind != ck_user)
    4499              :     return NULL_TREE;
    4500              :   /* Check that we actually can perform the conversion.  */
    4501          366 :   if (convert_like (c, arg, tf_none) == error_mark_node)
    4502              :     /* Let the normal code give the error.  */
    4503              :     return NULL_TREE;
    4504              : 
    4505              :   /* A glvalue initializer might be significant to a reference constructor
    4506              :      or conversion operator.  */
    4507          360 :   if (!DECL_CONSTRUCTOR_P (c->cand->fn)
    4508          360 :       || (TYPE_REF_P (TREE_VALUE
    4509              :                       (FUNCTION_FIRST_USER_PARMTYPE (c->cand->fn)))))
    4510          240 :     for (auto &ce : CONSTRUCTOR_ELTS (init))
    4511          108 :       if (non_mergeable_glvalue_p (ce.value))
    4512              :         return NULL_TREE;
    4513              : 
    4514          357 :   tree first = CONSTRUCTOR_ELT (init, 0)->value;
    4515          357 :   conversion *fc = implicit_conversion (elttype, init_elttype, first, false,
    4516              :                                         LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING,
    4517              :                                         tf_none);
    4518          357 :   if (fc && fc->kind == ck_rvalue)
    4519           48 :     fc = next_conversion (fc);
    4520          357 :   if (!fc || fc->kind != ck_user || fc->cand->fn != c->cand->fn)
    4521              :     return NULL_TREE;
    4522          315 :   first = convert_like (fc, first, tf_none);
    4523          315 :   if (first == error_mark_node)
    4524              :     /* Let the normal code give the error.  */
    4525              :     return NULL_TREE;
    4526              : 
    4527              :   /* Don't do this if the conversion would be constant.  */
    4528          312 :   first = maybe_constant_init (first);
    4529          312 :   if (TREE_CONSTANT (first))
    4530              :     return NULL_TREE;
    4531              : 
    4532              :   /* We can't do this if the conversion creates temporaries that need
    4533              :      to live until the whole array is initialized.  */
    4534          193 :   if (has_non_trivial_temporaries (first))
    4535              :     return NULL_TREE;
    4536              : 
    4537              :   /* We can't do this if copying from the initializer_list would be
    4538              :      ill-formed.  */
    4539          193 :   tree copy_argtypes = make_tree_vec (1);
    4540          193 :   TREE_VEC_ELT (copy_argtypes, 0)
    4541          193 :     = cp_build_qualified_type (elttype, TYPE_QUAL_CONST);
    4542          193 :   if (!is_xible (INIT_EXPR, elttype, copy_argtypes))
    4543              :     return NULL_TREE;
    4544              : 
    4545          187 :   unsigned HOST_WIDE_INT len = count_ctor_elements (init);
    4546          187 :   tree arr = build_array_of_n_type (init_elttype, len);
    4547          187 :   arr = finish_compound_literal (arr, init, tf_none);
    4548          187 :   DECL_MERGEABLE (TARGET_EXPR_SLOT (arr)) = true;
    4549          187 :   return arr;
    4550          375 : }
    4551              : 
    4552              : /* If we were going to call e.g. vector(initializer_list<string>) starting
    4553              :    with a list of string-literals (which is inefficient, see PR105838),
    4554              :    instead build an array of const char* and pass it to the range constructor.
    4555              :    But only do this for standard library types, where we can assume the
    4556              :    transformation makes sense.
    4557              : 
    4558              :    Really the container classes should have initializer_list<U> constructors to
    4559              :    get the same effect more simply; this is working around that lack.  */
    4560              : 
    4561              : static tree
    4562     15058615 : maybe_init_list_as_range (tree fn, tree expr)
    4563              : {
    4564     15058615 :   if (!processing_template_decl
    4565     14524173 :       && BRACE_ENCLOSED_INITIALIZER_P (expr)
    4566       904598 :       && is_list_ctor (fn)
    4567     15060279 :       && decl_in_std_namespace_p (fn))
    4568              :     {
    4569         1511 :       tree to = list_ctor_element_type (fn);
    4570         1511 :       if (tree init = maybe_init_list_as_array (to, expr))
    4571              :         {
    4572           55 :           tree begin = decay_conversion (TARGET_EXPR_SLOT (init), tf_none);
    4573           55 :           tree nelts = array_type_nelts_top (TREE_TYPE (init));
    4574           55 :           tree end = cp_build_binary_op (input_location, PLUS_EXPR, begin,
    4575              :                                          nelts, tf_none);
    4576           55 :           begin = cp_build_compound_expr (init, begin, tf_none);
    4577           55 :           return build_constructor_va (init_list_type_node, 2,
    4578           55 :                                        NULL_TREE, begin, NULL_TREE, end);
    4579              :         }
    4580              :     }
    4581              : 
    4582              :   return NULL_TREE;
    4583              : }
    4584              : 
    4585              : /* Returns the best overload candidate to perform the requested
    4586              :    conversion.  This function is used for three the overloading situations
    4587              :    described in [over.match.copy], [over.match.conv], and [over.match.ref].
    4588              :    If TOTYPE is a REFERENCE_TYPE, we're trying to find a direct binding as
    4589              :    per [dcl.init.ref], so we ignore temporary bindings.  */
    4590              : 
    4591              : static struct z_candidate *
    4592     97897618 : build_user_type_conversion_1 (tree totype, tree expr, int flags,
    4593              :                               tsubst_flags_t complain)
    4594              : {
    4595     97897618 :   struct z_candidate *candidates, *cand;
    4596     97897618 :   tree fromtype;
    4597     97897618 :   tree ctors = NULL_TREE;
    4598     97897618 :   tree conv_fns = NULL_TREE;
    4599     97897618 :   conversion *conv = NULL;
    4600     97897618 :   tree first_arg = NULL_TREE;
    4601     97897618 :   vec<tree, va_gc> *args = NULL;
    4602     97897618 :   bool any_viable_p;
    4603     97897618 :   int convflags;
    4604              : 
    4605     97897618 :   if (!expr)
    4606              :     return NULL;
    4607              : 
    4608     97897612 :   fromtype = TREE_TYPE (expr);
    4609              : 
    4610              :   /* We represent conversion within a hierarchy using RVALUE_CONV and
    4611              :      BASE_CONV, as specified by [over.best.ics]; these become plain
    4612              :      constructor calls, as specified in [dcl.init].  */
    4613     97897612 :   gcc_assert (!MAYBE_CLASS_TYPE_P (fromtype) || !MAYBE_CLASS_TYPE_P (totype)
    4614              :               || !DERIVED_FROM_P (totype, fromtype));
    4615              : 
    4616     97897612 :   if (CLASS_TYPE_P (totype))
    4617              :     /* Use lookup_fnfields_slot instead of lookup_fnfields to avoid
    4618              :        creating a garbage BASELINK; constructors can't be inherited.  */
    4619     54472880 :     ctors = get_class_binding (totype, complete_ctor_identifier);
    4620              : 
    4621     97897612 :   tree to_nonref = non_reference (totype);
    4622     97897612 :   if (MAYBE_CLASS_TYPE_P (fromtype))
    4623              :     {
    4624     67461240 :       if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
    4625     67451529 :           (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
    4626     54816567 :            && DERIVED_FROM_P (to_nonref, fromtype)))
    4627              :         {
    4628              :           /* [class.conv.fct] A conversion function is never used to
    4629              :              convert a (possibly cv-qualified) object to the (possibly
    4630              :              cv-qualified) same object type (or a reference to it), to a
    4631              :              (possibly cv-qualified) base class of that type (or a
    4632              :              reference to it)...  */
    4633              :         }
    4634              :       else
    4635     67451526 :         conv_fns = lookup_conversions (fromtype);
    4636              :     }
    4637              : 
    4638     97897612 :   candidates = 0;
    4639     97897612 :   flags |= LOOKUP_NO_CONVERSION;
    4640     97897612 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4641       948128 :     flags |= LOOKUP_NO_NARROWING;
    4642              :   /* Prevent add_candidates from treating a non-strictly viable candidate
    4643              :      as unviable.  */
    4644     97897612 :   complain |= tf_conv;
    4645              : 
    4646              :   /* It's OK to bind a temporary for converting constructor arguments, but
    4647              :      not in converting the return value of a conversion operator.  */
    4648     97897612 :   convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION
    4649     97897612 :                | (flags & LOOKUP_NO_NARROWING));
    4650     97897612 :   flags &= ~LOOKUP_NO_TEMP_BIND;
    4651              : 
    4652     97897612 :   if (ctors)
    4653              :     {
    4654     54253739 :       int ctorflags = flags;
    4655              : 
    4656     54253739 :       first_arg = build_dummy_object (totype);
    4657              : 
    4658              :       /* We should never try to call the abstract or base constructor
    4659              :          from here.  */
    4660    380764763 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (OVL_FIRST (ctors))
    4661              :                   && !DECL_HAS_VTT_PARM_P (OVL_FIRST (ctors)));
    4662              : 
    4663     54253739 :       args = make_tree_vector_single (expr);
    4664     54253739 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4665              :         {
    4666              :           /* List-initialization.  */
    4667       948128 :           add_list_candidates (ctors, first_arg, args, totype, NULL_TREE,
    4668       948128 :                                false, TYPE_BINFO (totype), TYPE_BINFO (totype),
    4669              :                                ctorflags, &candidates, complain);
    4670              :         }
    4671              :       else
    4672              :         {
    4673     53305611 :           add_candidates (ctors, first_arg, args, NULL_TREE, NULL_TREE, false,
    4674     53305611 :                           TYPE_BINFO (totype), TYPE_BINFO (totype),
    4675              :                           ctorflags, &candidates, complain);
    4676              :         }
    4677              : 
    4678    299012039 :       for (cand = candidates; cand; cand = cand->next)
    4679              :         {
    4680    244758300 :           cand->second_conv = build_identity_conv (totype, NULL_TREE);
    4681              : 
    4682              :           /* If totype isn't a reference, and LOOKUP_ONLYCONVERTING is
    4683              :              set, then this is copy-initialization.  In that case, "The
    4684              :              result of the call is then used to direct-initialize the
    4685              :              object that is the destination of the copy-initialization."
    4686              :              [dcl.init]
    4687              : 
    4688              :              We represent this in the conversion sequence with an
    4689              :              rvalue conversion, which means a constructor call.  */
    4690    244758300 :           if (!TYPE_REF_P (totype)
    4691    244758300 :               && cxx_dialect < cxx17
    4692       437624 :               && (flags & LOOKUP_ONLYCONVERTING)
    4693       379299 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4694       117658 :             cand->second_conv
    4695       117658 :               = build_conv (ck_rvalue, totype, cand->second_conv);
    4696              :         }
    4697              :     }
    4698              : 
    4699     97897612 :   if (conv_fns)
    4700              :     {
    4701     30381009 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4702            0 :         first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
    4703              :       else
    4704     97897612 :         first_arg = expr;
    4705              :     }
    4706              : 
    4707    133282854 :   for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
    4708              :     {
    4709     35385242 :       tree conversion_path = TREE_PURPOSE (conv_fns);
    4710     35385242 :       struct z_candidate *old_candidates;
    4711              : 
    4712              :       /* If LOOKUP_NO_CONVERSION, don't consider a conversion function that
    4713              :          would need an additional user-defined conversion, i.e. if the return
    4714              :          type differs in class-ness from the desired type.  So we avoid
    4715              :          considering operator bool when calling a copy constructor.
    4716              : 
    4717              :          This optimization avoids the failure in PR97600, and is allowed by
    4718              :          [temp.inst]/9: "If the function selected by overload resolution can be
    4719              :          determined without instantiating a class template definition, it is
    4720              :          unspecified whether that instantiation actually takes place."     */
    4721     35385242 :       tree convtype = non_reference (TREE_TYPE (conv_fns));
    4722     52145028 :       if ((flags & LOOKUP_NO_CONVERSION)
    4723     35385242 :           && !WILDCARD_TYPE_P (convtype)
    4724     67130454 :           && (CLASS_TYPE_P (to_nonref)
    4725     33565227 :               != CLASS_TYPE_P (convtype)))
    4726     16759786 :         continue;
    4727              : 
    4728              :       /* If we are called to convert to a reference type, we are trying to
    4729              :          find a direct binding, so don't even consider temporaries.  If
    4730              :          we don't find a direct binding, the caller will try again to
    4731              :          look for a temporary binding.  */
    4732     18625456 :       if (TYPE_REF_P (totype))
    4733      5168604 :         convflags |= LOOKUP_NO_TEMP_BIND;
    4734              : 
    4735     18625456 :       old_candidates = candidates;
    4736     18625456 :       add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype,
    4737              :                       NULL_TREE, false,
    4738     18625456 :                       conversion_path, TYPE_BINFO (fromtype),
    4739              :                       flags, &candidates, complain);
    4740              : 
    4741     37250199 :       for (cand = candidates; cand != old_candidates; cand = cand->next)
    4742              :         {
    4743     18624743 :           if (cand->viable == 0)
    4744              :             /* Already rejected, don't change to -1.  */
    4745      7036152 :             continue;
    4746              : 
    4747     11588591 :           tree rettype = TREE_TYPE (TREE_TYPE (cand->fn));
    4748     11588591 :           conversion *ics
    4749     11588591 :             = implicit_conversion (totype,
    4750              :                                    rettype,
    4751              :                                    0,
    4752              :                                    /*c_cast_p=*/false, convflags,
    4753              :                                    complain);
    4754              : 
    4755              :           /* If LOOKUP_NO_TEMP_BIND isn't set, then this is
    4756              :              copy-initialization.  In that case, "The result of the
    4757              :              call is then used to direct-initialize the object that is
    4758              :              the destination of the copy-initialization."  [dcl.init]
    4759              : 
    4760              :              We represent this in the conversion sequence with an
    4761              :              rvalue conversion, which means a constructor call.  But
    4762              :              don't add a second rvalue conversion if there's already
    4763              :              one there.  Which there really shouldn't be, but it's
    4764              :              harmless since we'd add it here anyway. */
    4765      4411799 :           if (ics && MAYBE_CLASS_TYPE_P (totype) && ics->kind != ck_rvalue
    4766     12303037 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4767       261045 :             ics = build_conv (ck_rvalue, totype, ics);
    4768              : 
    4769     11588591 :           cand->second_conv = ics;
    4770              : 
    4771     11588591 :           if (!ics)
    4772              :             {
    4773      7176792 :               cand->viable = 0;
    4774     14351019 :               cand->reason = arg_conversion_rejection (NULL_TREE, -2,
    4775              :                                                        rettype, totype,
    4776      7176792 :                                                        EXPR_LOCATION (expr));
    4777              :             }
    4778        14649 :           else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p
    4779              :                    /* Limit this to non-templates for now (PR90546).  */
    4780         1896 :                    && !cand->template_decl
    4781      4413690 :                    && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE)
    4782              :             {
    4783              :               /* If we are called to convert to a reference type, we are trying
    4784              :                  to find a direct binding per [over.match.ref], so rvaluedness
    4785              :                  must match for non-functions.  */
    4786         1885 :               cand->viable = 0;
    4787              :             }
    4788      4409914 :           else if (DECL_NONCONVERTING_P (cand->fn)
    4789      4409914 :                    && ics->rank > cr_exact)
    4790              :             {
    4791              :               /* 13.3.1.5: For direct-initialization, those explicit
    4792              :                  conversion functions that are not hidden within S and
    4793              :                  yield type T or a type that can be converted to type T
    4794              :                  with a qualification conversion (4.4) are also candidate
    4795              :                  functions.  */
    4796              :               /* 13.3.1.6 doesn't have a parallel restriction, but it should;
    4797              :                  I've raised this issue with the committee. --jason 9/2011 */
    4798         2747 :               cand->viable = -1;
    4799         2747 :               cand->reason = explicit_conversion_rejection (rettype, totype);
    4800              :             }
    4801      4407167 :           else if (cand->viable == 1 && ics->bad_p)
    4802              :             {
    4803         2579 :               cand->viable = -1;
    4804         2579 :               cand->reason
    4805         5158 :                 = bad_arg_conversion_rejection (NULL_TREE, -2,
    4806              :                                                 rettype, totype,
    4807         2579 :                                                 EXPR_LOCATION (expr));
    4808              :             }
    4809      4404588 :           else if (primary_template_specialization_p (cand->fn)
    4810      4404588 :                    && ics->rank > cr_exact)
    4811              :             {
    4812              :               /* 13.3.3.1.2: If the user-defined conversion is specified by
    4813              :                  a specialization of a conversion function template, the
    4814              :                  second standard conversion sequence shall have exact match
    4815              :                  rank.  */
    4816           21 :               cand->viable = -1;
    4817           21 :               cand->reason = template_conversion_rejection (rettype, totype);
    4818              :             }
    4819              :         }
    4820              :     }
    4821              : 
    4822     97897612 :   candidates = splice_viable (candidates, false, &any_viable_p);
    4823     97897612 :   if (!any_viable_p)
    4824              :     {
    4825     82837651 :       if (args)
    4826     42876752 :         release_tree_vector (args);
    4827              :       return NULL;
    4828              :     }
    4829              : 
    4830     15059961 :   cand = tourney (candidates, complain);
    4831     15059961 :   if (cand == NULL)
    4832              :     {
    4833         1346 :       if (complain & tf_error)
    4834              :         {
    4835           71 :           auto_diagnostic_group d;
    4836           74 :           error_at (cp_expr_loc_or_input_loc (expr),
    4837              :                     "conversion from %qH to %qI is ambiguous",
    4838              :                     fromtype, totype);
    4839           71 :           print_z_candidates (location_of (expr), candidates);
    4840           71 :         }
    4841              : 
    4842         1346 :       cand = candidates;        /* any one will do */
    4843         1346 :       cand->second_conv = build_ambiguous_conv (totype, expr);
    4844         1346 :       cand->second_conv->user_conv_p = true;
    4845         2692 :       if (!any_strictly_viable (candidates))
    4846           12 :         cand->second_conv->bad_p = true;
    4847         1346 :       if (flags & LOOKUP_ONLYCONVERTING)
    4848         1273 :         cand->second_conv->need_temporary_p = true;
    4849              :       /* If there are viable candidates, don't set ICS_BAD_FLAG; an
    4850              :          ambiguous conversion is no worse than another user-defined
    4851              :          conversion.  */
    4852              : 
    4853              :       return cand;
    4854              :     }
    4855              : 
    4856              :   /* Maybe pass { } as iterators instead of an initializer_list.  */
    4857     15058615 :   if (tree iters = maybe_init_list_as_range (cand->fn, expr))
    4858          110 :     if (z_candidate *cand2
    4859           55 :         = build_user_type_conversion_1 (totype, iters, flags, tf_none))
    4860           52 :       if (cand2->viable == 1 && !is_list_ctor (cand2->fn))
    4861              :         {
    4862              :           cand = cand2;
    4863              :           expr = iters;
    4864              :         }
    4865              : 
    4866     15058615 :   tree convtype;
    4867     30117230 :   if (!DECL_CONSTRUCTOR_P (cand->fn))
    4868      4397416 :     convtype = non_reference (TREE_TYPE (TREE_TYPE (cand->fn)));
    4869     10661199 :   else if (cand->second_conv->kind == ck_rvalue)
    4870              :     /* DR 5: [in the first step of copy-initialization]...if the function
    4871              :        is a constructor, the call initializes a temporary of the
    4872              :        cv-unqualified version of the destination type. */
    4873        12081 :     convtype = cv_unqualified (totype);
    4874              :   else
    4875              :     convtype = totype;
    4876              :   /* Build the user conversion sequence.  */
    4877     15058615 :   conv = build_conv
    4878     15058615 :     (ck_user,
    4879              :      convtype,
    4880     15058615 :      build_identity_conv (TREE_TYPE (expr), expr));
    4881     15058615 :   conv->cand = cand;
    4882     15058615 :   if (cand->viable == -1)
    4883        11601 :     conv->bad_p = true;
    4884              : 
    4885              :   /* Remember that this was a list-initialization.  */
    4886     15058615 :   if (flags & LOOKUP_NO_NARROWING)
    4887      3375671 :     conv->check_narrowing = true;
    4888              : 
    4889              :   /* Combine it with the second conversion sequence.  */
    4890     15058615 :   cand->second_conv = merge_conversion_sequences (conv,
    4891              :                                                   cand->second_conv);
    4892              : 
    4893     15058615 :   return cand;
    4894              : }
    4895              : 
    4896              : /* Wrapper for above. */
    4897              : 
    4898              : tree
    4899        24420 : build_user_type_conversion (tree totype, tree expr, int flags,
    4900              :                             tsubst_flags_t complain)
    4901              : {
    4902        24420 :   struct z_candidate *cand;
    4903        24420 :   tree ret;
    4904              : 
    4905        24420 :   auto_cond_timevar tv (TV_OVERLOAD);
    4906              : 
    4907        24420 :   conversion_obstack_sentinel cos;
    4908              : 
    4909        24420 :   cand = build_user_type_conversion_1 (totype, expr, flags, complain);
    4910              : 
    4911        24420 :   if (cand)
    4912              :     {
    4913        24190 :       if (cand->second_conv->kind == ck_ambig)
    4914           65 :         ret = error_mark_node;
    4915              :       else
    4916              :         {
    4917        24125 :           expr = convert_like (cand->second_conv, expr, complain);
    4918        24125 :           ret = convert_from_reference (expr);
    4919              :         }
    4920              :     }
    4921              :   else
    4922              :     ret = NULL_TREE;
    4923              : 
    4924        48840 :   return ret;
    4925        24420 : }
    4926              : 
    4927              : /* Give a helpful diagnostic when implicit_conversion fails.  */
    4928              : 
    4929              : static void
    4930          700 : implicit_conversion_error (location_t loc, tree type, tree expr,
    4931              :                            int flags)
    4932              : {
    4933          700 :   tsubst_flags_t complain = tf_warning_or_error;
    4934              : 
    4935              :   /* If expr has unknown type, then it is an overloaded function.
    4936              :      Call instantiate_type to get good error messages.  */
    4937          700 :   if (TREE_TYPE (expr) == unknown_type_node)
    4938           60 :     instantiate_type (type, expr, complain);
    4939          640 :   else if (invalid_nonstatic_memfn_p (loc, expr, complain))
    4940              :     /* We gave an error.  */;
    4941           72 :   else if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    4942           69 :            && CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    4943          655 :            && !CP_AGGREGATE_TYPE_P (type))
    4944           20 :     error_at (loc, "designated initializers cannot be used with a "
    4945              :               "non-aggregate type %qT", type);
    4946              :   else
    4947              :     {
    4948          615 :       auto_diagnostic_group d;
    4949          615 :       if (is_stub_object (expr))
    4950              :         /* The expression is generated by a trait check, we don't have
    4951              :            a useful location to highlight the label.  */
    4952           17 :         error_at (loc, "could not convert %qH to %qI",
    4953           17 :                   TREE_TYPE (expr), type);
    4954              :       else
    4955              :         {
    4956          598 :           range_label_for_type_mismatch label (TREE_TYPE (expr), type);
    4957          598 :           gcc_rich_location rich_loc (loc, &label,
    4958          598 :                                       highlight_colors::percent_h);
    4959          598 :           error_at (&rich_loc, "could not convert %qE from %qH to %qI",
    4960          598 :                     expr, TREE_TYPE (expr), type);
    4961          598 :         }
    4962          615 :       maybe_show_nonconverting_candidate (type, TREE_TYPE (expr), expr, flags);
    4963          615 :     }
    4964          700 : }
    4965              : 
    4966              : /* Worker for build_converted_constant_expr.  */
    4967              : 
    4968              : static tree
    4969    339388731 : build_converted_constant_expr_internal (tree type, tree expr,
    4970              :                                         int flags, tsubst_flags_t complain)
    4971              : {
    4972    339388731 :   conversion *conv;
    4973    339388731 :   tree t;
    4974    339388731 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    4975              : 
    4976    339388731 :   if (error_operand_p (expr))
    4977           65 :     return error_mark_node;
    4978              : 
    4979    339388666 :   conversion_obstack_sentinel cos;
    4980              : 
    4981    339388666 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
    4982              :                               /*c_cast_p=*/false, flags, complain);
    4983              : 
    4984              :   /* A converted constant expression of type T is an expression, implicitly
    4985              :      converted to type T, where the converted expression is a constant
    4986              :      expression and the implicit conversion sequence contains only
    4987              : 
    4988              :        * user-defined conversions,
    4989              :        * lvalue-to-rvalue conversions (7.1),
    4990              :        * array-to-pointer conversions (7.2),
    4991              :        * function-to-pointer conversions (7.3),
    4992              :        * qualification conversions (7.5),
    4993              :        * integral promotions (7.6),
    4994              :        * integral conversions (7.8) other than narrowing conversions (11.6.4),
    4995              :        * null pointer conversions (7.11) from std::nullptr_t,
    4996              :        * null member pointer conversions (7.12) from std::nullptr_t, and
    4997              :        * function pointer conversions (7.13),
    4998              : 
    4999              :      and where the reference binding (if any) binds directly.  */
    5000              : 
    5001    339388666 :   for (conversion *c = conv;
    5002    391668899 :        c && c->kind != ck_identity;
    5003     52280233 :        c = next_conversion (c))
    5004              :     {
    5005     52280233 :       switch (c->kind)
    5006              :         {
    5007              :           /* A conversion function is OK.  If it isn't constexpr, we'll
    5008              :              complain later that the argument isn't constant.  */
    5009              :         case ck_user:
    5010              :           /* List-initialization is OK.  */
    5011              :         case ck_aggr:
    5012              :           /* The lvalue-to-rvalue conversion is OK.  */
    5013              :         case ck_rvalue:
    5014              :           /* Array-to-pointer and function-to-pointer.  */
    5015              :         case ck_lvalue:
    5016              :           /* Function pointer conversions.  */
    5017              :         case ck_fnptr:
    5018              :           /* Qualification conversions.  */
    5019              :         case ck_qual:
    5020              :           break;
    5021              : 
    5022          775 :         case ck_ref_bind:
    5023          775 :           if (c->need_temporary_p)
    5024              :             {
    5025            6 :               if (complain & tf_error)
    5026            1 :                 error_at (loc, "initializing %qH with %qI in converted "
    5027              :                           "constant expression does not bind directly",
    5028            1 :                           type, next_conversion (c)->type);
    5029              :               conv = NULL;
    5030              :             }
    5031              :           break;
    5032              : 
    5033      9487093 :         case ck_base:
    5034      9487093 :         case ck_pmem:
    5035      9487093 :         case ck_ptr:
    5036      9487093 :         case ck_std:
    5037      9487093 :           t = next_conversion (c)->type;
    5038      9487093 :           if (INTEGRAL_OR_ENUMERATION_TYPE_P (t)
    5039      9487013 :               && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    5040              :             /* Integral promotion or conversion.  */
    5041              :             break;
    5042          114 :           if (NULLPTR_TYPE_P (t))
    5043              :             /* Conversion from nullptr to pointer or pointer-to-member.  */
    5044              :             break;
    5045              : 
    5046          114 :           if (complain & tf_error)
    5047           82 :             error_at (loc, "conversion from %qH to %qI in a "
    5048              :                       "converted constant expression", t, type);
    5049              :           /* fall through.  */
    5050              : 
    5051              :         default:
    5052              :           conv = NULL;
    5053              :           break;
    5054              :         }
    5055              :     }
    5056              : 
    5057              :   /* Avoid confusing convert_nontype_argument by introducing
    5058              :      a redundant conversion to the same reference type.  */
    5059    339387140 :   if (conv && conv->kind == ck_ref_bind
    5060    339389435 :       && REFERENCE_REF_P (expr))
    5061              :     {
    5062          495 :       tree ref = TREE_OPERAND (expr, 0);
    5063          495 :       if (same_type_p (type, TREE_TYPE (ref)))
    5064              :         return ref;
    5065              :     }
    5066              : 
    5067    339388195 :   if (conv)
    5068              :     {
    5069              :       /* Don't copy a class in a template.  */
    5070        67491 :       if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue
    5071    339421893 :           && processing_template_decl)
    5072          393 :         conv = next_conversion (conv);
    5073              : 
    5074              :       /* Issuing conversion warnings for value-dependent expressions is
    5075              :          likely too noisy.  */
    5076    339386669 :       warning_sentinel w (warn_conversion);
    5077    339386669 :       conv->check_narrowing = true;
    5078    339386669 :       conv->check_narrowing_const_only = true;
    5079    339386669 :       expr = convert_like (conv, expr, complain);
    5080    339386669 :     }
    5081              :   else
    5082              :     {
    5083         1526 :       if (complain & tf_error)
    5084          212 :         implicit_conversion_error (loc, type, expr, flags);
    5085         1526 :       expr = error_mark_node;
    5086              :     }
    5087              : 
    5088              :   return expr;
    5089    339388666 : }
    5090              : 
    5091              : /* Subroutine of convert_nontype_argument.
    5092              : 
    5093              :    EXPR is an expression used in a context that requires a converted
    5094              :    constant-expression, such as a template non-type parameter.  Do any
    5095              :    necessary conversions (that are permitted for converted
    5096              :    constant-expressions) to convert it to the desired type.
    5097              : 
    5098              :    This function doesn't consider explicit conversion functions.  If
    5099              :    you mean to use "a contextually converted constant expression of type
    5100              :    bool", use build_converted_constant_bool_expr.
    5101              : 
    5102              :    If conversion is successful, returns the converted expression;
    5103              :    otherwise, returns error_mark_node.  */
    5104              : 
    5105              : tree
    5106    193880139 : build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
    5107              : {
    5108    193880139 :   return build_converted_constant_expr_internal (type, expr, LOOKUP_IMPLICIT,
    5109    193880139 :                                                  complain);
    5110              : }
    5111              : 
    5112              : /* Used to create "a contextually converted constant expression of type
    5113              :    bool".  This differs from build_converted_constant_expr in that it
    5114              :    also considers explicit conversion functions.  */
    5115              : 
    5116              : tree
    5117    145508592 : build_converted_constant_bool_expr (tree expr, tsubst_flags_t complain)
    5118              : {
    5119    145508592 :   return build_converted_constant_expr_internal (boolean_type_node, expr,
    5120    145508592 :                                                  LOOKUP_NORMAL, complain);
    5121              : }
    5122              : 
    5123              : /* Do any initial processing on the arguments to a function call.  */
    5124              : 
    5125              : vec<tree, va_gc> *
    5126    211638651 : resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
    5127              : {
    5128    211638651 :   unsigned int ix;
    5129    211638651 :   tree arg;
    5130              : 
    5131    391944583 :   FOR_EACH_VEC_SAFE_ELT (args, ix, arg)
    5132              :     {
    5133    180306685 :       if (error_operand_p (arg))
    5134              :         return NULL;
    5135    180306114 :       else if (VOID_TYPE_P (TREE_TYPE (arg)))
    5136              :         {
    5137          155 :           if (complain & tf_error)
    5138           12 :             error_at (cp_expr_loc_or_input_loc (arg),
    5139              :                       "invalid use of void expression");
    5140              :           return NULL;
    5141              :         }
    5142    180305959 :       else if (invalid_nonstatic_memfn_p (EXPR_LOCATION (arg), arg, complain))
    5143              :         return NULL;
    5144              : 
    5145              :       /* Force auto deduction now.  Omit tf_warning to avoid redundant
    5146              :          deprecated warning on deprecated-14.C.  */
    5147    180305932 :       if (!mark_single_function (arg, complain & ~tf_warning))
    5148              :         return NULL;
    5149              :     }
    5150              :   return args;
    5151              : }
    5152              : 
    5153              : /* Perform overload resolution on FN, which is called with the ARGS.
    5154              : 
    5155              :    Return the candidate function selected by overload resolution, or
    5156              :    NULL if the event that overload resolution failed.  In the case
    5157              :    that overload resolution fails, *CANDIDATES will be the set of
    5158              :    candidates considered, and ANY_VIABLE_P will be set to true or
    5159              :    false to indicate whether or not any of the candidates were
    5160              :    viable.
    5161              : 
    5162              :    The ARGS should already have gone through RESOLVE_ARGS before this
    5163              :    function is called.  */
    5164              : 
    5165              : static struct z_candidate *
    5166    103992523 : perform_overload_resolution (tree fn,
    5167              :                              const vec<tree, va_gc> *args,
    5168              :                              struct z_candidate **candidates,
    5169              :                              bool *any_viable_p, tsubst_flags_t complain)
    5170              : {
    5171    103992523 :   struct z_candidate *cand;
    5172    103992523 :   tree explicit_targs;
    5173    103992523 :   int template_only;
    5174              : 
    5175    103992523 :   auto_cond_timevar tv (TV_OVERLOAD);
    5176              : 
    5177    103992523 :   explicit_targs = NULL_TREE;
    5178    103992523 :   template_only = 0;
    5179              : 
    5180    103992523 :   *candidates = NULL;
    5181    103992523 :   *any_viable_p = true;
    5182              : 
    5183              :   /* Check FN.  */
    5184    103992523 :   gcc_assert (OVL_P (fn) || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
    5185              : 
    5186    103992523 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5187              :     {
    5188     36558275 :       explicit_targs = TREE_OPERAND (fn, 1);
    5189     36558275 :       fn = TREE_OPERAND (fn, 0);
    5190     36558275 :       template_only = 1;
    5191              :     }
    5192              : 
    5193              :   /* Add the various candidate functions.  */
    5194    103992523 :   add_candidates (fn, NULL_TREE, args, NULL_TREE,
    5195              :                   explicit_targs, template_only,
    5196              :                   /*conversion_path=*/NULL_TREE,
    5197              :                   /*access_path=*/NULL_TREE,
    5198              :                   LOOKUP_NORMAL,
    5199              :                   candidates, complain & ~tf_any_viable);
    5200              : 
    5201    103979005 :   *candidates = splice_viable (*candidates, false, any_viable_p);
    5202    103979005 :   if (*any_viable_p)
    5203              :     {
    5204    103787332 :       if (complain & tf_any_viable)
    5205              :         cand = *candidates;
    5206              :       else
    5207    103787146 :         cand = tourney (*candidates, complain);
    5208              :     }
    5209              :   else
    5210              :     cand = NULL;
    5211              : 
    5212    207958010 :   return cand;
    5213    103979005 : }
    5214              : 
    5215              : /* Print an error message about being unable to build a call to FN with
    5216              :    ARGS.  ANY_VIABLE_P indicates whether any candidate functions could
    5217              :    be located; CANDIDATES is a possibly empty list of such
    5218              :    functions.  */
    5219              : 
    5220              : static void
    5221         3009 : print_error_for_call_failure (tree fn, const vec<tree, va_gc> *args,
    5222              :                               struct z_candidate *candidates)
    5223              : {
    5224         3009 :   tree targs = NULL_TREE;
    5225         3009 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5226              :     {
    5227          560 :       targs = TREE_OPERAND (fn, 1);
    5228          560 :       fn = TREE_OPERAND (fn, 0);
    5229              :     }
    5230         6018 :   tree name = OVL_NAME (fn);
    5231         3009 :   location_t loc = location_of (name);
    5232         3009 :   if (targs)
    5233          560 :     name = lookup_template_function (name, targs);
    5234              : 
    5235         3009 :   auto_diagnostic_group d;
    5236         6018 :   if (!any_strictly_viable (candidates))
    5237         2524 :     error_at (loc, "no matching function for call to %<%D(%A)%>",
    5238              :               name, build_tree_list_vec (args));
    5239              :   else
    5240          485 :     error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous",
    5241              :               name, build_tree_list_vec (args));
    5242         3009 :   if (candidates)
    5243         3009 :     print_z_candidates (loc, candidates);
    5244         3009 : }
    5245              : 
    5246              : /* Perform overload resolution on the set of deduction guides DGUIDES
    5247              :    using ARGS.  Returns the selected deduction guide, or error_mark_node
    5248              :    if overload resolution fails.  */
    5249              : 
    5250              : tree
    5251        31363 : perform_dguide_overload_resolution (tree dguides, const vec<tree, va_gc> *args,
    5252              :                                     tsubst_flags_t complain)
    5253              : {
    5254        31363 :   z_candidate *candidates;
    5255        31363 :   bool any_viable_p;
    5256        31363 :   tree result;
    5257              : 
    5258        62726 :   gcc_assert (deduction_guide_p (OVL_FIRST (dguides)));
    5259              : 
    5260        31363 :   conversion_obstack_sentinel cos;
    5261              : 
    5262        31363 :   z_candidate *cand = perform_overload_resolution (dguides, args, &candidates,
    5263              :                                                    &any_viable_p, complain);
    5264        31363 :   if (!cand)
    5265              :     {
    5266          971 :       if (complain & tf_error)
    5267          198 :         print_error_for_call_failure (dguides, args, candidates);
    5268          971 :       result = error_mark_node;
    5269              :     }
    5270              :   else
    5271        30392 :     result = cand->fn;
    5272              : 
    5273        62726 :   return result;
    5274        31363 : }
    5275              : 
    5276              : /* Return an expression for a call to FN (a namespace-scope function,
    5277              :    or a static member function) with the ARGS.  This may change
    5278              :    ARGS.  */
    5279              : 
    5280              : tree
    5281    102875694 : build_new_function_call (tree fn, vec<tree, va_gc> **args,
    5282              :                          tsubst_flags_t complain)
    5283              : {
    5284    102875694 :   struct z_candidate *candidates, *cand;
    5285    102875694 :   bool any_viable_p;
    5286    102875694 :   tree result;
    5287              : 
    5288    102875694 :   if (args != NULL && *args != NULL)
    5289              :     {
    5290    102875694 :       *args = resolve_args (*args, complain & ~tf_any_viable);
    5291    102875694 :       if (*args == NULL)
    5292          441 :         return error_mark_node;
    5293              :     }
    5294              : 
    5295    102875253 :   if (flag_tm)
    5296         3563 :     tm_malloc_replacement (fn);
    5297              : 
    5298    102875253 :   conversion_obstack_sentinel cos;
    5299              : 
    5300    102875253 :   cand = perform_overload_resolution (fn, *args, &candidates, &any_viable_p,
    5301              :                                       complain);
    5302              : 
    5303    102861735 :   if (!cand)
    5304              :     {
    5305       203712 :       if (complain & tf_error)
    5306              :         {
    5307              :           // If there is a single (non-viable) function candidate,
    5308              :           // let the error be diagnosed by cp_build_function_call_vec.
    5309         3273 :           if (!any_viable_p && candidates && ! candidates->next
    5310         1488 :               && TREE_CODE (candidates->fn) == FUNCTION_DECL
    5311              :               /* A template-id callee consisting of a single (ignored)
    5312              :                  non-template candidate needs to be diagnosed the
    5313              :                  ordinary way.  */
    5314          483 :               && (TREE_CODE (fn) != TEMPLATE_ID_EXPR
    5315           33 :                   || candidates->template_decl))
    5316          471 :             return cp_build_function_call_vec (candidates->fn, args, complain);
    5317              : 
    5318              :           // Otherwise, emit notes for non-viable candidates.
    5319         2802 :           print_error_for_call_failure (fn, *args, candidates);
    5320              :         }
    5321       203241 :       result = error_mark_node;
    5322              :     }
    5323    102658023 :   else if (complain & tf_any_viable)
    5324          186 :     return void_node;
    5325              :   else
    5326    102657837 :     result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5327              : 
    5328    102861078 :   if (flag_coroutines
    5329    100753599 :       && result
    5330    100753599 :       && TREE_CODE (result) == CALL_EXPR
    5331    164245851 :       && DECL_BUILT_IN_CLASS (TREE_OPERAND (CALL_EXPR_FN (result), 0))
    5332     61384773 :           == BUILT_IN_NORMAL)
    5333      8189509 :    result = coro_validate_builtin_call (result);
    5334              : 
    5335              :   return result;
    5336    102861735 : }
    5337              : 
    5338              : /* Build a call to a global operator new.  FNNAME is the name of the
    5339              :    operator (either "operator new" or "operator new[]") and ARGS are
    5340              :    the arguments provided.  This may change ARGS.  *SIZE points to the
    5341              :    total number of bytes required by the allocation, and is updated if
    5342              :    that is changed here.  *COOKIE_SIZE is non-NULL if a cookie should
    5343              :    be used.  If this function determines that no cookie should be
    5344              :    used, after all, *COOKIE_SIZE is set to NULL_TREE.  If SIZE_CHECK
    5345              :    is not NULL_TREE, it is evaluated before calculating the final
    5346              :    array size, and if it fails, the array size is replaced with
    5347              :    (size_t)-1 (usually triggering a std::bad_alloc exception).  If FN
    5348              :    is non-NULL, it will be set, upon return, to the allocation
    5349              :    function called.  */
    5350              : 
    5351              : tree
    5352      1085852 : build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
    5353              :                          tree *size, tree *cookie_size,
    5354              :                          tree align_arg, tree size_check,
    5355              :                          tree *fn, tsubst_flags_t complain)
    5356              : {
    5357      1085852 :   tree original_size = *size;
    5358      1085852 :   tree fns;
    5359      1085852 :   struct z_candidate *candidates;
    5360      1085852 :   struct z_candidate *cand = NULL;
    5361      1085852 :   bool any_viable_p;
    5362              : 
    5363      1085852 :   if (fn)
    5364      1084383 :     *fn = NULL_TREE;
    5365              :   /* Set to (size_t)-1 if the size check fails.  */
    5366      1085852 :   if (size_check != NULL_TREE)
    5367              :     {
    5368        21111 :       tree errval = TYPE_MAX_VALUE (sizetype);
    5369        21111 :       if (cxx_dialect >= cxx11 && flag_exceptions)
    5370        20704 :         errval = throw_bad_array_new_length ();
    5371        21111 :       *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5372              :                            original_size, errval);
    5373              :     }
    5374      1085852 :   vec_safe_insert (*args, 0, *size);
    5375      1085852 :   *args = resolve_args (*args, complain);
    5376      1085852 :   if (*args == NULL)
    5377            0 :     return error_mark_node;
    5378              : 
    5379      1085852 :   conversion_obstack_sentinel cos;
    5380              : 
    5381              :   /* Based on:
    5382              : 
    5383              :        [expr.new]
    5384              : 
    5385              :        If this lookup fails to find the name, or if the allocated type
    5386              :        is not a class type, the allocation function's name is looked
    5387              :        up in the global scope.
    5388              : 
    5389              :      we disregard block-scope declarations of "operator new".  */
    5390      1085852 :   fns = lookup_qualified_name (global_namespace, fnname);
    5391              : 
    5392      1085852 :   if (align_arg)
    5393              :     {
    5394         9449 :       vec<tree, va_gc>* align_args
    5395         9449 :         = vec_copy_and_insert (*args, align_arg, 1);
    5396         9449 :       cand = perform_overload_resolution (fns, align_args, &candidates,
    5397              :                                           &any_viable_p, tf_none);
    5398         9449 :       if (cand)
    5399         9394 :         *args = align_args;
    5400              :       /* If no aligned allocation function matches, try again without the
    5401              :          alignment.  */
    5402              :     }
    5403              : 
    5404              :   /* Figure out what function is being called.  */
    5405         9394 :   if (!cand)
    5406      1076458 :     cand = perform_overload_resolution (fns, *args, &candidates, &any_viable_p,
    5407              :                                         complain);
    5408              : 
    5409              :   /* If no suitable function could be found, issue an error message
    5410              :      and give up.  */
    5411      1085852 :   if (!cand)
    5412              :     {
    5413            9 :       if (complain & tf_error)
    5414            9 :         print_error_for_call_failure (fns, *args, candidates);
    5415            9 :       return error_mark_node;
    5416              :     }
    5417              : 
    5418              :    /* If a cookie is required, add some extra space.  Whether
    5419              :       or not a cookie is required cannot be determined until
    5420              :       after we know which function was called.  */
    5421      1085843 :    if (*cookie_size)
    5422              :      {
    5423          268 :        bool use_cookie = true;
    5424          268 :        tree arg_types;
    5425              : 
    5426          268 :        arg_types = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    5427              :        /* Skip the size_t parameter.  */
    5428          268 :        arg_types = TREE_CHAIN (arg_types);
    5429              :        /* Check the remaining parameters (if any).  */
    5430          268 :        if (arg_types
    5431          268 :            && TREE_CHAIN (arg_types) == void_list_node
    5432          331 :            && same_type_p (TREE_VALUE (arg_types),
    5433              :                            ptr_type_node))
    5434           48 :          use_cookie = false;
    5435              :        /* If we need a cookie, adjust the number of bytes allocated.  */
    5436          268 :        if (use_cookie)
    5437              :          {
    5438              :            /* Update the total size.  */
    5439          220 :            *size = size_binop (PLUS_EXPR, original_size, *cookie_size);
    5440          220 :            if (size_check)
    5441              :              {
    5442              :                /* Set to (size_t)-1 if the size check fails.  */
    5443           47 :                gcc_assert (size_check != NULL_TREE);
    5444           47 :                *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5445              :                                     *size, TYPE_MAX_VALUE (sizetype));
    5446              :             }
    5447              :            /* Update the argument list to reflect the adjusted size.  */
    5448          220 :            (**args)[0] = *size;
    5449              :          }
    5450              :        else
    5451           48 :          *cookie_size = NULL_TREE;
    5452              :      }
    5453              : 
    5454              :    /* Tell our caller which function we decided to call.  */
    5455      1085843 :    if (fn)
    5456      1084374 :      *fn = cand->fn;
    5457              : 
    5458              :    /* Build the CALL_EXPR.  */
    5459      1085843 :    tree ret = build_over_call (cand, LOOKUP_NORMAL, complain);
    5460              : 
    5461              :    /* Set this flag for all callers of this function.  In addition to
    5462              :       new-expressions, this is called for allocating coroutine state; treat
    5463              :       that as an implicit new-expression.  */
    5464      1085843 :    tree call = extract_call_expr (ret);
    5465      1085843 :    if (TREE_CODE (call) == CALL_EXPR)
    5466      1085843 :      CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    5467              : 
    5468              :    return ret;
    5469      1085852 : }
    5470              : 
    5471              : /* Evaluate side-effects from OBJ before evaluating call
    5472              :    to FN in RESULT expression.
    5473              :    This is for expressions of the form `obj->fn(...)'
    5474              :    where `fn' turns out to be a static member function and
    5475              :    `obj' needs to be evaluated.  `fn' could be also static operator[]
    5476              :    or static operator(), in which cases the source expression
    5477              :    would be `obj[...]' or `obj(...)'.  */
    5478              : 
    5479              : tree
    5480     80694671 : keep_unused_object_arg (tree result, tree obj, tree fn)
    5481              : {
    5482     80694671 :   if (result == NULL_TREE
    5483     80694671 :       || result == error_mark_node
    5484     79690153 :       || DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    5485     83436186 :       || !TREE_SIDE_EFFECTS (obj))
    5486              :     return result;
    5487              : 
    5488              :   /* But avoid the implicit lvalue-rvalue conversion when `obj' is
    5489              :      volatile.  */
    5490        89374 :   tree a = obj;
    5491        89374 :   if (TREE_THIS_VOLATILE (a))
    5492        58044 :     a = build_this (a);
    5493        89374 :   if (TREE_SIDE_EFFECTS (a))
    5494        31339 :     return cp_build_compound_expr (a, result, tf_error);
    5495              :   return result;
    5496              : }
    5497              : 
    5498              : /* Build a new call to operator().  This may change ARGS.  */
    5499              : 
    5500              : tree
    5501      2650990 : build_op_call (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
    5502              : {
    5503      2650990 :   struct z_candidate *candidates = 0, *cand;
    5504      2650990 :   tree fns, convs, first_mem_arg = NULL_TREE;
    5505      2650990 :   bool any_viable_p;
    5506      2650990 :   tree result = NULL_TREE;
    5507              : 
    5508      2650990 :   auto_cond_timevar tv (TV_OVERLOAD);
    5509              : 
    5510      2650990 :   obj = mark_lvalue_use (obj);
    5511              : 
    5512      2650990 :   if (error_operand_p (obj))
    5513            0 :     return error_mark_node;
    5514              : 
    5515      2650990 :   tree type = TREE_TYPE (obj);
    5516              : 
    5517      2650990 :   obj = prep_operand (obj);
    5518              : 
    5519      2650990 :   if (TYPE_PTRMEMFUNC_P (type))
    5520              :     {
    5521            0 :       if (complain & tf_error)
    5522              :         /* It's no good looking for an overloaded operator() on a
    5523              :            pointer-to-member-function.  */
    5524            0 :         error ("pointer-to-member function %qE cannot be called without "
    5525              :                "an object; consider using %<.*%> or %<->*%>", obj);
    5526            0 :       return error_mark_node;
    5527              :     }
    5528              : 
    5529      2650990 :   if (TYPE_BINFO (type))
    5530              :     {
    5531      2650966 :       fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1, complain);
    5532      2650966 :       if (fns == error_mark_node)
    5533              :         return error_mark_node;
    5534              :     }
    5535              :   else
    5536              :     fns = NULL_TREE;
    5537              : 
    5538      2650980 :   if (args != NULL && *args != NULL)
    5539              :     {
    5540      2650980 :       *args = resolve_args (*args, complain);
    5541      2650980 :       if (*args == NULL)
    5542          110 :         return error_mark_node;
    5543              :     }
    5544              : 
    5545      2650870 :   conversion_obstack_sentinel cos;
    5546              : 
    5547      2650870 :   if (fns)
    5548              :     {
    5549      2645518 :       first_mem_arg = obj;
    5550              : 
    5551      2645518 :       add_candidates (BASELINK_FUNCTIONS (fns),
    5552              :                       first_mem_arg, *args, NULL_TREE,
    5553              :                       NULL_TREE, false,
    5554      2645518 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    5555              :                       LOOKUP_NORMAL, &candidates, complain);
    5556              :     }
    5557              : 
    5558      2650870 :   bool any_call_ops = candidates != nullptr;
    5559              : 
    5560      2650870 :   convs = lookup_conversions (type);
    5561              : 
    5562      5494378 :   for (; convs; convs = TREE_CHAIN (convs))
    5563              :     {
    5564       192638 :       tree totype = TREE_TYPE (convs);
    5565              : 
    5566       159057 :       if (TYPE_PTRFN_P (totype)
    5567        33584 :           || TYPE_REFFN_P (totype)
    5568       226178 :           || (TYPE_REF_P (totype)
    5569         1189 :               && TYPE_PTRFN_P (TREE_TYPE (totype))))
    5570       318638 :         for (tree fn : ovl_range (TREE_VALUE (convs)))
    5571              :           {
    5572       159319 :             if (DECL_NONCONVERTING_P (fn))
    5573            3 :               continue;
    5574              : 
    5575       159316 :             if (TREE_CODE (fn) == TEMPLATE_DECL)
    5576              :               {
    5577              :                 /* Making this work broke PR 71117 and 85118, so until the
    5578              :                    committee resolves core issue 2189, let's disable this
    5579              :                    candidate if there are any call operators.  */
    5580        39641 :                 if (any_call_ops)
    5581        39629 :                   continue;
    5582              : 
    5583           12 :                 add_template_conv_candidate
    5584           12 :                   (&candidates, fn, obj, *args, totype,
    5585              :                    /*access_path=*/NULL_TREE,
    5586              :                    /*conversion_path=*/NULL_TREE, complain);
    5587              :               }
    5588              :             else
    5589       119675 :               add_conv_candidate (&candidates, fn, obj,
    5590              :                                   *args, /*conversion_path=*/NULL_TREE,
    5591              :                                   /*access_path=*/NULL_TREE, complain);
    5592              :           }
    5593              :     }
    5594              : 
    5595              :   /* Be strict here because if we choose a bad conversion candidate, the
    5596              :      errors we get won't mention the call context.  */
    5597      2650870 :   candidates = splice_viable (candidates, true, &any_viable_p);
    5598      2650870 :   if (!any_viable_p)
    5599              :     {
    5600        40458 :       if (complain & tf_error)
    5601              :         {
    5602          282 :           auto_diagnostic_group d;
    5603          282 :           error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj),
    5604              :                  build_tree_list_vec (*args));
    5605          282 :           print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5606          282 :         }
    5607        40458 :       result = error_mark_node;
    5608              :     }
    5609              :   else
    5610              :     {
    5611      2610412 :       cand = tourney (candidates, complain);
    5612      2610412 :       if (cand == 0)
    5613              :         {
    5614           22 :           if (complain & tf_error)
    5615              :             {
    5616            6 :               auto_diagnostic_group d;
    5617           12 :               error ("call of %<(%T) (%A)%> is ambiguous",
    5618            6 :                      TREE_TYPE (obj), build_tree_list_vec (*args));
    5619            6 :               print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5620            6 :             }
    5621           22 :           result = error_mark_node;
    5622              :         }
    5623      2610390 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    5624      2610331 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    5625      5220721 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, CALL_EXPR))
    5626              :         {
    5627      2610331 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5628              :           /* In an expression of the form `a()' where cand->fn
    5629              :              which is operator() turns out to be a static member function,
    5630              :              `a' is none-the-less evaluated.  */
    5631      2610331 :           result = keep_unused_object_arg (result, obj, cand->fn);
    5632              :         }
    5633              :       else
    5634              :         {
    5635           59 :           if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    5636            0 :             obj = convert_like_with_context (cand->convs[0], obj, cand->fn,
    5637              :                                              -1, complain);
    5638              :           else
    5639              :             {
    5640           59 :               gcc_checking_assert (TYPE_P (cand->fn));
    5641           59 :               obj = convert_like (cand->convs[0], obj, complain);
    5642              :             }
    5643           59 :           obj = convert_from_reference (obj);
    5644           59 :           result = cp_build_function_call_vec (obj, args, complain);
    5645              :         }
    5646              :     }
    5647              : 
    5648      2650870 :   return result;
    5649      2650990 : }
    5650              : 
    5651              : /* Subroutine for preparing format strings suitable for the error
    5652              :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    5653              :    and SUFFIX.  */
    5654              : 
    5655              : static const char *
    5656         1474 : concat_op_error_string (bool match, const char *errmsg, const char *suffix)
    5657              : {
    5658         1474 :   return concat (match
    5659              :                  ? G_("ambiguous overload for ")
    5660              :                  : G_("no match for "),
    5661            0 :                  errmsg, suffix, nullptr);
    5662              : }
    5663              : 
    5664              : /* Called by op_error to prepare format strings suitable for the error
    5665              :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    5666              :    and a suffix (controlled by NTYPES).  */
    5667              : 
    5668              : static const char *
    5669         1453 : op_error_string (const char *errmsg, int ntypes, bool match)
    5670              : {
    5671         1453 :   const char *suffix;
    5672            0 :   if (ntypes == 3)
    5673              :     suffix = G_(" (operand types are %qT, %qT, and %qT)");
    5674            0 :   else if (ntypes == 2)
    5675              :     suffix = G_(" (operand types are %qT and %qT)");
    5676              :   else
    5677            0 :     suffix = G_(" (operand type is %qT)");
    5678            0 :   return concat_op_error_string (match, errmsg, suffix);
    5679              : }
    5680              : 
    5681              : /* Similar to op_error_string, but a special-case for binary ops that
    5682              :    use %e for the args, rather than %qT.  */
    5683              : 
    5684              : static const char *
    5685           21 : binop_error_string (const char *errmsg, bool match)
    5686              : {
    5687           21 :   return concat_op_error_string (match, errmsg,
    5688           21 :                                  G_(" (operand types are %e and %e)"));
    5689              : }
    5690              : 
    5691              : static void
    5692         1474 : op_error (const op_location_t &loc,
    5693              :           enum tree_code code, enum tree_code code2,
    5694              :           tree arg1, tree arg2, tree arg3, bool match)
    5695              : {
    5696         1474 :   bool assop = code == MODIFY_EXPR;
    5697         1474 :   const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
    5698              : 
    5699         1474 :   switch (code)
    5700              :     {
    5701            0 :     case COND_EXPR:
    5702            0 :       if (flag_diagnostics_show_caret)
    5703            0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%>"),
    5704              :                                         3, match),
    5705            0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    5706              :       else
    5707            0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%> "
    5708              :                                            "in %<%E ? %E : %E%>"), 3, match),
    5709              :                   arg1, arg2, arg3,
    5710            0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    5711              :       break;
    5712              : 
    5713            0 :     case POSTINCREMENT_EXPR:
    5714            0 :     case POSTDECREMENT_EXPR:
    5715            0 :       if (flag_diagnostics_show_caret)
    5716            0 :         error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    5717            0 :                   opname, TREE_TYPE (arg1));
    5718              :       else
    5719            0 :         error_at (loc, op_error_string (G_("%<operator%s%> in %<%E%s%>"),
    5720              :                                         1, match),
    5721            0 :                   opname, arg1, opname, TREE_TYPE (arg1));
    5722              :       break;
    5723              : 
    5724           21 :     case ARRAY_REF:
    5725           21 :       if (flag_diagnostics_show_caret)
    5726            0 :         error_at (loc, op_error_string (G_("%<operator[]%>"), 2, match),
    5727            0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2));
    5728              :       else
    5729           42 :         error_at (loc, op_error_string (G_("%<operator[]%> in %<%E[%E]%>"),
    5730              :                                         2, match),
    5731           21 :                   arg1, arg2, TREE_TYPE (arg1), TREE_TYPE (arg2));
    5732              :       break;
    5733              : 
    5734            6 :     case REALPART_EXPR:
    5735            6 :     case IMAGPART_EXPR:
    5736            6 :       if (flag_diagnostics_show_caret)
    5737            0 :         error_at (loc, op_error_string (G_("%qs"), 1, match),
    5738            0 :                   opname, TREE_TYPE (arg1));
    5739              :       else
    5740           12 :         error_at (loc, op_error_string (G_("%qs in %<%s %E%>"), 1, match),
    5741            6 :                   opname, opname, arg1, TREE_TYPE (arg1));
    5742              :       break;
    5743              : 
    5744            0 :     case CO_AWAIT_EXPR:
    5745            0 :       if (flag_diagnostics_show_caret)
    5746            0 :         error_at (loc, op_error_string (G_("%<operator %s%>"), 1, match),
    5747            0 :                   opname, TREE_TYPE (arg1));
    5748              :       else
    5749            0 :         error_at (loc, op_error_string (G_("%<operator %s%> in %<%s%E%>"),
    5750              :                                           1, match),
    5751            0 :                    opname, opname, arg1, TREE_TYPE (arg1));
    5752              :       break;
    5753              : 
    5754         1447 :     default:
    5755         1447 :       if (arg2)
    5756         1348 :         if (flag_diagnostics_show_caret)
    5757              :           {
    5758           21 :             binary_op_rich_location richloc (loc, arg1, arg2, true);
    5759           21 :             pp_markup::element_quoted_type element_0
    5760           21 :               (TREE_TYPE (arg1), highlight_colors::lhs);
    5761           21 :             pp_markup::element_quoted_type element_1
    5762           21 :               (TREE_TYPE (arg2), highlight_colors::rhs);
    5763           21 :             error_at (&richloc,
    5764              :                       binop_error_string (G_("%<operator%s%>"), match),
    5765              :                       opname, &element_0, &element_1);
    5766           21 :           }
    5767              :         else
    5768         2654 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%E %s %E%>"),
    5769              :                                           2, match),
    5770              :                     opname, arg1, opname, arg2,
    5771         1327 :                     TREE_TYPE (arg1), TREE_TYPE (arg2));
    5772              :       else
    5773           99 :         if (flag_diagnostics_show_caret)
    5774            0 :           error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    5775            0 :                     opname, TREE_TYPE (arg1));
    5776              :         else
    5777          198 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%s%E%>"),
    5778              :                                           1, match),
    5779           99 :                     opname, opname, arg1, TREE_TYPE (arg1));
    5780              :       break;
    5781              :     }
    5782         1474 : }
    5783              : 
    5784              : /* Return the implicit conversion sequence that could be used to
    5785              :    convert E1 to E2 in [expr.cond].  */
    5786              : 
    5787              : static conversion *
    5788       519398 : conditional_conversion (tree e1, tree e2, tsubst_flags_t complain)
    5789              : {
    5790       519398 :   tree t1 = non_reference (TREE_TYPE (e1));
    5791       519398 :   tree t2 = non_reference (TREE_TYPE (e2));
    5792       519398 :   conversion *conv;
    5793       519398 :   bool good_base;
    5794              : 
    5795              :   /* [expr.cond]
    5796              : 
    5797              :      If E2 is an lvalue: E1 can be converted to match E2 if E1 can be
    5798              :      implicitly converted (clause _conv_) to the type "lvalue reference to
    5799              :      T2", subject to the constraint that in the conversion the
    5800              :      reference must bind directly (_dcl.init.ref_) to an lvalue.
    5801              : 
    5802              :      If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
    5803              :      implicitly converted to the type "rvalue reference to T2", subject to
    5804              :      the constraint that the reference must bind directly.  */
    5805       519398 :   if (glvalue_p (e2))
    5806              :     {
    5807       509403 :       tree rtype = cp_build_reference_type (t2, !lvalue_p (e2));
    5808       509403 :       conv = implicit_conversion (rtype,
    5809              :                                   t1,
    5810              :                                   e1,
    5811              :                                   /*c_cast_p=*/false,
    5812              :                                   LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND
    5813              :                                   |LOOKUP_ONLYCONVERTING,
    5814              :                                   complain);
    5815       509403 :       if (conv && !conv->bad_p)
    5816              :         return conv;
    5817              :     }
    5818              : 
    5819              :   /* If E2 is a prvalue or if neither of the conversions above can be done
    5820              :      and at least one of the operands has (possibly cv-qualified) class
    5821              :      type: */
    5822       408951 :   if (!CLASS_TYPE_P (t1) && !CLASS_TYPE_P (t2))
    5823              :     return NULL;
    5824              : 
    5825              :   /* [expr.cond]
    5826              : 
    5827              :      If E1 and E2 have class type, and the underlying class types are
    5828              :      the same or one is a base class of the other: E1 can be converted
    5829              :      to match E2 if the class of T2 is the same type as, or a base
    5830              :      class of, the class of T1, and the cv-qualification of T2 is the
    5831              :      same cv-qualification as, or a greater cv-qualification than, the
    5832              :      cv-qualification of T1.  If the conversion is applied, E1 is
    5833              :      changed to an rvalue of type T2 that still refers to the original
    5834              :      source class object (or the appropriate subobject thereof).  */
    5835       161713 :   if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    5836       323533 :       && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
    5837              :     {
    5838        19655 :       if (good_base && at_least_as_qualified_p (t2, t1))
    5839              :         {
    5840         9717 :           conv = build_identity_conv (t1, e1);
    5841         9717 :           if (!same_type_p (TYPE_MAIN_VARIANT (t1),
    5842              :                             TYPE_MAIN_VARIANT (t2)))
    5843            6 :             conv = build_conv (ck_base, t2, conv);
    5844              :           else
    5845         9711 :             conv = build_conv (ck_rvalue, t2, conv);
    5846              :           return conv;
    5847              :         }
    5848              :       else
    5849              :         return NULL;
    5850              :     }
    5851              :   else
    5852              :     /* [expr.cond]
    5853              : 
    5854              :        Otherwise: E1 can be converted to match E2 if E1 can be implicitly
    5855              :        converted to the type that expression E2 would have if E2 were
    5856              :        converted to an rvalue (or the type it has, if E2 is an rvalue).  */
    5857       279200 :     return implicit_conversion (t2, t1, e1, /*c_cast_p=*/false,
    5858       279200 :                                 LOOKUP_IMPLICIT, complain);
    5859              : }
    5860              : 
    5861              : /* Implement [expr.cond].  ARG1, ARG2, and ARG3 are the three
    5862              :    arguments to the conditional expression.  */
    5863              : 
    5864              : tree
    5865      8050969 : build_conditional_expr (const op_location_t &loc,
    5866              :                         tree arg1, tree arg2, tree arg3,
    5867              :                         tsubst_flags_t complain)
    5868              : {
    5869      8050969 :   tree arg2_type;
    5870      8050969 :   tree arg3_type;
    5871      8050969 :   tree result = NULL_TREE;
    5872      8050969 :   tree result_type = NULL_TREE;
    5873      8050969 :   tree semantic_result_type = NULL_TREE;
    5874      8050969 :   bool is_glvalue = true;
    5875      8050969 :   struct z_candidate *candidates = 0;
    5876      8050969 :   struct z_candidate *cand;
    5877      8050969 :   tree orig_arg2, orig_arg3;
    5878              : 
    5879      8050969 :   auto_cond_timevar tv (TV_OVERLOAD);
    5880              : 
    5881              :   /* As a G++ extension, the second argument to the conditional can be
    5882              :      omitted.  (So that `a ? : c' is roughly equivalent to `a ? a :
    5883              :      c'.)  If the second operand is omitted, make sure it is
    5884              :      calculated only once.  */
    5885      8050969 :   if (!arg2)
    5886              :     {
    5887          386 :       if (complain & tf_error)
    5888          380 :         pedwarn (loc, OPT_Wpedantic,
    5889              :                  "ISO C++ forbids omitting the middle term of "
    5890              :                  "a %<?:%> expression");
    5891              : 
    5892          386 :       if ((complain & tf_warning) && !truth_value_p (TREE_CODE (arg1)))
    5893          338 :         warn_for_omitted_condop (loc, arg1);
    5894              : 
    5895              :       /* Make sure that lvalues remain lvalues.  See g++.oliva/ext1.C.  */
    5896          386 :       if (glvalue_p (arg1))
    5897              :         {
    5898           95 :           arg1 = cp_stabilize_reference (arg1);
    5899           95 :           arg2 = arg1 = prevent_lifetime_extension (arg1);
    5900              :         }
    5901          291 :       else if (TREE_CODE (arg1) == TARGET_EXPR)
    5902              :         /* arg1 can't be a prvalue result of the conditional
    5903              :            expression, since it needs to be materialized for the
    5904              :            conversion to bool, so treat it as an xvalue in arg2.  */
    5905            6 :         arg2 = move (TARGET_EXPR_SLOT (arg1));
    5906          285 :       else if (TREE_CODE (arg1) == EXCESS_PRECISION_EXPR)
    5907            3 :         arg2 = arg1 = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (arg1),
    5908            3 :                               cp_save_expr (TREE_OPERAND (arg1, 0)));
    5909              :       else
    5910          282 :         arg2 = arg1 = cp_save_expr (arg1);
    5911              :     }
    5912              : 
    5913              :   /* If something has already gone wrong, just pass that fact up the
    5914              :      tree.  */
    5915      8050969 :   if (error_operand_p (arg1)
    5916      8050890 :       || error_operand_p (arg2)
    5917     16101809 :       || error_operand_p (arg3))
    5918          180 :     return error_mark_node;
    5919              : 
    5920      8050789 :   conversion_obstack_sentinel cos;
    5921              : 
    5922      8050789 :   orig_arg2 = arg2;
    5923      8050789 :   orig_arg3 = arg3;
    5924              : 
    5925      8050789 :   if (gnu_vector_type_p (TREE_TYPE (arg1))
    5926      8050789 :       && (VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg1))
    5927            3 :           || VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (arg1))))
    5928              :     {
    5929         1860 :       tree arg1_type = TREE_TYPE (arg1);
    5930              : 
    5931              :       /* If arg1 is another cond_expr choosing between -1 and 0,
    5932              :          then we can use its comparison.  It may help to avoid
    5933              :          additional comparison, produce more accurate diagnostics
    5934              :          and enables folding.  */
    5935         1860 :       if (TREE_CODE (arg1) == VEC_COND_EXPR
    5936         1587 :           && integer_minus_onep (TREE_OPERAND (arg1, 1))
    5937         3447 :           && integer_zerop (TREE_OPERAND (arg1, 2)))
    5938         1587 :         arg1 = TREE_OPERAND (arg1, 0);
    5939              : 
    5940         1860 :       arg1 = force_rvalue (arg1, complain);
    5941         1860 :       arg2 = force_rvalue (arg2, complain);
    5942         1860 :       arg3 = force_rvalue (arg3, complain);
    5943              : 
    5944              :       /* force_rvalue can return error_mark on valid arguments.  */
    5945         1860 :       if (error_operand_p (arg1)
    5946         1860 :           || error_operand_p (arg2)
    5947         3720 :           || error_operand_p (arg3))
    5948            0 :         return error_mark_node;
    5949              : 
    5950         1860 :       arg2_type = TREE_TYPE (arg2);
    5951         1860 :       arg3_type = TREE_TYPE (arg3);
    5952              : 
    5953         1860 :       if (!VECTOR_TYPE_P (arg2_type)
    5954          559 :           && !VECTOR_TYPE_P (arg3_type))
    5955              :         {
    5956              :           /* Rely on the error messages of the scalar version.  */
    5957          541 :           tree scal = build_conditional_expr (loc, integer_one_node,
    5958              :                                               orig_arg2, orig_arg3, complain);
    5959          541 :           if (scal == error_mark_node)
    5960              :             return error_mark_node;
    5961          541 :           tree stype = TREE_TYPE (scal);
    5962          541 :           tree ctype = TREE_TYPE (arg1_type);
    5963          541 :           if (TYPE_SIZE (stype) != TYPE_SIZE (ctype)
    5964          541 :               || (!INTEGRAL_TYPE_P (stype) && !SCALAR_FLOAT_TYPE_P (stype)))
    5965              :             {
    5966            9 :               if (complain & tf_error)
    5967            9 :                 error_at (loc, "inferred scalar type %qT is not an integer or "
    5968              :                           "floating-point type of the same size as %qT", stype,
    5969            9 :                           COMPARISON_CLASS_P (arg1)
    5970            9 :                           ? TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg1, 0)))
    5971              :                           : ctype);
    5972            9 :               return error_mark_node;
    5973              :             }
    5974              : 
    5975          532 :           tree vtype = build_opaque_vector_type (stype,
    5976          532 :                          TYPE_VECTOR_SUBPARTS (arg1_type));
    5977              :           /* We could pass complain & tf_warning to unsafe_conversion_p,
    5978              :              but the warnings (like Wsign-conversion) have already been
    5979              :              given by the scalar build_conditional_expr_1. We still check
    5980              :              unsafe_conversion_p to forbid truncating long long -> float.  */
    5981          532 :           if (unsafe_conversion_p (stype, arg2, NULL_TREE, false))
    5982              :             {
    5983            0 :               if (complain & tf_error)
    5984            0 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5985              :                                "involves truncation", arg2_type, vtype);
    5986            0 :               return error_mark_node;
    5987              :             }
    5988          532 :           if (unsafe_conversion_p (stype, arg3, NULL_TREE, false))
    5989              :             {
    5990            3 :               if (complain & tf_error)
    5991            3 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5992              :                                "involves truncation", arg3_type, vtype);
    5993            3 :               return error_mark_node;
    5994              :             }
    5995              : 
    5996          529 :           arg2 = cp_convert (stype, arg2, complain);
    5997          529 :           arg2 = save_expr (arg2);
    5998          529 :           arg2 = build_vector_from_val (vtype, arg2);
    5999          529 :           arg2_type = vtype;
    6000          529 :           arg3 = cp_convert (stype, arg3, complain);
    6001          529 :           arg3 = save_expr (arg3);
    6002          529 :           arg3 = build_vector_from_val (vtype, arg3);
    6003          529 :           arg3_type = vtype;
    6004              :         }
    6005              : 
    6006         3678 :       if ((gnu_vector_type_p (arg2_type) && !VECTOR_TYPE_P (arg3_type))
    6007         3600 :           || (gnu_vector_type_p (arg3_type) && !VECTOR_TYPE_P (arg2_type)))
    6008              :         {
    6009           96 :           enum stv_conv convert_flag =
    6010           96 :             scalar_to_vector (loc, VEC_COND_EXPR, arg2, arg3,
    6011              :                               complain & tf_error);
    6012              : 
    6013           96 :           switch (convert_flag)
    6014              :             {
    6015            0 :               case stv_error:
    6016            0 :                 return error_mark_node;
    6017           15 :               case stv_firstarg:
    6018           15 :                 {
    6019           15 :                   arg2 = save_expr (arg2);
    6020           15 :                   arg2 = convert (TREE_TYPE (arg3_type), arg2);
    6021           15 :                   arg2 = build_vector_from_val (arg3_type, arg2);
    6022           15 :                   arg2_type = TREE_TYPE (arg2);
    6023           15 :                   break;
    6024              :                 }
    6025           72 :               case stv_secondarg:
    6026           72 :                 {
    6027           72 :                   arg3 = save_expr (arg3);
    6028           72 :                   arg3 = convert (TREE_TYPE (arg2_type), arg3);
    6029           72 :                   arg3 = build_vector_from_val (arg2_type, arg3);
    6030           72 :                   arg3_type = TREE_TYPE (arg3);
    6031           72 :                   break;
    6032              :                 }
    6033              :               default:
    6034              :                 break;
    6035              :             }
    6036              :         }
    6037              : 
    6038         1848 :       if (!gnu_vector_type_p (arg2_type)
    6039         1845 :           || !gnu_vector_type_p (arg3_type)
    6040         1839 :           || !same_type_p (arg2_type, arg3_type)
    6041         1839 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type),
    6042         1848 :                        TYPE_VECTOR_SUBPARTS (arg2_type))
    6043         3687 :           || TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type))
    6044              :         {
    6045            9 :           if (complain & tf_error)
    6046            6 :             error_at (loc,
    6047              :                       "incompatible vector types in conditional expression: "
    6048            6 :                       "%qT, %qT and %qT", TREE_TYPE (arg1),
    6049            6 :                       TREE_TYPE (orig_arg2), TREE_TYPE (orig_arg3));
    6050            9 :           return error_mark_node;
    6051              :         }
    6052              : 
    6053         1839 :       if (!COMPARISON_CLASS_P (arg1))
    6054              :         {
    6055          270 :           tree cmp_type = truth_type_for (arg1_type);
    6056          270 :           arg1 = build2 (NE_EXPR, cmp_type, arg1, build_zero_cst (arg1_type));
    6057              :         }
    6058         1839 :       return build3_loc (loc, VEC_COND_EXPR, arg2_type, arg1, arg2, arg3);
    6059              :     }
    6060              : 
    6061              :   /* [expr.cond]
    6062              : 
    6063              :      The first expression is implicitly converted to bool (clause
    6064              :      _conv_).  */
    6065      8048929 :   arg1 = perform_implicit_conversion_flags (boolean_type_node, arg1, complain,
    6066              :                                             LOOKUP_NORMAL);
    6067      8048929 :   if (error_operand_p (arg1))
    6068           25 :     return error_mark_node;
    6069              : 
    6070      8048904 :   arg2_type = unlowered_expr_type (arg2);
    6071      8048904 :   arg3_type = unlowered_expr_type (arg3);
    6072              : 
    6073      8048904 :   if ((TREE_CODE (arg2) == EXCESS_PRECISION_EXPR
    6074      8048886 :        || TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
    6075           45 :       && (TREE_CODE (arg2_type) == INTEGER_TYPE
    6076              :           || SCALAR_FLOAT_TYPE_P (arg2_type)
    6077              :           || TREE_CODE (arg2_type) == COMPLEX_TYPE)
    6078           45 :       && (TREE_CODE (arg3_type) == INTEGER_TYPE
    6079              :           || SCALAR_FLOAT_TYPE_P (arg3_type)
    6080              :           || TREE_CODE (arg3_type) == COMPLEX_TYPE))
    6081              :     {
    6082           45 :       semantic_result_type
    6083           45 :         = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6084           45 :       if (semantic_result_type == error_mark_node)
    6085              :         {
    6086            0 :           tree t1 = arg2_type;
    6087            0 :           tree t2 = arg3_type;
    6088            0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6089            0 :             t1 = TREE_TYPE (t1);
    6090            0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6091            0 :             t2 = TREE_TYPE (t2);
    6092            0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6093              :                                && SCALAR_FLOAT_TYPE_P (t2)
    6094              :                                && (extended_float_type_p (t1)
    6095              :                                    || extended_float_type_p (t2))
    6096              :                                && cp_compare_floating_point_conversion_ranks
    6097              :                                     (t1, t2) == 3);
    6098            0 :           if (complain & tf_error)
    6099            0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6100              :                            "have unordered conversion rank",
    6101              :                       arg2_type, arg3_type);
    6102            0 :           return error_mark_node;
    6103              :         }
    6104           45 :       if (TREE_CODE (arg2) == EXCESS_PRECISION_EXPR)
    6105              :         {
    6106           18 :           arg2 = TREE_OPERAND (arg2, 0);
    6107           18 :           arg2_type = TREE_TYPE (arg2);
    6108              :         }
    6109           45 :       if (TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
    6110              :         {
    6111           27 :           arg3 = TREE_OPERAND (arg3, 0);
    6112           27 :           arg3_type = TREE_TYPE (arg3);
    6113              :         }
    6114              :     }
    6115              : 
    6116              :   /* [expr.cond]
    6117              : 
    6118              :      If either the second or the third operand has type (possibly
    6119              :      cv-qualified) void, then the lvalue-to-rvalue (_conv.lval_),
    6120              :      array-to-pointer (_conv.array_), and function-to-pointer
    6121              :      (_conv.func_) standard conversions are performed on the second
    6122              :      and third operands.  */
    6123      8048904 :   if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type))
    6124              :     {
    6125              :       /* 'void' won't help in resolving an overloaded expression on the
    6126              :          other side, so require it to resolve by itself.  */
    6127       128858 :       if (arg2_type == unknown_type_node)
    6128              :         {
    6129           18 :           arg2 = resolve_nondeduced_context_or_error (arg2, complain);
    6130           18 :           arg2_type = TREE_TYPE (arg2);
    6131              :         }
    6132       128858 :       if (arg3_type == unknown_type_node)
    6133              :         {
    6134            0 :           arg3 = resolve_nondeduced_context_or_error (arg3, complain);
    6135            0 :           arg3_type = TREE_TYPE (arg3);
    6136              :         }
    6137              : 
    6138              :       /* [expr.cond]
    6139              : 
    6140              :          One of the following shall hold:
    6141              : 
    6142              :          --The second or the third operand (but not both) is a
    6143              :            throw-expression (_except.throw_); the result is of the type
    6144              :            and value category of the other.
    6145              : 
    6146              :          --Both the second and the third operands have type void; the
    6147              :            result is of type void and is a prvalue.  */
    6148       128858 :       if (TREE_CODE (arg2) == THROW_EXPR
    6149           84 :           && TREE_CODE (arg3) != THROW_EXPR)
    6150              :         {
    6151           72 :           result_type = arg3_type;
    6152           72 :           is_glvalue = glvalue_p (arg3);
    6153              :         }
    6154       128786 :       else if (TREE_CODE (arg2) != THROW_EXPR
    6155       128774 :                && TREE_CODE (arg3) == THROW_EXPR)
    6156              :         {
    6157          180 :           result_type = arg2_type;
    6158          180 :           is_glvalue = glvalue_p (arg2);
    6159              :         }
    6160       128606 :       else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
    6161              :         {
    6162       128577 :           result_type = void_type_node;
    6163       128577 :           is_glvalue = false;
    6164              :         }
    6165              :       else
    6166              :         {
    6167           29 :           if (complain & tf_error)
    6168              :             {
    6169           18 :               if (VOID_TYPE_P (arg2_type))
    6170            9 :                 error_at (cp_expr_loc_or_loc (arg3, loc),
    6171              :                           "second operand to the conditional operator "
    6172              :                           "is of type %<void%>, but the third operand is "
    6173              :                           "neither a throw-expression nor of type %<void%>");
    6174              :               else
    6175            9 :                 error_at (cp_expr_loc_or_loc (arg2, loc),
    6176              :                           "third operand to the conditional operator "
    6177              :                           "is of type %<void%>, but the second operand is "
    6178              :                           "neither a throw-expression nor of type %<void%>");
    6179              :             }
    6180           29 :           return error_mark_node;
    6181              :         }
    6182              : 
    6183       128829 :       goto valid_operands;
    6184              :     }
    6185              :   /* [expr.cond]
    6186              : 
    6187              :      Otherwise, if the second and third operand have different types,
    6188              :      and either has (possibly cv-qualified) class type, or if both are
    6189              :      glvalues of the same value category and the same type except for
    6190              :      cv-qualification, an attempt is made to convert each of those operands
    6191              :      to the type of the other.  */
    6192      7920046 :   else if (!same_type_p (arg2_type, arg3_type)
    6193      7920046 :             && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)
    6194      1607105 :                 || (same_type_ignoring_top_level_qualifiers_p (arg2_type,
    6195              :                                                                arg3_type)
    6196       450242 :                     && glvalue_p (arg2) && glvalue_p (arg3)
    6197       110166 :                     && lvalue_p (arg2) == lvalue_p (arg3))))
    6198              :     {
    6199       259699 :       conversion *conv2;
    6200       259699 :       conversion *conv3;
    6201       259699 :       bool converted = false;
    6202              : 
    6203       259699 :       conv2 = conditional_conversion (arg2, arg3, complain);
    6204       259699 :       conv3 = conditional_conversion (arg3, arg2, complain);
    6205              : 
    6206              :       /* [expr.cond]
    6207              : 
    6208              :          If both can be converted, or one can be converted but the
    6209              :          conversion is ambiguous, the program is ill-formed.  If
    6210              :          neither can be converted, the operands are left unchanged and
    6211              :          further checking is performed as described below.  If exactly
    6212              :          one conversion is possible, that conversion is applied to the
    6213              :          chosen operand and the converted operand is used in place of
    6214              :          the original operand for the remainder of this section.  */
    6215       259699 :       if ((conv2 && !conv2->bad_p
    6216        47518 :            && conv3 && !conv3->bad_p)
    6217        47496 :           || (conv2 && conv2->kind == ck_ambig)
    6218       259577 :           || (conv3 && conv3->kind == ck_ambig))
    6219              :         {
    6220          122 :           if (complain & tf_error)
    6221              :             {
    6222            6 :               error_at (loc, "operands to %<?:%> have different types "
    6223              :                         "%qT and %qT",
    6224              :                         arg2_type, arg3_type);
    6225            6 :               if (conv2 && !conv2->bad_p && conv3 && !conv3->bad_p)
    6226            3 :                 inform (loc, "  and each type can be converted to the other");
    6227            3 :               else if (conv2 && conv2->kind == ck_ambig)
    6228            3 :                 convert_like (conv2, arg2, complain);
    6229              :               else
    6230            0 :                 convert_like (conv3, arg3, complain);
    6231              :             }
    6232          122 :           result = error_mark_node;
    6233              :         }
    6234       259577 :       else if (conv2 && !conv2->bad_p)
    6235              :         {
    6236        47396 :           arg2 = convert_like (conv2, arg2, complain);
    6237        47396 :           arg2 = convert_from_reference (arg2);
    6238        47396 :           arg2_type = TREE_TYPE (arg2);
    6239              :           /* Even if CONV2 is a valid conversion, the result of the
    6240              :              conversion may be invalid.  For example, if ARG3 has type
    6241              :              "volatile X", and X does not have a copy constructor
    6242              :              accepting a "volatile X&", then even if ARG2 can be
    6243              :              converted to X, the conversion will fail.  */
    6244        47396 :           if (error_operand_p (arg2))
    6245            8 :             result = error_mark_node;
    6246              :           converted = true;
    6247              :         }
    6248       212181 :       else if (conv3 && !conv3->bad_p)
    6249              :         {
    6250       211443 :           arg3 = convert_like (conv3, arg3, complain);
    6251       211443 :           arg3 = convert_from_reference (arg3);
    6252       211443 :           arg3_type = TREE_TYPE (arg3);
    6253       211443 :           if (error_operand_p (arg3))
    6254            0 :             result = error_mark_node;
    6255              :           converted = true;
    6256              :         }
    6257              : 
    6258          130 :       if (result)
    6259              :         return result;
    6260              : 
    6261              :       /* If, after the conversion, both operands have class type,
    6262              :          treat the cv-qualification of both operands as if it were the
    6263              :          union of the cv-qualification of the operands.
    6264              : 
    6265              :          The standard is not clear about what to do in this
    6266              :          circumstance.  For example, if the first operand has type
    6267              :          "const X" and the second operand has a user-defined
    6268              :          conversion to "volatile X", what is the type of the second
    6269              :          operand after this step?  Making it be "const X" (matching
    6270              :          the first operand) seems wrong, as that discards the
    6271              :          qualification without actually performing a copy.  Leaving it
    6272              :          as "volatile X" seems wrong as that will result in the
    6273              :          conditional expression failing altogether, even though,
    6274              :          according to this step, the one operand could be converted to
    6275              :          the type of the other.  */
    6276       259569 :       if (converted
    6277       258831 :           && CLASS_TYPE_P (arg2_type)
    6278       271593 :           && cp_type_quals (arg2_type) != cp_type_quals (arg3_type))
    6279            0 :         arg2_type = arg3_type =
    6280            0 :           cp_build_qualified_type (arg2_type,
    6281            0 :                                    cp_type_quals (arg2_type)
    6282            0 :                                    | cp_type_quals (arg3_type));
    6283              :     }
    6284              : 
    6285              :   /* [expr.cond]
    6286              : 
    6287              :      If the second and third operands are glvalues of the same value
    6288              :      category and have the same type, the result is of that type and
    6289              :      value category.  */
    6290     11747959 :   if (((lvalue_p (arg2) && lvalue_p (arg3))
    6291      4735969 :        || (xvalue_p (arg2) && xvalue_p (arg3)))
    6292     11153095 :       && same_type_p (arg2_type, arg3_type))
    6293              :     {
    6294      3137429 :       result_type = arg2_type;
    6295      3137429 :       goto valid_operands;
    6296              :     }
    6297              : 
    6298              :   /* [expr.cond]
    6299              : 
    6300              :      Otherwise, the result is an rvalue.  If the second and third
    6301              :      operand do not have the same type, and either has (possibly
    6302              :      cv-qualified) class type, overload resolution is used to
    6303              :      determine the conversions (if any) to be applied to the operands
    6304              :      (_over.match.oper_, _over.built_).  */
    6305      4782487 :   is_glvalue = false;
    6306      4782487 :   if (!same_type_p (arg2_type, arg3_type)
    6307      4782487 :       && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
    6308              :     {
    6309          738 :       releasing_vec args;
    6310          738 :       conversion *conv;
    6311          738 :       bool any_viable_p;
    6312              : 
    6313              :       /* Rearrange the arguments so that add_builtin_candidate only has
    6314              :          to know about two args.  In build_builtin_candidate, the
    6315              :          arguments are unscrambled.  */
    6316          738 :       args->quick_push (arg2);
    6317          738 :       args->quick_push (arg3);
    6318          738 :       args->quick_push (arg1);
    6319          738 :       add_builtin_candidates (&candidates,
    6320              :                               COND_EXPR,
    6321              :                               NOP_EXPR,
    6322              :                               ovl_op_identifier (false, COND_EXPR),
    6323              :                               args,
    6324              :                               LOOKUP_NORMAL, complain);
    6325              : 
    6326              :       /* [expr.cond]
    6327              : 
    6328              :          If the overload resolution fails, the program is
    6329              :          ill-formed.  */
    6330          738 :       candidates = splice_viable (candidates, false, &any_viable_p);
    6331          738 :       if (!any_viable_p)
    6332              :         {
    6333          615 :           if (complain & tf_error)
    6334           22 :             error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6335              :                       arg2_type, arg3_type);
    6336          615 :           return error_mark_node;
    6337              :         }
    6338          123 :       cand = tourney (candidates, complain);
    6339          123 :       if (!cand)
    6340              :         {
    6341            0 :           if (complain & tf_error)
    6342              :             {
    6343            0 :               auto_diagnostic_group d;
    6344            0 :               op_error (loc, COND_EXPR, NOP_EXPR, arg1, arg2, arg3, false);
    6345            0 :               print_z_candidates (loc, candidates);
    6346            0 :             }
    6347            0 :           return error_mark_node;
    6348              :         }
    6349              : 
    6350              :       /* [expr.cond]
    6351              : 
    6352              :          Otherwise, the conversions thus determined are applied, and
    6353              :          the converted operands are used in place of the original
    6354              :          operands for the remainder of this section.  */
    6355          123 :       conv = cand->convs[0];
    6356          123 :       arg1 = convert_like (conv, arg1, complain);
    6357          123 :       conv = cand->convs[1];
    6358          123 :       arg2 = convert_like (conv, arg2, complain);
    6359          123 :       arg2_type = TREE_TYPE (arg2);
    6360          123 :       conv = cand->convs[2];
    6361          123 :       arg3 = convert_like (conv, arg3, complain);
    6362          123 :       arg3_type = TREE_TYPE (arg3);
    6363          738 :     }
    6364              : 
    6365              :   /* [expr.cond]
    6366              : 
    6367              :      Lvalue-to-rvalue (_conv.lval_), array-to-pointer (_conv.array_),
    6368              :      and function-to-pointer (_conv.func_) standard conversions are
    6369              :      performed on the second and third operands.
    6370              : 
    6371              :      We need to force the lvalue-to-rvalue conversion here for class types,
    6372              :      so we get TARGET_EXPRs; trying to deal with a COND_EXPR of class rvalues
    6373              :      that isn't wrapped with a TARGET_EXPR plays havoc with exception
    6374              :      regions.  */
    6375              : 
    6376      4781872 :   arg2 = force_rvalue (arg2, complain);
    6377      4781872 :   if (!CLASS_TYPE_P (arg2_type))
    6378      4689484 :     arg2_type = TREE_TYPE (arg2);
    6379              : 
    6380      4781872 :   arg3 = force_rvalue (arg3, complain);
    6381      4781872 :   if (!CLASS_TYPE_P (arg3_type))
    6382      4689484 :     arg3_type = TREE_TYPE (arg3);
    6383              : 
    6384      4781872 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6385              :     return error_mark_node;
    6386              : 
    6387              :   /* [expr.cond]
    6388              : 
    6389              :      After those conversions, one of the following shall hold:
    6390              : 
    6391              :      --The second and third operands have the same type; the result  is  of
    6392              :        that type.  */
    6393      4781824 :   if (same_type_p (arg2_type, arg3_type))
    6394              :     result_type = arg2_type;
    6395              :   /* [expr.cond]
    6396              : 
    6397              :      --The second and third operands have arithmetic or enumeration
    6398              :        type; the usual arithmetic conversions are performed to bring
    6399              :        them to a common type, and the result is of that type.  */
    6400      1063840 :   else if ((ARITHMETIC_TYPE_P (arg2_type)
    6401          106 :             || UNSCOPED_ENUM_P (arg2_type))
    6402      1040842 :            && (ARITHMETIC_TYPE_P (arg3_type)
    6403           71 :                || UNSCOPED_ENUM_P (arg3_type)))
    6404              :     {
    6405              :       /* A conditional expression between a floating-point
    6406              :          type and an integer type should convert the integer type to
    6407              :          the evaluation format of the floating-point type, with
    6408              :          possible excess precision.  */
    6409      1040688 :       tree eptype2 = arg2_type;
    6410      1040688 :       tree eptype3 = arg3_type;
    6411      1040688 :       tree eptype;
    6412          831 :       if (ANY_INTEGRAL_TYPE_P (arg2_type)
    6413      1040691 :           && (eptype = excess_precision_type (arg3_type)) != NULL_TREE)
    6414              :         {
    6415           15 :           eptype3 = eptype;
    6416           15 :           if (!semantic_result_type)
    6417           15 :             semantic_result_type
    6418           15 :               = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6419              :         }
    6420          505 :       else if (ANY_INTEGRAL_TYPE_P (arg3_type)
    6421      1040673 :                && (eptype = excess_precision_type (arg2_type)) != NULL_TREE)
    6422              :         {
    6423           27 :           eptype2 = eptype;
    6424           27 :           if (!semantic_result_type)
    6425           27 :             semantic_result_type
    6426           27 :               = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6427              :         }
    6428      1040688 :       result_type = type_after_usual_arithmetic_conversions (eptype2,
    6429              :                                                              eptype3);
    6430      1040688 :       if (result_type == error_mark_node)
    6431              :         {
    6432            0 :           tree t1 = eptype2;
    6433            0 :           tree t2 = eptype3;
    6434            0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6435            0 :             t1 = TREE_TYPE (t1);
    6436            0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6437            0 :             t2 = TREE_TYPE (t2);
    6438            0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6439              :                                && SCALAR_FLOAT_TYPE_P (t2)
    6440              :                                && (extended_float_type_p (t1)
    6441              :                                    || extended_float_type_p (t2))
    6442              :                                && cp_compare_floating_point_conversion_ranks
    6443              :                                     (t1, t2) == 3);
    6444            0 :           if (complain & tf_error)
    6445            0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6446              :                            "have unordered conversion rank",
    6447              :                       eptype2, eptype3);
    6448            0 :           return error_mark_node;
    6449              :         }
    6450      1040688 :       if (semantic_result_type == error_mark_node)
    6451              :         {
    6452            0 :           tree t1 = arg2_type;
    6453            0 :           tree t2 = arg3_type;
    6454            0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6455            0 :             t1 = TREE_TYPE (t1);
    6456            0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6457            0 :             t2 = TREE_TYPE (t2);
    6458            0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6459              :                                && SCALAR_FLOAT_TYPE_P (t2)
    6460              :                                && (extended_float_type_p (t1)
    6461              :                                    || extended_float_type_p (t2))
    6462              :                                && cp_compare_floating_point_conversion_ranks
    6463              :                                     (t1, t2) == 3);
    6464            0 :           if (complain & tf_error)
    6465            0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6466              :                            "have unordered conversion rank",
    6467              :                       arg2_type, arg3_type);
    6468            0 :           return error_mark_node;
    6469              :         }
    6470              : 
    6471      1040688 :       if (complain & tf_warning)
    6472       987116 :         do_warn_double_promotion (result_type, arg2_type, arg3_type,
    6473              :                                   "implicit conversion from %qH to %qI to "
    6474              :                                   "match other result of conditional",
    6475              :                                   loc);
    6476              : 
    6477      1040688 :       if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6478          102 :           && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
    6479              :         {
    6480           35 :           tree stripped_orig_arg2 = tree_strip_any_location_wrapper (orig_arg2);
    6481           35 :           tree stripped_orig_arg3 = tree_strip_any_location_wrapper (orig_arg3);
    6482           35 :           if (TREE_CODE (stripped_orig_arg2) == CONST_DECL
    6483           23 :               && TREE_CODE (stripped_orig_arg3) == CONST_DECL
    6484           58 :               && (DECL_CONTEXT (stripped_orig_arg2)
    6485           23 :                   == DECL_CONTEXT (stripped_orig_arg3)))
    6486              :             /* Two enumerators from the same enumeration can have different
    6487              :                types when the enumeration is still being defined.  */;
    6488           29 :           else if (complain & (cxx_dialect >= cxx26
    6489           29 :                                ? tf_warning_or_error : tf_warning))
    6490           44 :             emit_diagnostic ((cxx_dialect >= cxx26
    6491              :                               ? diagnostics::kind::pedwarn
    6492              :                               : diagnostics::kind::warning),
    6493           26 :                              loc, OPT_Wenum_compare, "enumerated mismatch "
    6494              :                              "in conditional expression: %qT vs %qT",
    6495              :                              arg2_type, arg3_type);
    6496            3 :           else if (cxx_dialect >= cxx26)
    6497            2 :             return error_mark_node;
    6498              :         }
    6499      1040653 :       else if ((((complain & (cxx_dialect >= cxx26
    6500      1040653 :                               ? tf_warning_or_error : tf_warning))
    6501       991514 :                  && warn_deprecated_enum_float_conv)
    6502        65769 :                 || (cxx_dialect >= cxx26
    6503         2161 :                     && (complain & tf_warning_or_error) == 0))
    6504       976942 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6505           40 :                     && SCALAR_FLOAT_TYPE_P (arg3_type))
    6506       976929 :                    || (SCALAR_FLOAT_TYPE_P (arg2_type)
    6507          354 :                        && TREE_CODE (arg3_type) == ENUMERAL_TYPE)))
    6508              :         {
    6509           23 :           if (cxx_dialect >= cxx26 && (complain & tf_warning_or_error) == 0)
    6510            4 :             return error_mark_node;
    6511           19 :           if (cxx_dialect >= cxx26 && TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6512            5 :             pedwarn (loc, OPT_Wdeprecated_enum_float_conversion,
    6513              :                      "conditional expression between enumeration type "
    6514              :                      "%qT and floating-point type %qT", arg2_type, arg3_type);
    6515           14 :           else if (cxx_dialect >= cxx26)
    6516            4 :             pedwarn (loc, OPT_Wdeprecated_enum_float_conversion,
    6517              :                      "conditional expression between floating-point type "
    6518              :                      "%qT and enumeration type %qT", arg2_type, arg3_type);
    6519           10 :           else if (TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6520            6 :             warning_at (loc, OPT_Wdeprecated_enum_float_conversion,
    6521              :                         "conditional expression between enumeration type "
    6522              :                         "%qT and floating-point type %qT is deprecated",
    6523              :                         arg2_type, arg3_type);
    6524              :           else
    6525            4 :             warning_at (loc, OPT_Wdeprecated_enum_float_conversion,
    6526              :                         "conditional expression between floating-point "
    6527              :                         "type %qT and enumeration type %qT is deprecated",
    6528              :                         arg2_type, arg3_type);
    6529              :         }
    6530      1030857 :       else if ((extra_warnings || warn_enum_conversion)
    6531      1040635 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6532           15 :                     && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
    6533         9766 :                    || (TREE_CODE (arg3_type) == ENUMERAL_TYPE
    6534            8 :                        && !same_type_p (arg2_type,
    6535              :                                         type_promotes_to (arg3_type)))))
    6536              :         {
    6537           17 :           if (complain & tf_warning)
    6538              :             {
    6539           12 :               enum opt_code opt = (warn_enum_conversion
    6540           17 :                                    ? OPT_Wenum_conversion
    6541              :                                    : OPT_Wextra);
    6542           17 :               warning_at (loc, opt, "enumerated and "
    6543              :                           "non-enumerated type in conditional expression");
    6544              :             }
    6545              :         }
    6546              : 
    6547      1040682 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6548      1040682 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6549              :     }
    6550              :   /* [expr.cond]
    6551              : 
    6552              :      --The second and third operands have pointer type, or one has
    6553              :        pointer type and the other is a null pointer constant; pointer
    6554              :        conversions (_conv.ptr_) and qualification conversions
    6555              :        (_conv.qual_) are performed to bring them to their composite
    6556              :        pointer type (_expr.rel_).  The result is of the composite
    6557              :        pointer type.
    6558              : 
    6559              :      --The second and third operands have pointer to member type, or
    6560              :        one has pointer to member type and the other is a null pointer
    6561              :        constant; pointer to member conversions (_conv.mem_) and
    6562              :        qualification conversions (_conv.qual_) are performed to bring
    6563              :        them to a common type, whose cv-qualification shall match the
    6564              :        cv-qualification of either the second or the third operand.
    6565              :        The result is of the common type.  */
    6566        23152 :   else if ((null_ptr_cst_p (arg2)
    6567          224 :             && TYPE_PTR_OR_PTRMEM_P (arg3_type))
    6568        22928 :            || (null_ptr_cst_p (arg3)
    6569        21964 :                && TYPE_PTR_OR_PTRMEM_P (arg2_type))
    6570          964 :            || (TYPE_PTR_P (arg2_type) && TYPE_PTR_P (arg3_type))
    6571           99 :            || (TYPE_PTRDATAMEM_P (arg2_type) && TYPE_PTRDATAMEM_P (arg3_type))
    6572        23228 :            || (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
    6573              :     {
    6574        23098 :       result_type = composite_pointer_type (loc,
    6575              :                                             arg2_type, arg3_type, arg2,
    6576              :                                             arg3, CPO_CONDITIONAL_EXPR,
    6577              :                                             complain);
    6578        23098 :       if (result_type == error_mark_node)
    6579              :         return error_mark_node;
    6580        23072 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6581        23072 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6582              :     }
    6583              : 
    6584      4781738 :   if (!result_type)
    6585              :     {
    6586           54 :       if (complain & tf_error)
    6587            3 :         error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6588              :                   arg2_type, arg3_type);
    6589           54 :       return error_mark_node;
    6590              :     }
    6591              : 
    6592      4781738 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6593              :     return error_mark_node;
    6594              : 
    6595      4781735 :  valid_operands:
    6596      8047993 :   if (processing_template_decl && is_glvalue)
    6597              :     {
    6598              :       /* Let lvalue_kind know this was a glvalue.  */
    6599       114884 :       tree arg = (result_type == arg2_type ? arg2 : arg3);
    6600       114884 :       result_type = cp_build_reference_type (result_type, xvalue_p (arg));
    6601              :     }
    6602              : 
    6603      8047993 :   result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3);
    6604              : 
    6605              :   /* If the ARG2 and ARG3 are the same and don't have side-effects,
    6606              :      warn here, because the COND_EXPR will be turned into ARG2.  */
    6607      8047993 :   if (warn_duplicated_branches
    6608          153 :       && (complain & tf_warning)
    6609      8048146 :       && (arg2 == arg3 || operand_equal_p (arg2, arg3,
    6610              :                                            OEP_ADDRESS_OF_SAME_FIELD)))
    6611           57 :     warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches,
    6612              :                 "this condition has identical branches");
    6613              : 
    6614              :   /* We can't use result_type below, as fold might have returned a
    6615              :      throw_expr.  */
    6616              : 
    6617      8047993 :   if (!is_glvalue)
    6618              :     {
    6619              :       /* Expand both sides into the same slot, hopefully the target of
    6620              :          the ?: expression.  We used to check for TARGET_EXPRs here,
    6621              :          but now we sometimes wrap them in NOP_EXPRs so the test would
    6622              :          fail.  */
    6623      4910495 :       if (CLASS_TYPE_P (TREE_TYPE (result)))
    6624              :         {
    6625        92425 :           result = get_target_expr (result, complain);
    6626              :           /* Tell gimplify_modify_expr_rhs not to strip this in
    6627              :              assignment context: we want both arms to initialize
    6628              :              the same temporary.  */
    6629        92425 :           TARGET_EXPR_NO_ELIDE (result) = true;
    6630              :         }
    6631              :       /* If this expression is an rvalue, but might be mistaken for an
    6632              :          lvalue, we must add a NON_LVALUE_EXPR.  */
    6633      4910495 :       result = rvalue (result);
    6634      4910495 :       if (semantic_result_type)
    6635           87 :         result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6636              :                          result);
    6637              :     }
    6638              :   else
    6639              :     {
    6640      3137498 :       result = force_paren_expr (result);
    6641      3137498 :       gcc_assert (semantic_result_type == NULL_TREE);
    6642              :     }
    6643              : 
    6644              :   return result;
    6645      8050969 : }
    6646              : 
    6647              : /* OPERAND is an operand to an expression.  Perform necessary steps
    6648              :    required before using it.  If OPERAND is NULL_TREE, NULL_TREE is
    6649              :    returned.  */
    6650              : 
    6651              : static tree
    6652    665970357 : prep_operand (tree operand)
    6653              : {
    6654    665970357 :   if (operand)
    6655              :     {
    6656    769935306 :       if (CLASS_TYPE_P (TREE_TYPE (operand))
    6657    412085218 :           && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
    6658              :         /* Make sure the template type is instantiated now.  */
    6659     10874633 :         instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (operand)));
    6660              :     }
    6661              : 
    6662    665970357 :   return operand;
    6663              : }
    6664              : 
    6665              : /* True iff CONV represents a conversion sequence which no other can be better
    6666              :    than under [over.ics.rank]: in other words, a "conversion" to the exact same
    6667              :    type (including binding to a reference to the same type).  This is stronger
    6668              :    than the standard's "identity" category, which also includes reference
    6669              :    bindings that add cv-qualifiers or change rvalueness.  */
    6670              : 
    6671              : static bool
    6672    233900207 : perfect_conversion_p (conversion *conv)
    6673              : {
    6674    233900207 :   if (CONVERSION_RANK (conv) != cr_identity)
    6675              :     return false;
    6676    167276708 :   if (conv->kind == ck_ref_bind)
    6677              :     {
    6678     43798516 :       if (!conv->rvaluedness_matches_p)
    6679              :         return false;
    6680     30313014 :       if (!same_type_p (TREE_TYPE (conv->type),
    6681              :                         next_conversion (conv)->type))
    6682              :         return false;
    6683              :     }
    6684    149809466 :   if (conv->check_narrowing)
    6685              :     /* Brace elision is imperfect.  */
    6686           50 :     return false;
    6687              :   return true;
    6688              : }
    6689              : 
    6690              : /* True if CAND represents a perfect match, i.e. all perfect conversions, so no
    6691              :    other candidate can be a better match.  Since the template/non-template
    6692              :    tiebreaker comes immediately after the conversion comparison in
    6693              :    [over.match.best], a perfect non-template candidate is better than all
    6694              :    templates.  */
    6695              : 
    6696              : static bool
    6697    556451018 : perfect_candidate_p (z_candidate *cand)
    6698              : {
    6699    556451018 :   if (cand->viable < 1)
    6700              :     return false;
    6701              :   /* CWG1402 makes an implicitly deleted move op worse than other
    6702              :      candidates.  */
    6703    215398136 :   if (DECL_DELETED_FN (cand->fn) && DECL_DEFAULTED_FN (cand->fn)
    6704    214376748 :       && move_fn_p (cand->fn))
    6705              :     return false;
    6706    212698553 :   int len = cand->num_convs;
    6707    362507969 :   for (int i = 0; i < len; ++i)
    6708    233900207 :     if (!perfect_conversion_p (cand->convs[i]))
    6709              :       return false;
    6710    128607762 :   if (conversion *conv = cand->second_conv)
    6711            0 :     if (!perfect_conversion_p (conv))
    6712              :       return false;
    6713              :   return true;
    6714              : }
    6715              : 
    6716              : /* True iff one of CAND's argument conversions is missing.  */
    6717              : 
    6718              : static bool
    6719     22676970 : missing_conversion_p (const z_candidate *cand)
    6720              : {
    6721     41369642 :   for (unsigned i = 0; i < cand->num_convs; ++i)
    6722              :     {
    6723     27459127 :       conversion *conv = cand->convs[i];
    6724     27459127 :       if (!conv)
    6725              :         return true;
    6726     26449946 :       if (conv->kind == ck_deferred_bad)
    6727              :         {
    6728              :           /* We don't know whether this conversion is outright invalid or
    6729              :              just bad, so conservatively assume it's missing.  */
    6730      7757274 :           gcc_checking_assert (conv->bad_p);
    6731              :           return true;
    6732              :         }
    6733              :     }
    6734              :   return false;
    6735              : }
    6736              : 
    6737              : /* Add each of the viable functions in FNS (a FUNCTION_DECL or
    6738              :    OVERLOAD) to the CANDIDATES, returning an updated list of
    6739              :    CANDIDATES.  The ARGS are the arguments provided to the call;
    6740              :    if FIRST_ARG is non-null it is the implicit object argument,
    6741              :    otherwise the first element of ARGS is used if needed.  The
    6742              :    EXPLICIT_TARGS are explicit template arguments provided.
    6743              :    TEMPLATE_ONLY is true if only template functions should be
    6744              :    considered.  CONVERSION_PATH, ACCESS_PATH, and FLAGS are as for
    6745              :    add_function_candidate.  */
    6746              : 
    6747              : static void
    6748    320077522 : add_candidates (tree fns, tree first_arg, const vec<tree, va_gc> *args,
    6749              :                 tree return_type,
    6750              :                 tree explicit_targs, bool template_only,
    6751              :                 tree conversion_path, tree access_path,
    6752              :                 int flags,
    6753              :                 struct z_candidate **candidates,
    6754              :                 tsubst_flags_t complain)
    6755              : {
    6756    320077522 :   tree ctype;
    6757    320077522 :   const vec<tree, va_gc> *non_static_args;
    6758    320077522 :   bool check_list_ctor = false;
    6759    320077522 :   bool check_converting = false;
    6760    320077522 :   unification_kind_t strict;
    6761    320077522 :   tree ne_context = NULL_TREE;
    6762    320077522 :   tree ne_fns = NULL_TREE;
    6763              : 
    6764    320077522 :   if (!fns)
    6765      3444030 :     return;
    6766              : 
    6767              :   /* Precalculate special handling of constructors and conversion ops.  */
    6768    316633492 :   tree fn = OVL_FIRST (fns);
    6769    316633492 :   if (DECL_CONV_FN_P (fn))
    6770              :     {
    6771     18627422 :       check_list_ctor = false;
    6772     18627422 :       check_converting = (flags & LOOKUP_ONLYCONVERTING) != 0;
    6773     18627422 :       if (flags & LOOKUP_NO_CONVERSION)
    6774              :         /* We're doing return_type(x).  */
    6775              :         strict = DEDUCE_CONV;
    6776              :       else
    6777              :         /* We're doing x.operator return_type().  */
    6778         1966 :         strict = DEDUCE_EXACT;
    6779              :       /* [over.match.funcs] For conversion functions, the function
    6780              :          is considered to be a member of the class of the implicit
    6781              :          object argument for the purpose of defining the type of
    6782              :          the implicit object parameter.  */
    6783     18627422 :       ctype = TYPE_MAIN_VARIANT (TREE_TYPE (first_arg));
    6784              :     }
    6785              :   else
    6786              :     {
    6787    596012140 :       if (DECL_CONSTRUCTOR_P (fn))
    6788              :         {
    6789     81081489 :           check_list_ctor = (flags & LOOKUP_LIST_ONLY) != 0;
    6790              :           /* For list-initialization we consider explicit constructors
    6791              :              and complain if one is chosen.  */
    6792     81081489 :           check_converting
    6793     81081489 :             = ((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    6794              :                == LOOKUP_ONLYCONVERTING);
    6795              :         }
    6796    298006070 :       strict = DEDUCE_CALL;
    6797    464353982 :       ctype = conversion_path ? BINFO_TYPE (conversion_path) : NULL_TREE;
    6798              :     }
    6799              : 
    6800              :   /* P2468: Check if operator== is a rewrite target with first operand
    6801              :      (*args)[0]; for now just do the lookups.  */
    6802    316633492 :   if ((flags & (LOOKUP_REWRITTEN | LOOKUP_REVERSED))
    6803    316633492 :       && DECL_OVERLOADED_OPERATOR_IS (fn, EQ_EXPR))
    6804              :     {
    6805      7203241 :       tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6806      7203241 :       if (DECL_CLASS_SCOPE_P (fn))
    6807              :         {
    6808       190132 :           ne_context = DECL_CONTEXT (fn);
    6809       190132 :           ne_fns = lookup_fnfields (TREE_TYPE ((*args)[0]), ne_name,
    6810              :                                     1, tf_none);
    6811       190132 :           if (ne_fns == error_mark_node || ne_fns == NULL_TREE)
    6812              :             ne_fns = NULL_TREE;
    6813              :           else
    6814        22030 :             ne_fns = BASELINK_FUNCTIONS (ne_fns);
    6815              :         }
    6816              :       else
    6817              :         {
    6818      7013109 :           ne_context = decl_namespace_context (fn);
    6819      7013109 :           ne_fns = lookup_qualified_name (ne_context, ne_name,
    6820              :                                           LOOK_want::NORMAL,
    6821              :                                           /*complain*/false);
    6822      7013109 :           if (ne_fns == error_mark_node
    6823      2273279 :               || !is_overloaded_fn (ne_fns))
    6824      4739830 :             ne_fns = NULL_TREE;
    6825              :         }
    6826              :     }
    6827              : 
    6828    316633492 :   if (first_arg)
    6829              :     non_static_args = args;
    6830              :   else
    6831              :     /* Delay creating the implicit this parameter until it is needed.  */
    6832    140318241 :     non_static_args = NULL;
    6833              : 
    6834    316633492 :   bool seen_strictly_viable = any_strictly_viable (*candidates);
    6835              :   /* If there's a non-template perfect match, we don't need to consider
    6836              :      templates.  So check non-templates first.  This optimization is only
    6837              :      really needed for the defaulted copy constructor of tuple and the like
    6838              :      (96926), but it seems like we might as well enable it more generally.  */
    6839    316633492 :   bool seen_perfect = false;
    6840    316633492 :   enum { templates, non_templates, either } which = either;
    6841    316633492 :   if (template_only)
    6842              :     which = templates;
    6843              :   else /*if (flags & LOOKUP_DEFAULTED)*/
    6844    277332096 :     which = non_templates;
    6845              : 
    6846              :   /* Template candidates that we'll potentially ignore if the
    6847              :      perfect candidate optimization succeeds.  */
    6848    316633492 :   z_candidate *ignored_template_cands = nullptr;
    6849              : 
    6850              :   /* During overload resolution, we first consider each function under the
    6851              :      assumption that we'll eventually find a strictly viable candidate.
    6852              :      This allows us to circumvent our defacto behavior when checking
    6853              :      argument conversions and shortcut consideration of the candidate
    6854              :      upon encountering the first bad conversion.  If this assumption
    6855              :      turns out to be false, and all candidates end up being non-strictly
    6856              :      viable, then we reconsider such candidates under the defacto behavior.
    6857              :      This trick is important for pruning member function overloads according
    6858              :      to their const/ref-qualifiers (since all 'this' conversions are at
    6859              :      worst bad) without breaking -fpermissive.  */
    6860    316633492 :   z_candidate *bad_cands = nullptr;
    6861    316633492 :   bool shortcut_bad_convs = true;
    6862              : 
    6863    148849285 :  again:
    6864   2723431495 :   for (tree fn : lkp_range (fns))
    6865              :     {
    6866   2257962269 :       if (which == templates && TREE_CODE (fn) != TEMPLATE_DECL)
    6867              :         {
    6868    328434632 :           if (template_only)
    6869       802231 :             add_ignored_candidate (candidates, fn);
    6870    328434632 :           continue;
    6871              :         }
    6872   1929527637 :       if (which == non_templates && TREE_CODE (fn) == TEMPLATE_DECL)
    6873              :         {
    6874    672181272 :           add_ignored_candidate (&ignored_template_cands, fn);
    6875    672181272 :           continue;
    6876              :         }
    6877    241671670 :       if ((check_converting && DECL_NONCONVERTING_P (fn))
    6878   1472994814 :           || (check_list_ctor && !is_list_ctor (fn)))
    6879              :         {
    6880     27435047 :           add_ignored_candidate (candidates, fn);
    6881     27435047 :           continue;
    6882              :         }
    6883              : 
    6884   1229911318 :       tree fn_first_arg = NULL_TREE;
    6885   1229911318 :       const vec<tree, va_gc> *fn_args = args;
    6886              : 
    6887   1229911318 :       if (DECL_OBJECT_MEMBER_FUNCTION_P (fn))
    6888              :         {
    6889              :           /* Figure out where the object arg comes from.  If this
    6890              :              function is a non-static member and we didn't get an
    6891              :              implicit object argument, move it out of args.  */
    6892    442214950 :           if (first_arg == NULL_TREE)
    6893              :             {
    6894      8660083 :               unsigned int ix;
    6895      8660083 :               tree arg;
    6896      8660083 :               vec<tree, va_gc> *tempvec;
    6897      8660083 :               vec_alloc (tempvec, args->length () - 1);
    6898     23448181 :               for (ix = 1; args->iterate (ix, &arg); ++ix)
    6899      6128015 :                 tempvec->quick_push (arg);
    6900      8660083 :               non_static_args = tempvec;
    6901      8660083 :               first_arg = (*args)[0];
    6902              :             }
    6903              : 
    6904              :           fn_first_arg = first_arg;
    6905              :           fn_args = non_static_args;
    6906              :         }
    6907              : 
    6908              :       /* Don't bother reversing an operator with two identical parameters.  */
    6909    787696368 :       else if (vec_safe_length (args) == 2 && (flags & LOOKUP_REVERSED))
    6910              :         {
    6911    222645128 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6912    222645128 :           if (same_type_p (TREE_VALUE (parmlist),
    6913              :                            TREE_VALUE (TREE_CHAIN (parmlist))))
    6914    105727427 :             continue;
    6915              :         }
    6916              : 
    6917              :       /* When considering reversed operator==, if there's a corresponding
    6918              :          operator!= in the same scope, it's not a rewrite target.  */
    6919   1124183891 :       if (ne_context)
    6920              :         {
    6921    157199560 :           if (TREE_CODE (ne_context) == NAMESPACE_DECL)
    6922              :             {
    6923              :               /* With argument-dependent lookup, fns can span multiple
    6924              :                  namespaces; make sure we look in the fn's namespace for a
    6925              :                  corresponding operator!=.  */
    6926    157002161 :               tree fn_ns = decl_namespace_context (fn);
    6927    157002161 :               if (fn_ns != ne_context)
    6928              :                 {
    6929      8904602 :                   ne_context = fn_ns;
    6930      8904602 :                   tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6931      8904602 :                   ne_fns = lookup_qualified_name (ne_context, ne_name,
    6932              :                                                   LOOK_want::NORMAL,
    6933              :                                                   /*complain*/false);
    6934      8904602 :                   if (ne_fns == error_mark_node
    6935      5649315 :                       || !is_overloaded_fn (ne_fns))
    6936      3255287 :                     ne_fns = NULL_TREE;
    6937              :                 }
    6938              :             }
    6939    157199560 :           bool found = false;
    6940   1705038643 :           for (lkp_iterator ne (ne_fns); !found && ne; ++ne)
    6941   1585673271 :             if (0 && !ne.using_p ()
    6942              :                 && DECL_NAMESPACE_SCOPE_P (fn)
    6943              :                 && DECL_CONTEXT (*ne) != DECL_CONTEXT (fn))
    6944              :               /* ??? This kludge excludes inline namespace members for the H
    6945              :                  test in spaceship-eq15.C, but I don't see why we would want
    6946              :                  that behavior.  Asked Core 2022-11-04.  Disabling for now.  */;
    6947   1585673271 :             else if (fns_correspond (fn, *ne))
    6948              :               {
    6949              :                 found = true;
    6950              :                 break;
    6951              :               }
    6952    157199560 :           if (found)
    6953     37834188 :             continue;
    6954              :         }
    6955              : 
    6956              :       /* Do not resolve any non-default function.  Only the default version
    6957              :          is resolvable (for the target_version attribute semantics.)  */
    6958   1086349703 :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    6959              :           && TREE_CODE (fn) == FUNCTION_DECL
    6960              :           && !is_function_default_version (fn))
    6961              :         {
    6962              :           add_ignored_candidate (candidates, fn);
    6963              :           continue;
    6964              :         }
    6965              : 
    6966   1086349703 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    6967    529898685 :         add_template_candidate (candidates,
    6968              :                                 fn,
    6969              :                                 ctype,
    6970              :                                 explicit_targs,
    6971              :                                 fn_first_arg,
    6972              :                                 fn_args,
    6973              :                                 return_type,
    6974              :                                 access_path,
    6975              :                                 conversion_path,
    6976              :                                 flags,
    6977              :                                 strict,
    6978              :                                 shortcut_bad_convs,
    6979              :                                 complain);
    6980              :       else
    6981              :         {
    6982    556451018 :           add_function_candidate (candidates,
    6983              :                                   fn,
    6984              :                                   ctype,
    6985              :                                   fn_first_arg,
    6986              :                                   fn_args,
    6987              :                                   access_path,
    6988              :                                   conversion_path,
    6989              :                                   flags,
    6990              :                                   NULL,
    6991              :                                   shortcut_bad_convs,
    6992              :                                   complain);
    6993    556451018 :           if (perfect_candidate_p (*candidates))
    6994   1086336152 :             seen_perfect = true;
    6995              :         }
    6996              : 
    6997   1086336152 :       z_candidate *cand = *candidates;
    6998   1086336152 :       if (cand->viable == 1)
    6999    300843674 :         seen_strictly_viable = true;
    7000              : 
    7001   1086336152 :       if (cand->viable == -1
    7002     22677484 :           && shortcut_bad_convs
    7003   1109013122 :           && (missing_conversion_p (cand)
    7004     13910515 :               || TREE_CODE (cand->fn) == TEMPLATE_DECL))
    7005              :         {
    7006              :           /* This candidate has been tentatively marked non-strictly viable,
    7007              :              and we didn't compute all argument conversions for it (having
    7008              :              stopped at the first bad conversion).  Move it to BAD_CANDS to
    7009              :              to fully reconsider later if we don't find any strictly viable
    7010              :              candidates.  */
    7011      8798351 :           if (complain & (tf_error | tf_conv))
    7012              :             {
    7013      8469302 :               *candidates = cand->next;
    7014      8469302 :               cand->next = bad_cands;
    7015      8469302 :               bad_cands = cand;
    7016              :             }
    7017              :           else
    7018              :             /* But if we're in a SFINAE context, just mark this candidate as
    7019              :                unviable outright and avoid potentially reconsidering it.
    7020              :                This is safe to do because in a SFINAE context, performing a bad
    7021              :                conversion is always an error (even with -fpermissive), so a
    7022              :                non-strictly viable candidate is effectively unviable anyway.  */
    7023       329049 :             cand->viable = 0;
    7024              :         }
    7025              :     }
    7026    465469226 :   if (which == non_templates && !seen_perfect)
    7027              :     {
    7028    148730535 :       which = templates;
    7029    148730535 :       ignored_template_cands = nullptr;
    7030    148730535 :       goto again;
    7031              :     }
    7032    316738691 :   else if (which == templates
    7033    316738691 :            && !seen_strictly_viable
    7034              :            && shortcut_bad_convs
    7035     59393678 :            && bad_cands)
    7036              :     {
    7037              :       /* None of the candidates are strictly viable, so consider again those
    7038              :          functions in BAD_CANDS, this time without shortcutting bad conversions
    7039              :          so that all their argument conversions are computed.  */
    7040       262420 :       which = either;
    7041              :       fns = NULL_TREE;
    7042       262420 :       for (z_candidate *cand = bad_cands; cand; cand = cand->next)
    7043              :         {
    7044       143670 :           tree fn = cand->fn;
    7045       143670 :           if (tree ti = cand->template_decl)
    7046          120 :             fn = TI_TEMPLATE (ti);
    7047       143670 :           fns = ovl_make (fn, fns);
    7048              :         }
    7049       118750 :       shortcut_bad_convs = false;
    7050       118750 :       bad_cands = nullptr;
    7051       118750 :       goto again;
    7052              :     }
    7053              : 
    7054    316619941 :   if (complain & tf_error)
    7055              :     {
    7056              :       /* Remember any omitted candidates; we may want to print all candidates
    7057              :          as part of overload resolution failure diagnostics.  */
    7058    483431496 :       for (z_candidate *omitted_cands : { ignored_template_cands, bad_cands })
    7059              :         {
    7060    322287664 :           z_candidate **omitted_cands_tail = &omitted_cands;
    7061    370710459 :           while (*omitted_cands_tail)
    7062     48422795 :             omitted_cands_tail = &(*omitted_cands_tail)->next;
    7063    322287664 :           *omitted_cands_tail = *candidates;
    7064    322287664 :           *candidates = omitted_cands;
    7065              :         }
    7066              :     }
    7067              : }
    7068              : 
    7069              : /* Returns 1 if P0145R2 says that the LHS of operator CODE is evaluated first,
    7070              :    -1 if the RHS is evaluated first, or 0 if the order is unspecified.  */
    7071              : 
    7072              : static int
    7073     16642474 : op_is_ordered (tree_code code)
    7074              : {
    7075     16641815 :   switch (code)
    7076              :     {
    7077              :       // 5. b @= a
    7078      3735294 :     case MODIFY_EXPR:
    7079      3735294 :       return (flag_strong_eval_order > 1 ? -1 : 0);
    7080              : 
    7081              :       // 6. a[b]
    7082       432506 :     case ARRAY_REF:
    7083       431847 :       return (flag_strong_eval_order > 1 ? 1 : 0);
    7084              : 
    7085              :       // 1. a.b
    7086              :       // Not overloadable (yet).
    7087              :       // 2. a->b
    7088              :       // Only one argument.
    7089              :       // 3. a->*b
    7090        79090 :     case MEMBER_REF:
    7091              :       // 7. a << b
    7092        79090 :     case LSHIFT_EXPR:
    7093              :       // 8. a >> b
    7094        79090 :     case RSHIFT_EXPR:
    7095              :       // a && b
    7096              :       // Predates P0145R3.
    7097        79090 :     case TRUTH_ANDIF_EXPR:
    7098              :       // a || b
    7099              :       // Predates P0145R3.
    7100        79090 :     case TRUTH_ORIF_EXPR:
    7101              :       // a , b
    7102              :       // Predates P0145R3.
    7103        79090 :     case COMPOUND_EXPR:
    7104        79090 :       return (flag_strong_eval_order ? 1 : 0);
    7105              : 
    7106              :     default:
    7107              :       return 0;
    7108              :     }
    7109              : }
    7110              : 
    7111              : /* Subroutine of build_new_op: Add to CANDIDATES all candidates for the
    7112              :    operator indicated by CODE/CODE2.  This function calls itself recursively to
    7113              :    handle C++20 rewritten comparison operator candidates.  Returns NULL_TREE
    7114              :    upon success, and error_mark_node if something went wrong that prevented
    7115              :    us from performing overload resolution (e.g. ambiguous member name lookup).
    7116              : 
    7117              :    LOOKUPS, if non-NULL, is the set of pertinent namespace-scope operator
    7118              :    overloads to consider.  This parameter is used when instantiating a
    7119              :    dependent operator expression and has the same structure as
    7120              :    DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS.  */
    7121              : 
    7122              : static tree
    7123     35405680 : add_operator_candidates (z_candidate **candidates,
    7124              :                          tree_code code, tree_code code2,
    7125              :                          vec<tree, va_gc> *arglist, tree lookups,
    7126              :                          int flags, tsubst_flags_t complain)
    7127              : {
    7128     35405680 :   z_candidate *start_candidates = *candidates;
    7129     35405680 :   bool ismodop = code2 != ERROR_MARK;
    7130     35405680 :   tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    7131              : 
    7132              :   /* LOOKUP_REWRITTEN is set when we're looking for the == or <=> operator to
    7133              :      rewrite from, and also when we're looking for the e.g. < operator to use
    7134              :      on the result of <=>.  In the latter case, we don't want the flag set in
    7135              :      the candidate, we just want to suppress looking for rewrites.  */
    7136     35405680 :   bool rewritten = (flags & LOOKUP_REWRITTEN);
    7137     35405680 :   if (rewritten && code != EQ_EXPR && code != SPACESHIP_EXPR)
    7138       952200 :     flags &= ~LOOKUP_REWRITTEN;
    7139              : 
    7140     32844692 :   bool memonly = false;
    7141     32844692 :   switch (code)
    7142              :     {
    7143              :       /* =, ->, [], () must be non-static member functions.  */
    7144      6571969 :     case MODIFY_EXPR:
    7145      6571969 :       if (code2 != NOP_EXPR)
    7146              :         break;
    7147              :       /* FALLTHRU */
    7148              :     case COMPONENT_REF:
    7149              :     case ARRAY_REF:
    7150              :       memonly = true;
    7151              :       break;
    7152              : 
    7153              :     default:
    7154              :       break;
    7155              :     }
    7156              : 
    7157              :   /* Add namespace-scope operators to the list of functions to
    7158              :      consider.  */
    7159              :   if (!memonly)
    7160              :     {
    7161     31109665 :       tree fns;
    7162     31109665 :       if (!lookups)
    7163     23039399 :         fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    7164              :       /* If LOOKUPS is non-NULL, then we're instantiating a dependent operator
    7165              :          expression, and LOOKUPS is the result of stage 1 name lookup.  */
    7166      8070266 :       else if (tree found = purpose_member (fnname, lookups))
    7167      1757428 :         fns = TREE_VALUE (found);
    7168              :       else
    7169              :         fns = NULL_TREE;
    7170     31109665 :       fns = lookup_arg_dependent (fnname, fns, arglist);
    7171     31109665 :       add_candidates (fns, NULL_TREE, arglist, NULL_TREE,
    7172              :                       NULL_TREE, false, NULL_TREE, NULL_TREE,
    7173              :                       flags, candidates, complain);
    7174              :     }
    7175              : 
    7176              :   /* Add class-member operators to the candidate set.  */
    7177     35405647 :   tree arg1_type = TREE_TYPE ((*arglist)[0]);
    7178     35405647 :   unsigned nargs = arglist->length () > 1 ? 2 : 1;
    7179     30346072 :   tree arg2_type = nargs > 1 ? TREE_TYPE ((*arglist)[1]) : NULL_TREE;
    7180     35405647 :   if (CLASS_TYPE_P (arg1_type))
    7181              :     {
    7182     20358470 :       tree fns = lookup_fnfields (arg1_type, fnname, 1, complain);
    7183     20358470 :       if (fns == error_mark_node)
    7184              :         return error_mark_node;
    7185     20358458 :       if (fns)
    7186              :         {
    7187      9091955 :           if (code == ARRAY_REF)
    7188              :             {
    7189       431872 :               vec<tree,va_gc> *restlist = make_tree_vector ();
    7190       863744 :               for (unsigned i = 1; i < nargs; ++i)
    7191       431872 :                 vec_safe_push (restlist, (*arglist)[i]);
    7192       431872 :               z_candidate *save_cand = *candidates;
    7193       863744 :               add_candidates (BASELINK_FUNCTIONS (fns),
    7194       431872 :                               (*arglist)[0], restlist, NULL_TREE,
    7195              :                               NULL_TREE, false,
    7196       431872 :                               BASELINK_BINFO (fns),
    7197       431872 :                               BASELINK_ACCESS_BINFO (fns),
    7198              :                               flags, candidates, complain);
    7199              :               /* Release the vec if we didn't add a candidate that uses it.  */
    7200       432470 :               for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7201       432470 :                 if (c->args == restlist)
    7202              :                   {
    7203       431872 :                     restlist = NULL;
    7204       431872 :                     break;
    7205              :                   }
    7206       431872 :               release_tree_vector (restlist);
    7207              :             }
    7208              :           else
    7209      8660083 :             add_candidates (BASELINK_FUNCTIONS (fns),
    7210              :                             NULL_TREE, arglist, NULL_TREE,
    7211              :                             NULL_TREE, false,
    7212      8660083 :                             BASELINK_BINFO (fns),
    7213      8660083 :                             BASELINK_ACCESS_BINFO (fns),
    7214              :                             flags, candidates, complain);
    7215              :         }
    7216              :     }
    7217              :   /* Per [over.match.oper]3.2, if no operand has a class type, then
    7218              :      only non-member functions that have type T1 or reference to
    7219              :      cv-qualified-opt T1 for the first argument, if the first argument
    7220              :      has an enumeration type, or T2 or reference to cv-qualified-opt
    7221              :      T2 for the second argument, if the second argument has an
    7222              :      enumeration type.  Filter out those that don't match.  */
    7223     15047177 :   else if (! arg2_type || ! CLASS_TYPE_P (arg2_type))
    7224              :     {
    7225              :       struct z_candidate **candp, **next;
    7226              : 
    7227    255368193 :       for (candp = candidates; *candp != start_candidates; candp = next)
    7228              :         {
    7229    240921336 :           unsigned i;
    7230    240921336 :           z_candidate *cand = *candp;
    7231    240921336 :           next = &cand->next;
    7232              : 
    7233    240921336 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    7234              : 
    7235    711576582 :           for (i = 0; i < nargs; ++i)
    7236              :             {
    7237    475843513 :               tree parmtype = TREE_VALUE (parmlist);
    7238    475843513 :               tree argtype = unlowered_expr_type ((*arglist)[i]);
    7239              : 
    7240    475843513 :               if (TYPE_REF_P (parmtype))
    7241    377771879 :                 parmtype = TREE_TYPE (parmtype);
    7242    475843513 :               if (TREE_CODE (argtype) == ENUMERAL_TYPE
    7243    930567300 :                   && (same_type_ignoring_top_level_qualifiers_p
    7244    454723787 :                       (argtype, parmtype)))
    7245              :                 break;
    7246              : 
    7247    470655246 :               parmlist = TREE_CHAIN (parmlist);
    7248              :             }
    7249              : 
    7250              :           /* No argument has an appropriate type, so remove this
    7251              :              candidate function from the list.  */
    7252    240921336 :           if (i == nargs)
    7253              :             {
    7254    235733069 :               *candp = cand->next;
    7255    235733069 :               next = candp;
    7256              :             }
    7257              :         }
    7258              :     }
    7259              : 
    7260     35405635 :   if (!rewritten)
    7261              :     {
    7262              :       /* The standard says to rewrite built-in candidates, too,
    7263              :          but there's no point.  */
    7264     24843239 :       add_builtin_candidates (candidates, code, code2, fnname, arglist,
    7265              :                               flags, complain);
    7266              : 
    7267              :       /* Maybe add C++20 rewritten comparison candidates.  */
    7268     24843239 :       tree_code rewrite_code = ERROR_MARK;
    7269     24843239 :       if (cxx_dialect >= cxx20
    7270     24541051 :           && nargs == 2
    7271     44447124 :           && (OVERLOAD_TYPE_P (arg1_type) || OVERLOAD_TYPE_P (arg2_type)))
    7272     19596265 :         switch (code)
    7273              :           {
    7274      1343764 :           case LT_EXPR:
    7275      1343764 :           case LE_EXPR:
    7276      1343764 :           case GT_EXPR:
    7277      1343764 :           case GE_EXPR:
    7278      1343764 :           case SPACESHIP_EXPR:
    7279      1343764 :             rewrite_code = SPACESHIP_EXPR;
    7280      1343764 :             break;
    7281              : 
    7282              :           case NE_EXPR:
    7283              :           case EQ_EXPR:
    7284              :             rewrite_code = EQ_EXPR;
    7285              :             break;
    7286              : 
    7287              :           default:;
    7288              :           }
    7289              : 
    7290      1343764 :       if (rewrite_code)
    7291              :         {
    7292      6481814 :           tree r;
    7293      6481814 :           flags |= LOOKUP_REWRITTEN;
    7294      6481814 :           if (rewrite_code != code)
    7295              :             {
    7296              :               /* Add rewritten candidates in same order.  */
    7297      3128080 :               r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7298              :                                            arglist, lookups, flags, complain);
    7299      3128080 :               if (r == error_mark_node)
    7300              :                 return error_mark_node;
    7301              :             }
    7302              : 
    7303      6481808 :           z_candidate *save_cand = *candidates;
    7304              : 
    7305              :           /* Add rewritten candidates in reverse order.  */
    7306      6481808 :           flags |= LOOKUP_REVERSED;
    7307      6481808 :           vec<tree,va_gc> *revlist = make_tree_vector ();
    7308      6481808 :           revlist->quick_push ((*arglist)[1]);
    7309      6481808 :           revlist->quick_push ((*arglist)[0]);
    7310      6481808 :           r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7311              :                                        revlist, lookups, flags, complain);
    7312      6481808 :           if (r == error_mark_node)
    7313              :             return error_mark_node;
    7314              : 
    7315              :           /* Release the vec if we didn't add a candidate that uses it.  */
    7316      6644249 :           for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7317      2996862 :             if (c->args == revlist)
    7318              :               {
    7319              :                 revlist = NULL;
    7320              :                 break;
    7321              :               }
    7322      6481808 :           release_tree_vector (revlist);
    7323              :         }
    7324              :     }
    7325              : 
    7326              :   return NULL_TREE;
    7327              : }
    7328              : 
    7329              : tree
    7330    221116456 : build_new_op (const op_location_t &loc, enum tree_code code, int flags,
    7331              :               tree arg1, tree arg2, tree arg3, tree lookups,
    7332              :               tree *overload, tsubst_flags_t complain)
    7333              : {
    7334    221116456 :   struct z_candidate *candidates = 0, *cand;
    7335    221116456 :   releasing_vec arglist;
    7336    221116456 :   tree result = NULL_TREE;
    7337    221116456 :   bool result_valid_p = false;
    7338    221116456 :   enum tree_code code2 = ERROR_MARK;
    7339    221116456 :   enum tree_code code_orig_arg1 = ERROR_MARK;
    7340    221116456 :   enum tree_code code_orig_arg2 = ERROR_MARK;
    7341    221116456 :   bool strict_p;
    7342    221116456 :   bool any_viable_p;
    7343              : 
    7344    221116456 :   auto_cond_timevar tv (TV_OVERLOAD);
    7345              : 
    7346    221116456 :   if (error_operand_p (arg1)
    7347    221112281 :       || error_operand_p (arg2)
    7348    442222677 :       || error_operand_p (arg3))
    7349        10235 :     return error_mark_node;
    7350              : 
    7351    221106221 :   conversion_obstack_sentinel cos;
    7352              : 
    7353    221106221 :   bool ismodop = code == MODIFY_EXPR;
    7354    221106221 :   if (ismodop)
    7355              :     {
    7356     11419415 :       code2 = TREE_CODE (arg3);
    7357     11419415 :       arg3 = NULL_TREE;
    7358              :     }
    7359              : 
    7360    221106221 :   tree arg1_type = unlowered_expr_type (arg1);
    7361    221106221 :   tree arg2_type = arg2 ? unlowered_expr_type (arg2) : NULL_TREE;
    7362              : 
    7363    221106221 :   arg1 = prep_operand (arg1);
    7364              : 
    7365    221106221 :   switch (code)
    7366              :     {
    7367            0 :     case NEW_EXPR:
    7368            0 :     case VEC_NEW_EXPR:
    7369            0 :     case VEC_DELETE_EXPR:
    7370            0 :     case DELETE_EXPR:
    7371              :       /* Use build_operator_new_call and build_op_delete_call instead.  */
    7372            0 :       gcc_unreachable ();
    7373              : 
    7374            0 :     case CALL_EXPR:
    7375              :       /* Use build_op_call instead.  */
    7376            0 :       gcc_unreachable ();
    7377              : 
    7378     18619165 :     case TRUTH_ORIF_EXPR:
    7379     18619165 :     case TRUTH_ANDIF_EXPR:
    7380     18619165 :     case TRUTH_AND_EXPR:
    7381     18619165 :     case TRUTH_OR_EXPR:
    7382              :       /* These are saved for the sake of warn_logical_operator.  */
    7383     18619165 :       code_orig_arg1 = TREE_CODE (arg1);
    7384     18619165 :       code_orig_arg2 = TREE_CODE (arg2);
    7385     18619165 :       break;
    7386     51890136 :     case GT_EXPR:
    7387     51890136 :     case LT_EXPR:
    7388     51890136 :     case GE_EXPR:
    7389     51890136 :     case LE_EXPR:
    7390     51890136 :     case EQ_EXPR:
    7391     51890136 :     case NE_EXPR:
    7392              :       /* These are saved for the sake of maybe_warn_bool_compare.  */
    7393     51890136 :       code_orig_arg1 = TREE_CODE (arg1_type);
    7394     51890136 :       code_orig_arg2 = TREE_CODE (arg2_type);
    7395     51890136 :       break;
    7396              : 
    7397              :     default:
    7398              :       break;
    7399              :     }
    7400              : 
    7401    221106221 :   arg2 = prep_operand (arg2);
    7402    221106221 :   arg3 = prep_operand (arg3);
    7403              : 
    7404    221106221 :   if (code == COND_EXPR)
    7405              :     /* Use build_conditional_expr instead.  */
    7406            0 :     gcc_unreachable ();
    7407    221106221 :   else if (! OVERLOAD_TYPE_P (arg1_type)
    7408    416855807 :            && (! arg2 || ! OVERLOAD_TYPE_P (arg2_type)))
    7409    195310429 :     goto builtin;
    7410              : 
    7411     25795792 :   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    7412              :     {
    7413       320059 :       arg2 = integer_zero_node;
    7414       320059 :       arg2_type = integer_type_node;
    7415              :     }
    7416              : 
    7417     25795792 :   arglist->quick_push (arg1);
    7418     25795792 :   if (arg2 != NULL_TREE)
    7419     20736217 :     arglist->quick_push (arg2);
    7420     25795792 :   if (arg3 != NULL_TREE)
    7421            0 :     arglist->quick_push (arg3);
    7422              : 
    7423     25795792 :   result = add_operator_candidates (&candidates, code, code2, arglist,
    7424              :                                     lookups, flags, complain);
    7425     25795759 :   if (result == error_mark_node)
    7426              :     return error_mark_node;
    7427              : 
    7428     25795747 :   switch (code)
    7429              :     {
    7430              :     case COMPOUND_EXPR:
    7431              :     case ADDR_EXPR:
    7432              :       /* For these, the built-in candidates set is empty
    7433              :          [over.match.oper]/3.  We don't want non-strict matches
    7434              :          because exact matches are always possible with built-in
    7435              :          operators.  The built-in candidate set for COMPONENT_REF
    7436              :          would be empty too, but since there are no such built-in
    7437              :          operators, we accept non-strict matches for them.  */
    7438              :       strict_p = true;
    7439              :       break;
    7440              : 
    7441     23873033 :     default:
    7442     23873033 :       strict_p = false;
    7443     23873033 :       break;
    7444              :     }
    7445              : 
    7446     25795747 :   candidates = splice_viable (candidates, strict_p, &any_viable_p);
    7447     25795747 :   if (!any_viable_p)
    7448              :     {
    7449      1973906 :       switch (code)
    7450              :         {
    7451          357 :         case POSTINCREMENT_EXPR:
    7452          357 :         case POSTDECREMENT_EXPR:
    7453              :           /* Don't try anything fancy if we're not allowed to produce
    7454              :              errors.  */
    7455          357 :           if (!(complain & tf_error))
    7456              :             return error_mark_node;
    7457              : 
    7458              :           /* Look for an `operator++ (int)'. Pre-1985 C++ didn't
    7459              :              distinguish between prefix and postfix ++ and
    7460              :              operator++() was used for both, so we allow this with
    7461              :              -fpermissive.  */
    7462              :           else
    7463              :             {
    7464           42 :               tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    7465           30 :               const char *msg = (flag_permissive)
    7466           42 :                 ? G_("no %<%D(int)%> declared for postfix %qs,"
    7467              :                      " trying prefix operator instead")
    7468              :                 : G_("no %<%D(int)%> declared for postfix %qs");
    7469           42 :               permerror (loc, msg, fnname, OVL_OP_INFO (false, code)->name);
    7470              :             }
    7471              : 
    7472           42 :           if (!flag_permissive)
    7473           30 :             return error_mark_node;
    7474              : 
    7475           12 :           if (code == POSTINCREMENT_EXPR)
    7476              :             code = PREINCREMENT_EXPR;
    7477              :           else
    7478            0 :             code = PREDECREMENT_EXPR;
    7479           12 :           result = build_new_op (loc, code, flags, arg1, NULL_TREE,
    7480              :                                  NULL_TREE, lookups, overload, complain);
    7481           12 :           break;
    7482              : 
    7483              :           /* The caller will deal with these.  */
    7484              :         case ADDR_EXPR:
    7485              :         case COMPOUND_EXPR:
    7486              :         case COMPONENT_REF:
    7487              :         case CO_AWAIT_EXPR:
    7488              :           result = NULL_TREE;
    7489              :           result_valid_p = true;
    7490              :           break;
    7491              : 
    7492        48064 :         default:
    7493        48064 :           if (complain & tf_error)
    7494              :             {
    7495              :                 /* If one of the arguments of the operator represents
    7496              :                    an invalid use of member function pointer, try to report
    7497              :                    a meaningful error ...  */
    7498         1354 :               if (invalid_nonstatic_memfn_p (loc, arg1, tf_error)
    7499         1351 :                     || invalid_nonstatic_memfn_p (loc, arg2, tf_error)
    7500         2699 :                     || invalid_nonstatic_memfn_p (loc, arg3, tf_error))
    7501              :                   /* We displayed the error message.  */;
    7502              :                 else
    7503              :                   {
    7504              :                     /* ... Otherwise, report the more generic
    7505              :                        "no matching operator found" error */
    7506         1345 :                     auto_diagnostic_group d;
    7507         1345 :                     op_error (loc, code, code2, arg1, arg2, arg3, false);
    7508         1345 :                     print_z_candidates (loc, candidates);
    7509         1345 :                   }
    7510              :             }
    7511        48064 :           result = error_mark_node;
    7512        48064 :           break;
    7513              :         }
    7514              :     }
    7515              :   else
    7516              :     {
    7517     23821841 :       cand = tourney (candidates, complain);
    7518     23821841 :       if (cand == 0)
    7519              :         {
    7520          184 :           if (complain & tf_error)
    7521              :             {
    7522          129 :               auto_diagnostic_group d;
    7523          129 :               op_error (loc, code, code2, arg1, arg2, arg3, true);
    7524          129 :               print_z_candidates (loc, candidates);
    7525          129 :             }
    7526          184 :           result = error_mark_node;
    7527          184 :           if (overload)
    7528          165 :             *overload = error_mark_node;
    7529              :         }
    7530     23821657 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    7531              :         {
    7532     19469305 :           if (overload)
    7533              :             {
    7534     14915545 :               if (cand->rewritten ())
    7535              :                 /* build_min_non_dep_op_overload needs to know whether the
    7536              :                    candidate is rewritten/reversed.  */
    7537      1860055 :                 *overload = build_tree_list (build_int_cst (integer_type_node,
    7538      1860055 :                                                             cand->flags),
    7539              :                                              cand->fn);
    7540              :               else
    7541     13055490 :                 *overload = cand->fn;
    7542              :             }
    7543              : 
    7544     19469305 :           if (resolve_args (arglist, complain) == NULL)
    7545            6 :             result = error_mark_node;
    7546              :           else
    7547              :             {
    7548     19469299 :               tsubst_flags_t ocomplain = complain;
    7549     19469299 :               if (cand->rewritten ())
    7550              :                 /* We'll wrap this call in another one.  */
    7551      1860661 :                 ocomplain &= ~tf_decltype;
    7552     19469299 :               if (cand->reversed ())
    7553              :                 {
    7554              :                   /* We swapped these in add_candidate, swap them back now.  */
    7555        21429 :                   std::swap (cand->convs[0], cand->convs[1]);
    7556        21429 :                   if (cand->fn == current_function_decl)
    7557            1 :                     warning_at (loc, 0, "in C++20 this comparison calls the "
    7558              :                                 "current function recursively with reversed "
    7559              :                                 "arguments");
    7560              :                 }
    7561     19469299 :               result = build_over_call (cand, LOOKUP_NORMAL, ocomplain);
    7562              :             }
    7563              : 
    7564     36114183 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7565              :             /* There won't be a CALL_EXPR.  */;
    7566     16644464 :           else if (result && result != error_mark_node)
    7567              :             {
    7568     16641815 :               tree call = extract_call_expr (result);
    7569     16641815 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7570              : 
    7571              :               /* Specify evaluation order as per P0145R2.  */
    7572     16641815 :               CALL_EXPR_ORDERED_ARGS (call) = false;
    7573     16641815 :               switch (op_is_ordered (code))
    7574              :                 {
    7575      3707155 :                 case -1:
    7576      3707155 :                   CALL_EXPR_REVERSE_ARGS (call) = true;
    7577      3707155 :                   break;
    7578              : 
    7579       509907 :                 case 1:
    7580       509907 :                   CALL_EXPR_ORDERED_ARGS (call) = true;
    7581       509907 :                   break;
    7582              : 
    7583              :                 default:
    7584              :                   break;
    7585              :                 }
    7586              :             }
    7587              : 
    7588              :           /* If this was a C++20 rewritten comparison, adjust the result.  */
    7589     19469302 :           if (cand->rewritten ())
    7590              :             {
    7591      1860661 :               switch (code)
    7592              :                 {
    7593         9946 :                 case EQ_EXPR:
    7594         9946 :                   gcc_checking_assert (cand->reversed ());
    7595       907098 :                   gcc_fallthrough ();
    7596       907098 :                 case NE_EXPR:
    7597       907098 :                   if (result == error_mark_node)
    7598              :                     ;
    7599              :                   /* If a rewritten operator== candidate is selected by
    7600              :                      overload resolution for an operator @, its return type
    7601              :                      shall be cv bool.... */
    7602       907096 :                   else if (TREE_CODE (TREE_TYPE (result)) != BOOLEAN_TYPE)
    7603              :                     {
    7604           44 :                       if (complain & tf_error)
    7605              :                         {
    7606            6 :                           auto_diagnostic_group d;
    7607            6 :                           error_at (loc, "return type of %qD is not %qs",
    7608              :                                     cand->fn, "bool");
    7609            6 :                           inform (loc, "used as rewritten candidate for "
    7610              :                                   "comparison of %qT and %qT",
    7611              :                                   arg1_type, arg2_type);
    7612            6 :                         }
    7613           44 :                       result = error_mark_node;
    7614              :                     }
    7615       907052 :                   else if (code == NE_EXPR)
    7616              :                     /* !(y == x) or !(x == y)  */
    7617       897127 :                     result = build1_loc (loc, TRUTH_NOT_EXPR,
    7618              :                                          boolean_type_node, result);
    7619              :                   break;
    7620              : 
    7621              :                   /* If a rewritten operator<=> candidate is selected by
    7622              :                      overload resolution for an operator @, x @ y is
    7623              :                      interpreted as 0 @ (y <=> x) if the selected candidate is
    7624              :                      a synthesized candidate with reversed order of parameters,
    7625              :                      or (x <=> y) @ 0 otherwise, using the selected rewritten
    7626              :                      operator<=> candidate.  */
    7627          637 :                 case SPACESHIP_EXPR:
    7628          637 :                   if (!cand->reversed ())
    7629              :                     /* We're in the build_new_op call below for an outer
    7630              :                        reversed call; we don't need to do anything more.  */
    7631              :                     break;
    7632       953249 :                   gcc_fallthrough ();
    7633       953249 :                 case LT_EXPR:
    7634       953249 :                 case LE_EXPR:
    7635       953249 :                 case GT_EXPR:
    7636       953249 :                 case GE_EXPR:
    7637       953249 :                   {
    7638       953249 :                     tree lhs = result;
    7639       953249 :                     tree rhs = integer_zero_node;
    7640       953249 :                     if (cand->reversed ())
    7641         2164 :                       std::swap (lhs, rhs);
    7642       953249 :                     warning_sentinel ws (warn_zero_as_null_pointer_constant);
    7643       953249 :                     result = build_new_op (loc, code,
    7644              :                                            LOOKUP_NORMAL|LOOKUP_REWRITTEN,
    7645              :                                            lhs, rhs, NULL_TREE, lookups,
    7646              :                                            NULL, complain);
    7647       953249 :                   }
    7648       953249 :                   break;
    7649              : 
    7650            0 :                 default:
    7651            0 :                   gcc_unreachable ();
    7652              :                 }
    7653              :             }
    7654              : 
    7655              :           /* In an expression of the form `a[]' where cand->fn
    7656              :              which is operator[] turns out to be a static member function,
    7657              :              `a' is none-the-less evaluated.  */
    7658     19469302 :           if (code == ARRAY_REF)
    7659       431847 :             result = keep_unused_object_arg (result, arg1, cand->fn);
    7660              :         }
    7661              :       else
    7662              :         {
    7663              :           /* Give any warnings we noticed during overload resolution.  */
    7664      4352352 :           if (cand->warnings && (complain & tf_warning))
    7665              :             {
    7666              :               struct candidate_warning *w;
    7667            0 :               for (w = cand->warnings; w; w = w->next)
    7668            0 :                 joust (cand, w->loser, 1, complain);
    7669              :             }
    7670              : 
    7671              :           /* Check for comparison of different enum types.  */
    7672      4352352 :           switch (code)
    7673              :             {
    7674      3451493 :             case GT_EXPR:
    7675      3451493 :             case LT_EXPR:
    7676      3451493 :             case GE_EXPR:
    7677      3451493 :             case LE_EXPR:
    7678      3451493 :             case EQ_EXPR:
    7679      3451493 :             case NE_EXPR:
    7680      3451493 :               if (TREE_CODE (arg1_type) == ENUMERAL_TYPE
    7681      3241050 :                   && TREE_CODE (arg2_type) == ENUMERAL_TYPE
    7682      6614573 :                   && (TYPE_MAIN_VARIANT (arg1_type)
    7683      3163080 :                       != TYPE_MAIN_VARIANT (arg2_type)))
    7684              :                 {
    7685           80 :                   if (cxx_dialect >= cxx26
    7686           26 :                       && (complain & tf_warning_or_error) == 0)
    7687            2 :                     result = error_mark_node;
    7688           78 :                   else if (cxx_dialect >= cxx26 || (complain & tf_warning))
    7689          130 :                     emit_diagnostic ((cxx_dialect >= cxx26
    7690              :                                       ? diagnostics::kind::pedwarn
    7691              :                                       : diagnostics::kind::warning),
    7692           77 :                                      loc, OPT_Wenum_compare,
    7693              :                                      "comparison between %q#T and %q#T",
    7694              :                                      arg1_type, arg2_type);
    7695              :                 }
    7696              :               break;
    7697              :             default:
    7698              :               break;
    7699              :             }
    7700              : 
    7701              :           /* "If a built-in candidate is selected by overload resolution, the
    7702              :              operands of class type are converted to the types of the
    7703              :              corresponding parameters of the selected operation function,
    7704              :              except that the second standard conversion sequence of a
    7705              :              user-defined conversion sequence (12.3.3.1.2) is not applied."  */
    7706      4352352 :           conversion *conv = cand->convs[0];
    7707      4352352 :           if (conv->user_conv_p)
    7708              :             {
    7709        65162 :               conv = strip_standard_conversion (conv);
    7710        65162 :               arg1 = convert_like (conv, arg1, complain);
    7711              :             }
    7712              : 
    7713      4352352 :           if (arg2)
    7714              :             {
    7715      3853970 :               conv = cand->convs[1];
    7716      3853970 :               if (conv->user_conv_p)
    7717              :                 {
    7718        11273 :                   conv = strip_standard_conversion (conv);
    7719        11273 :                   arg2 = convert_like (conv, arg2, complain);
    7720              :                 }
    7721              :             }
    7722              : 
    7723      4352352 :           if (arg3)
    7724              :             {
    7725            0 :               conv = cand->convs[2];
    7726            0 :               if (conv->user_conv_p)
    7727              :                 {
    7728            0 :                   conv = strip_standard_conversion (conv);
    7729            0 :                   arg3 = convert_like (conv, arg3, complain);
    7730              :                 }
    7731              :             }
    7732              :         }
    7733              :     }
    7734              : 
    7735     25795399 :   if (result || result_valid_p)
    7736              :     return result;
    7737              : 
    7738      4352350 :  builtin:
    7739    199662779 :   switch (code)
    7740              :     {
    7741      4847904 :     case MODIFY_EXPR:
    7742      4847904 :       return cp_build_modify_expr (loc, arg1, code2, arg2, complain);
    7743              : 
    7744     20903075 :     case INDIRECT_REF:
    7745     20903075 :       return cp_build_indirect_ref (loc, arg1, RO_UNARY_STAR, complain);
    7746              : 
    7747     18616982 :     case TRUTH_ANDIF_EXPR:
    7748     18616982 :     case TRUTH_ORIF_EXPR:
    7749     18616982 :     case TRUTH_AND_EXPR:
    7750     18616982 :     case TRUTH_OR_EXPR:
    7751     18616982 :       if ((complain & tf_warning) && !processing_template_decl)
    7752      7779197 :         warn_logical_operator (loc, code, boolean_type_node,
    7753              :                                code_orig_arg1, arg1,
    7754              :                                code_orig_arg2, arg2);
    7755              :       /* Fall through.  */
    7756     65791407 :     case GT_EXPR:
    7757     65791407 :     case LT_EXPR:
    7758     65791407 :     case GE_EXPR:
    7759     65791407 :     case LE_EXPR:
    7760     65791407 :     case EQ_EXPR:
    7761     65791407 :     case NE_EXPR:
    7762     65791407 :       if ((complain & tf_warning)
    7763     59650453 :           && ((code_orig_arg1 == BOOLEAN_TYPE)
    7764     59650453 :               ^ (code_orig_arg2 == BOOLEAN_TYPE)))
    7765        26591 :         maybe_warn_bool_compare (loc, code, arg1, arg2);
    7766     59650453 :       if (complain & tf_warning && warn_tautological_compare)
    7767       456502 :         warn_tautological_cmp (loc, code, arg1, arg2);
    7768              :       /* Fall through.  */
    7769    136844688 :     case SPACESHIP_EXPR:
    7770    136844688 :     case PLUS_EXPR:
    7771    136844688 :     case MINUS_EXPR:
    7772    136844688 :     case MULT_EXPR:
    7773    136844688 :     case TRUNC_DIV_EXPR:
    7774    136844688 :     case MAX_EXPR:
    7775    136844688 :     case MIN_EXPR:
    7776    136844688 :     case LSHIFT_EXPR:
    7777    136844688 :     case RSHIFT_EXPR:
    7778    136844688 :     case TRUNC_MOD_EXPR:
    7779    136844688 :     case BIT_AND_EXPR:
    7780    136844688 :     case BIT_IOR_EXPR:
    7781    136844688 :     case BIT_XOR_EXPR:
    7782    136844688 :       return cp_build_binary_op (loc, code, arg1, arg2, complain);
    7783              : 
    7784     31552715 :     case UNARY_PLUS_EXPR:
    7785     31552715 :     case NEGATE_EXPR:
    7786     31552715 :     case BIT_NOT_EXPR:
    7787     31552715 :     case TRUTH_NOT_EXPR:
    7788     31552715 :     case PREINCREMENT_EXPR:
    7789     31552715 :     case POSTINCREMENT_EXPR:
    7790     31552715 :     case PREDECREMENT_EXPR:
    7791     31552715 :     case POSTDECREMENT_EXPR:
    7792     31552715 :     case REALPART_EXPR:
    7793     31552715 :     case IMAGPART_EXPR:
    7794     31552715 :     case ABS_EXPR:
    7795     31552715 :     case CO_AWAIT_EXPR:
    7796     31552715 :       return cp_build_unary_op (code, arg1, false, complain);
    7797              : 
    7798      2452188 :     case ARRAY_REF:
    7799      2452188 :       return cp_build_array_ref (input_location, arg1, arg2, complain);
    7800              : 
    7801          783 :     case MEMBER_REF:
    7802          783 :       return build_m_component_ref (cp_build_indirect_ref (loc, arg1,
    7803              :                                                            RO_ARROW_STAR,
    7804              :                                                            complain),
    7805          783 :                                     arg2, complain);
    7806              : 
    7807              :       /* The caller will deal with these.  */
    7808              :     case ADDR_EXPR:
    7809              :     case COMPONENT_REF:
    7810              :     case COMPOUND_EXPR:
    7811              :       return NULL_TREE;
    7812              : 
    7813            0 :     default:
    7814            0 :       gcc_unreachable ();
    7815              :     }
    7816              :   return NULL_TREE;
    7817    221116420 : }
    7818              : 
    7819              : /* Build a new call to operator[].  This may change ARGS.  */
    7820              : 
    7821              : tree
    7822          704 : build_op_subscript (const op_location_t &loc, tree obj,
    7823              :                     vec<tree, va_gc> **args, tree *overload,
    7824              :                     tsubst_flags_t complain)
    7825              : {
    7826          704 :   struct z_candidate *candidates = 0, *cand;
    7827          704 :   tree fns, first_mem_arg = NULL_TREE;
    7828          704 :   bool any_viable_p;
    7829          704 :   tree result = NULL_TREE;
    7830              : 
    7831          704 :   auto_cond_timevar tv (TV_OVERLOAD);
    7832              : 
    7833          704 :   obj = mark_lvalue_use (obj);
    7834              : 
    7835          704 :   if (error_operand_p (obj))
    7836            0 :     return error_mark_node;
    7837              : 
    7838          704 :   tree type = TREE_TYPE (obj);
    7839              : 
    7840          704 :   obj = prep_operand (obj);
    7841              : 
    7842          704 :   if (TYPE_BINFO (type))
    7843              :     {
    7844          704 :       fns = lookup_fnfields (TYPE_BINFO (type), ovl_op_identifier (ARRAY_REF),
    7845              :                              1, complain);
    7846          704 :       if (fns == error_mark_node)
    7847              :         return error_mark_node;
    7848              :     }
    7849              :   else
    7850              :     fns = NULL_TREE;
    7851              : 
    7852          704 :   if (args != NULL && *args != NULL)
    7853              :     {
    7854          704 :       *args = resolve_args (*args, complain);
    7855          704 :       if (*args == NULL)
    7856            0 :         return error_mark_node;
    7857              :     }
    7858              : 
    7859          704 :   conversion_obstack_sentinel cos;
    7860              : 
    7861          704 :   if (fns)
    7862              :     {
    7863          702 :       first_mem_arg = obj;
    7864              : 
    7865          702 :       add_candidates (BASELINK_FUNCTIONS (fns),
    7866              :                       first_mem_arg, *args, NULL_TREE,
    7867              :                       NULL_TREE, false,
    7868          702 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    7869              :                       LOOKUP_NORMAL, &candidates, complain);
    7870              :     }
    7871              : 
    7872              :   /* Be strict here because if we choose a bad conversion candidate, the
    7873              :      errors we get won't mention the call context.  */
    7874          704 :   candidates = splice_viable (candidates, true, &any_viable_p);
    7875          704 :   if (!any_viable_p)
    7876              :     {
    7877           45 :       if (complain & tf_error)
    7878              :         {
    7879            1 :           auto_diagnostic_group d;
    7880            2 :           error ("no match for call to %<%T::operator[] (%A)%>",
    7881            1 :                  TREE_TYPE (obj), build_tree_list_vec (*args));
    7882            1 :           print_z_candidates (loc, candidates);
    7883            1 :         }
    7884           45 :       result = error_mark_node;
    7885              :     }
    7886              :   else
    7887              :     {
    7888          659 :       cand = tourney (candidates, complain);
    7889          659 :       if (cand == 0)
    7890              :         {
    7891            0 :           if (complain & tf_error)
    7892              :             {
    7893            0 :               auto_diagnostic_group d;
    7894            0 :               error ("call of %<%T::operator[] (%A)%> is ambiguous",
    7895            0 :                      TREE_TYPE (obj), build_tree_list_vec (*args));
    7896            0 :               print_z_candidates (loc, candidates);
    7897            0 :             }
    7898            0 :           result = error_mark_node;
    7899              :         }
    7900          659 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    7901          659 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    7902         1318 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, ARRAY_REF))
    7903              :         {
    7904          659 :           if (overload)
    7905          659 :             *overload = cand->fn;
    7906          659 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    7907         1318 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7908              :             /* There won't be a CALL_EXPR.  */;
    7909          659 :           else if (result && result != error_mark_node)
    7910              :             {
    7911          659 :               tree call = extract_call_expr (result);
    7912          659 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7913              : 
    7914              :               /* Specify evaluation order as per P0145R2.  */
    7915          659 :               CALL_EXPR_ORDERED_ARGS (call) = op_is_ordered (ARRAY_REF) == 1;
    7916              :             }
    7917              : 
    7918              :           /* In an expression of the form `a[]' where cand->fn
    7919              :              which is operator[] turns out to be a static member function,
    7920              :              `a' is none-the-less evaluated.  */
    7921          659 :           result = keep_unused_object_arg (result, obj, cand->fn);
    7922              :         }
    7923              :       else
    7924            0 :         gcc_unreachable ();
    7925              :     }
    7926              : 
    7927          704 :   return result;
    7928          704 : }
    7929              : 
    7930              : /* CALL was returned by some call-building function; extract the actual
    7931              :    CALL_EXPR from any bits that have been tacked on, e.g. by
    7932              :    convert_from_reference.  */
    7933              : 
    7934              : tree
    7935     45923259 : extract_call_expr (tree call)
    7936              : {
    7937     45923964 :   while (TREE_CODE (call) == COMPOUND_EXPR)
    7938          705 :     call = TREE_OPERAND (call, 1);
    7939     45923259 :   if (REFERENCE_REF_P (call))
    7940     10555112 :     call = TREE_OPERAND (call, 0);
    7941     45923259 :   if (TREE_CODE (call) == TARGET_EXPR)
    7942      3121312 :     call = TARGET_EXPR_INITIAL (call);
    7943              : 
    7944     45923259 :   if (TREE_CODE (call) != CALL_EXPR
    7945       860267 :       && TREE_CODE (call) != AGGR_INIT_EXPR
    7946       751605 :       && call != error_mark_node)
    7947       751587 :     return NULL_TREE;
    7948              :   return call;
    7949              : }
    7950              : 
    7951              : /* Returns true if FN has two parameters, of which the second has type
    7952              :    size_t.  */
    7953              : 
    7954              : static bool
    7955       681685 : second_parm_is_size_t (tree fn)
    7956              : {
    7957       681685 :   tree t = FUNCTION_ARG_CHAIN (fn);
    7958       681685 :   if (!t || !same_type_p (TREE_VALUE (t), size_type_node))
    7959              :     return false;
    7960           15 :   t = TREE_CHAIN (t);
    7961           15 :   if (t == void_list_node)
    7962            9 :     return true;
    7963              :   return false;
    7964              : }
    7965              : 
    7966              : /* True if T, an allocation function, has std::align_val_t as its second
    7967              :    argument.  */
    7968              : 
    7969              : bool
    7970       353676 : aligned_allocation_fn_p (tree t)
    7971              : {
    7972       353676 :   if (!aligned_new_threshold)
    7973              :     return false;
    7974              : 
    7975       343818 :   tree a = FUNCTION_ARG_CHAIN (t);
    7976       343818 :   return (a && same_type_p (TREE_VALUE (a), align_type_node));
    7977              : }
    7978              : 
    7979              : /* True if T is std::destroying_delete_t.  */
    7980              : 
    7981              : static bool
    7982      5864446 : std_destroying_delete_t_p (tree t)
    7983              : {
    7984      5864446 :   return (TYPE_CONTEXT (t) == std_node
    7985      5864446 :           && id_equal (TYPE_IDENTIFIER (t), "destroying_delete_t"));
    7986              : }
    7987              : 
    7988              : /* A deallocation function with at least two parameters whose second parameter
    7989              :    type is of type std::destroying_delete_t is a destroying operator delete. A
    7990              :    destroying operator delete shall be a class member function named operator
    7991              :    delete. [ Note: Array deletion cannot use a destroying operator
    7992              :    delete. --end note ] */
    7993              : 
    7994              : tree
    7995      5864461 : destroying_delete_p (tree t)
    7996              : {
    7997      5864461 :   tree a = TYPE_ARG_TYPES (TREE_TYPE (t));
    7998      5864461 :   if (!a || !TREE_CHAIN (a))
    7999              :     return NULL_TREE;
    8000      5864446 :   tree type = TREE_VALUE (TREE_CHAIN (a));
    8001      5864446 :   return std_destroying_delete_t_p (type) ? type : NULL_TREE;
    8002              : }
    8003              : 
    8004              : struct dealloc_info
    8005              : {
    8006              :   bool sized;
    8007              :   bool aligned;
    8008              :   tree destroying;
    8009              : };
    8010              : 
    8011              : /* Returns true iff T, an element of an OVERLOAD chain, is a usual deallocation
    8012              :    function (3.7.4.2 [basic.stc.dynamic.deallocation]).  If so, and DI is
    8013              :    non-null, also set *DI. */
    8014              : 
    8015              : static bool
    8016      4006826 : usual_deallocation_fn_p (tree t, dealloc_info *di)
    8017              : {
    8018      4006826 :   if (di) *di = dealloc_info();
    8019              : 
    8020              :   /* A template instance is never a usual deallocation function,
    8021              :      regardless of its signature.  */
    8022      4006826 :   if (TREE_CODE (t) == TEMPLATE_DECL
    8023      4006826 :       || primary_template_specialization_p (t))
    8024              :     return false;
    8025              : 
    8026              :   /* A usual deallocation function is a deallocation function whose parameters
    8027              :      after the first are
    8028              :      - optionally, a parameter of type std::destroying_delete_t, then
    8029              :      - optionally, a parameter of type std::size_t, then
    8030              :      - optionally, a parameter of type std::align_val_t.  */
    8031      4006814 :   bool global = DECL_NAMESPACE_SCOPE_P (t);
    8032      4006814 :   tree chain = FUNCTION_ARG_CHAIN (t);
    8033      4006814 :   if (chain && destroying_delete_p (t))
    8034              :     {
    8035           86 :       if (di) di->destroying = TREE_VALUE (chain);
    8036           86 :       chain = TREE_CHAIN (chain);
    8037              :     }
    8038      4006814 :   if (chain
    8039      4006811 :       && (!global || flag_sized_deallocation)
    8040      7998313 :       && same_type_p (TREE_VALUE (chain), size_type_node))
    8041              :     {
    8042      1155264 :       if (di) di->sized = true;
    8043      1155264 :       chain = TREE_CHAIN (chain);
    8044              :     }
    8045      4006811 :   if (chain && aligned_new_threshold
    8046      7997280 :       && same_type_p (TREE_VALUE (chain), align_type_node))
    8047              :     {
    8048      1714797 :       if (di) di->aligned = true;
    8049      1714797 :       chain = TREE_CHAIN (chain);
    8050              :     }
    8051      4006814 :   return (chain == void_list_node);
    8052              : }
    8053              : 
    8054              : /* Just return whether FN is a usual deallocation function.  */
    8055              : 
    8056              : bool
    8057         8883 : usual_deallocation_fn_p (tree fn)
    8058              : {
    8059         8883 :   return usual_deallocation_fn_p (fn, NULL);
    8060              : }
    8061              : 
    8062              : /* Build a call to operator delete.  This has to be handled very specially,
    8063              :    because the restrictions on what signatures match are different from all
    8064              :    other call instances.  For a normal delete, only a delete taking (void *)
    8065              :    or (void *, size_t) is accepted.  For a placement delete, only an exact
    8066              :    match with the placement new is accepted.
    8067              : 
    8068              :    CODE is either DELETE_EXPR or VEC_DELETE_EXPR.
    8069              :    ADDR is the pointer to be deleted.
    8070              :    SIZE is the size of the memory block to be deleted.
    8071              :    GLOBAL_P is true if the delete-expression should not consider
    8072              :    class-specific delete operators.
    8073              :    CORO_P is true if the allocation is for a coroutine, where the two argument
    8074              :    usual deallocation should be chosen in preference to the single argument
    8075              :    version in a class context.
    8076              :    PLACEMENT is the corresponding placement new call, or NULL_TREE.
    8077              :    PLACEMENT_ARGS is a pointer to vector containing the original placement
    8078              :    arguments, or NULL.
    8079              : 
    8080              :    If this call to "operator delete" is being generated as part to
    8081              :    deallocate memory allocated via a new-expression (as per [expr.new]
    8082              :    which requires that if the initialization throws an exception then
    8083              :    we call a deallocation function), then ALLOC_FN is the allocation
    8084              :    function.  */
    8085              : 
    8086              : static tree
    8087      1265308 : build_op_delete_call_1 (enum tree_code code, tree addr, tree size,
    8088              :                         bool global_p, bool coro_p, tree placement,
    8089              :                         vec<tree, va_gc> *placement_args, tree alloc_fn,
    8090              :                         tsubst_flags_t complain)
    8091              : {
    8092      1265308 :   tree fn = NULL_TREE;
    8093      1265308 :   tree fns, fnname, type, t;
    8094      1265308 :   dealloc_info di_fn = { };
    8095              : 
    8096      1265308 :   if (addr == error_mark_node)
    8097              :     return error_mark_node;
    8098              : 
    8099      1265308 :   type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
    8100              : 
    8101      1265308 :   fnname = ovl_op_identifier (false, code);
    8102              : 
    8103       878427 :   if (CLASS_TYPE_P (type)
    8104       878391 :       && COMPLETE_TYPE_P (complete_type (type))
    8105      2143664 :       && !global_p)
    8106              :     /* In [class.free]
    8107              : 
    8108              :        If the result of the lookup is ambiguous or inaccessible, or if
    8109              :        the lookup selects a placement deallocation function, the
    8110              :        program is ill-formed.
    8111              : 
    8112              :        Therefore, we ask lookup_fnfields to complain about ambiguity.  */
    8113              :     {
    8114       519640 :       fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1, complain);
    8115       519640 :       if (fns == error_mark_node)
    8116              :         return error_mark_node;
    8117              :     }
    8118              :   else
    8119              :     fns = NULL_TREE;
    8120              : 
    8121       519637 :   if (fns == NULL_TREE)
    8122      1264224 :     fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    8123              : 
    8124              :   /* Strip const and volatile from addr.  */
    8125      1265305 :   tree oaddr = addr;
    8126      1265305 :   addr = cp_convert (ptr_type_node, addr, complain);
    8127              : 
    8128      1265305 :   tree excluded_destroying = NULL_TREE;
    8129              : 
    8130      1265305 :   if (placement)
    8131              :     {
    8132              :       /* For a placement allocation function, the matching deallocation
    8133              :          function is selected as follows:
    8134              : 
    8135              :          - Each candidate that is a function template is replaced by the
    8136              :            function template specializations (if any) generated using template
    8137              :            argument deduction with arguments as specified below.
    8138              :          - Each candidate whose parameter-type-list is not identical to that
    8139              :            of the allocation function, ignoring their respective first
    8140              :            parameters, is removed from the set of candidates.
    8141              :          - Each candidate whose associated constraints (if any) are not
    8142              :            satisfied is removed from the set of candidates.
    8143              :          - If exactly one function remains, that function is selected.
    8144              :          - Otherwise, no deallocation function is selected.  */
    8145       682639 :       t = FUNCTION_ARG_CHAIN (alloc_fn);
    8146       682639 :       fn = NULL_TREE;
    8147       682639 :       tree *args = NULL;
    8148       682639 :       unsigned nargs = 0;
    8149      6137355 :       for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8150              :         {
    8151      4772092 :           if (TREE_CODE (elt) == TEMPLATE_DECL)
    8152              :             {
    8153          359 :               tree targs = make_tree_vec (DECL_NTPARMS (elt));
    8154          359 :               if (args == NULL)
    8155              :                 {
    8156           57 :                   nargs = vec_safe_length (placement_args);
    8157           57 :                   args = XALLOCAVEC (tree, nargs);
    8158           57 :                   args[0] = addr;
    8159          162 :                   for (unsigned i = 1; i < nargs; ++i)
    8160          105 :                     args[i] = (*placement_args)[i];
    8161              :                 }
    8162          359 :               elt = fn_type_unification (elt, NULL_TREE, targs, args,
    8163              :                                          nargs, NULL_TREE,
    8164              :                                          DEDUCE_CALL, LOOKUP_NORMAL,
    8165              :                                          NULL, false, false);
    8166          359 :               if (elt == error_mark_node)
    8167              :                 /* Instantiation failed.  */
    8168          227 :                 continue;
    8169              :             }
    8170              : 
    8171      4771865 :           if (!constraints_satisfied_p (elt))
    8172            0 :             continue;
    8173              : 
    8174              :           /* See if there's a match.  */
    8175      4771865 :           if (!compparms (t, FUNCTION_ARG_CHAIN (elt)))
    8176      4090150 :             continue;
    8177              : 
    8178       681715 :           if (fn != NULL_TREE)
    8179              :             {
    8180              :               fn = NULL_TREE;
    8181              :               break;
    8182              :             }
    8183              :           else
    8184              :             fn = elt;
    8185              :         }
    8186              : 
    8187              :       /* "If the lookup finds the two-parameter form of a usual deallocation
    8188              :          function (3.7.4.2) and that function, considered as a placement
    8189              :          deallocation function, would have been selected as a match for the
    8190              :          allocation function, the program is ill-formed."  */
    8191       682639 :       if (fn && second_parm_is_size_t (fn))
    8192              :         {
    8193            9 :           const char *const msg1
    8194              :             = G_("exception cleanup for this placement new selects "
    8195              :                  "non-placement %<operator delete%>");
    8196            9 :           const char *const msg2
    8197              :             = G_("%qD is a usual (non-placement) deallocation "
    8198              :                  "function in C++14 (or with %<-fsized-deallocation%>)");
    8199              : 
    8200              :           /* But if the class has an operator delete (void *), then that is
    8201              :              the usual deallocation function, so we shouldn't complain
    8202              :              about using the operator delete (void *, size_t).  */
    8203            9 :           if (DECL_CLASS_SCOPE_P (fn))
    8204           18 :             for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8205              :               {
    8206            9 :                 if (usual_deallocation_fn_p (elt)
    8207            9 :                     && FUNCTION_ARG_CHAIN (elt) == void_list_node)
    8208            3 :                   goto ok;
    8209              :               }
    8210              :           /* Before C++14 a two-parameter global deallocation function is
    8211              :              always a placement deallocation function, but warn if
    8212              :              -Wc++14-compat.  */
    8213            3 :           else if (!flag_sized_deallocation)
    8214              :             {
    8215            1 :               if (complain & tf_warning)
    8216              :                 {
    8217            1 :                   auto_diagnostic_group d;
    8218            1 :                   if (warning (OPT_Wc__14_compat, msg1))
    8219            1 :                     inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
    8220            1 :                 }
    8221            1 :               goto ok;
    8222              :             }
    8223              : 
    8224            5 :           if (complain & tf_warning_or_error)
    8225              :             {
    8226            5 :               auto_diagnostic_group d;
    8227            5 :               if (permerror (input_location, msg1))
    8228              :                 {
    8229              :                   /* Only mention C++14 for namespace-scope delete.  */
    8230            5 :                   if (DECL_NAMESPACE_SCOPE_P (fn))
    8231            2 :                     inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
    8232              :                   else
    8233            3 :                     inform (DECL_SOURCE_LOCATION (fn),
    8234              :                             "%qD is a usual (non-placement) deallocation "
    8235              :                             "function", fn);
    8236              :                 }
    8237            5 :             }
    8238              :           else
    8239            0 :             return error_mark_node;
    8240      1265305 :         ok:;
    8241              :         }
    8242              :     }
    8243              :   else
    8244              :     /* "Any non-placement deallocation function matches a non-placement
    8245              :        allocation function. If the lookup finds a single matching
    8246              :        deallocation function, that function will be called; otherwise, no
    8247              :        deallocation function will be called."  */
    8248      5163275 :     for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8249              :       {
    8250      3997943 :         dealloc_info di_elt;
    8251      3997943 :         if (usual_deallocation_fn_p (elt, &di_elt))
    8252              :           {
    8253              :             /* If we're called for an EH cleanup in a new-expression, we can't
    8254              :                use a destroying delete; the exception was thrown before the
    8255              :                object was constructed.  */
    8256      2309012 :             if (alloc_fn && di_elt.destroying)
    8257              :               {
    8258           13 :                 excluded_destroying = elt;
    8259      1176775 :                 continue;
    8260              :               }
    8261              : 
    8262      2308999 :             if (!fn)
    8263              :               {
    8264       582641 :                 fn = elt;
    8265       582641 :                 di_fn = di_elt;
    8266       582641 :                 continue;
    8267              :               }
    8268              : 
    8269              :             /* -- If any of the deallocation functions is a destroying
    8270              :                operator delete, all deallocation functions that are not
    8271              :                destroying operator deletes are eliminated from further
    8272              :                consideration.  */
    8273      1726358 :             if (di_elt.destroying != di_fn.destroying)
    8274              :               {
    8275           12 :                 if (di_elt.destroying)
    8276              :                   {
    8277            6 :                     fn = elt;
    8278            6 :                     di_fn = di_elt;
    8279              :                   }
    8280           12 :                 continue;
    8281              :               }
    8282              : 
    8283              :             /* -- If the type has new-extended alignment, a function with a
    8284              :                parameter of type std::align_val_t is preferred; otherwise a
    8285              :                function without such a parameter is preferred. If exactly one
    8286              :                preferred function is found, that function is selected and the
    8287              :                selection process terminates. If more than one preferred
    8288              :                function is found, all non-preferred functions are eliminated
    8289              :                from further consideration.  */
    8290      1726346 :             if (aligned_new_threshold)
    8291              :               {
    8292      1726079 :                 bool want_align = type_has_new_extended_alignment (type);
    8293      1726079 :                 if (di_elt.aligned != di_fn.aligned)
    8294              :                   {
    8295       594109 :                     if (want_align == di_elt.aligned)
    8296              :                       {
    8297       556598 :                         fn = elt;
    8298       556598 :                         di_fn = di_elt;
    8299              :                       }
    8300       594109 :                     continue;
    8301              :                   }
    8302              :               }
    8303              : 
    8304              :             /* -- If the deallocation functions have class scope, the one
    8305              :                without a parameter of type std::size_t is selected.  */
    8306      1132237 :             bool want_size;
    8307      1132237 :             if (DECL_CLASS_SCOPE_P (fn) && !coro_p)
    8308              :               want_size = false;
    8309              : 
    8310              :             /* -- If the type is complete and if, for the second alternative
    8311              :                (delete array) only, the operand is a pointer to a class type
    8312              :                with a non-trivial destructor or a (possibly multi-dimensional)
    8313              :                array thereof, the function with a parameter of type std::size_t
    8314              :                is selected.
    8315              : 
    8316              :                -- Otherwise, it is unspecified whether a deallocation function
    8317              :                with a parameter of type std::size_t is selected.  */
    8318              :             else
    8319              :               {
    8320      1132129 :                 want_size = COMPLETE_TYPE_P (type);
    8321      1132129 :                 if (code == VEC_DELETE_EXPR
    8322      1132129 :                     && !TYPE_VEC_NEW_USES_COOKIE (type))
    8323              :                   /* We need a cookie to determine the array size.  */
    8324              :                   want_size = false;
    8325              :               }
    8326      1132237 :             gcc_assert (di_fn.sized != di_elt.sized);
    8327      1132237 :             if (want_size == di_elt.sized)
    8328              :               {
    8329        46001 :                 fn = elt;
    8330        46001 :                 di_fn = di_elt;
    8331              :               }
    8332              :           }
    8333              :       }
    8334              : 
    8335              :   /* If we have a matching function, call it.  */
    8336      1265305 :   if (fn)
    8337              :     {
    8338      1264326 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    8339              : 
    8340              :       /* If the FN is a member function, make sure that it is
    8341              :          accessible.  */
    8342      1264326 :       if (BASELINK_P (fns))
    8343         1011 :         perform_or_defer_access_check (BASELINK_BINFO (fns), fn, fn,
    8344              :                                        complain);
    8345              : 
    8346              :       /* Core issue 901: It's ok to new a type with deleted delete.  */
    8347      1264326 :       if (DECL_DELETED_FN (fn) && alloc_fn)
    8348              :         return NULL_TREE;
    8349              : 
    8350      1264320 :       tree ret;
    8351      1264320 :       if (placement)
    8352              :         {
    8353              :           /* The placement args might not be suitable for overload
    8354              :              resolution at this point, so build the call directly.  */
    8355       681685 :           int nargs = call_expr_nargs (placement);
    8356       681685 :           tree *argarray = XALLOCAVEC (tree, nargs);
    8357       681685 :           int i;
    8358       681685 :           argarray[0] = addr;
    8359      1363434 :           for (i = 1; i < nargs; i++)
    8360       681749 :             argarray[i] = CALL_EXPR_ARG (placement, i);
    8361       681685 :           if (!mark_used (fn, complain) && !(complain & tf_error))
    8362            0 :             return error_mark_node;
    8363       681685 :           ret = build_cxx_call (fn, nargs, argarray, complain);
    8364              :         }
    8365              :       else
    8366              :         {
    8367       582635 :           tree destroying = di_fn.destroying;
    8368       582635 :           if (destroying)
    8369              :             {
    8370              :               /* Strip const and volatile from addr but retain the type of the
    8371              :                  object.  */
    8372           28 :               tree rtype = TREE_TYPE (TREE_TYPE (oaddr));
    8373           28 :               rtype = cv_unqualified (rtype);
    8374           28 :               rtype = TYPE_POINTER_TO (rtype);
    8375           28 :               addr = cp_convert (rtype, oaddr, complain);
    8376           28 :               destroying = build_functional_cast (input_location,
    8377              :                                                   destroying, NULL_TREE,
    8378              :                                                   complain);
    8379              :             }
    8380              : 
    8381       582635 :           releasing_vec args;
    8382       582635 :           args->quick_push (addr);
    8383       582635 :           if (destroying)
    8384           28 :             args->quick_push (destroying);
    8385       582635 :           if (di_fn.sized)
    8386       543541 :             args->quick_push (size);
    8387       582635 :           if (di_fn.aligned)
    8388              :             {
    8389        18759 :               tree al = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (type));
    8390        18759 :               args->quick_push (al);
    8391              :             }
    8392       582635 :           ret = cp_build_function_call_vec (fn, &args, complain);
    8393       582635 :         }
    8394              : 
    8395              :       /* Set this flag for all callers of this function.  In addition to
    8396              :          delete-expressions, this is called for deallocating coroutine state;
    8397              :          treat that as an implicit delete-expression.  This is also called for
    8398              :          the delete if the constructor throws in a new-expression, and for a
    8399              :          deleting destructor (which implements a delete-expression).  */
    8400              :       /* But leave this flag off for destroying delete to avoid wrong
    8401              :          assumptions in the optimizers.  */
    8402      1264320 :       tree call = extract_call_expr (ret);
    8403      1264320 :       if (TREE_CODE (call) == CALL_EXPR && !destroying_delete_p (fn))
    8404      1264286 :         CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    8405              : 
    8406              :       return ret;
    8407              :     }
    8408              : 
    8409              :   /* If there's only a destroying delete that we can't use because the
    8410              :      object isn't constructed yet, and we used global new, use global
    8411              :      delete as well.  */
    8412          979 :   if (excluded_destroying
    8413          979 :       && DECL_NAMESPACE_SCOPE_P (alloc_fn))
    8414            7 :     return build_op_delete_call (code, addr, size, true, placement,
    8415            7 :                                  placement_args, alloc_fn, complain);
    8416              : 
    8417              :   /* [expr.new]
    8418              : 
    8419              :      If no unambiguous matching deallocation function can be found,
    8420              :      propagating the exception does not cause the object's memory to
    8421              :      be freed.  */
    8422          972 :   if (alloc_fn)
    8423              :     {
    8424          969 :       if ((complain & tf_warning) && !placement)
    8425              :         {
    8426           15 :           auto_diagnostic_group d;
    8427           15 :           bool w = warning (0,
    8428              :                             "no corresponding deallocation function for %qD",
    8429              :                             alloc_fn);
    8430           15 :           if (w && excluded_destroying)
    8431            3 :             inform (DECL_SOURCE_LOCATION (excluded_destroying), "destroying "
    8432              :                     "delete %qD cannot be used to release the allocated memory"
    8433              :                     " if the initialization throws because the object is not "
    8434              :                     "constructed yet", excluded_destroying);
    8435           15 :         }
    8436              :       return NULL_TREE;
    8437              :     }
    8438              : 
    8439            3 :   if (complain & tf_error)
    8440            3 :     error ("no suitable %<operator %s%> for %qT",
    8441            3 :            OVL_OP_INFO (false, code)->name, type);
    8442            3 :   return error_mark_node;
    8443              : }
    8444              : 
    8445              : /* Arguments as per build_op_delete_call_1 ().  */
    8446              : 
    8447              : tree
    8448      1262011 : build_op_delete_call (enum tree_code code, tree addr, tree size, bool global_p,
    8449              :                       tree placement, vec<tree, va_gc> *placement_args,
    8450              :                       tree alloc_fn, tsubst_flags_t complain)
    8451              : {
    8452      1262011 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/false,
    8453              :                                  placement, placement_args, alloc_fn,
    8454      1262011 :                                  complain);
    8455              : }
    8456              : 
    8457              : /* Arguments as per build_op_delete_call_1 ().  */
    8458              : 
    8459              : tree
    8460         3297 : build_coroutine_op_delete_call (enum tree_code code, tree addr, tree size,
    8461              :                                 bool global_p, tree alloc_fn,
    8462              :                                 tsubst_flags_t complain)
    8463              : {
    8464         3297 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/true,
    8465              :                                  /*placement*/NULL_TREE,
    8466         3297 :                                  /*placement_args*/NULL, alloc_fn, complain);
    8467              : }
    8468              : 
    8469              : /* Issue diagnostics about a disallowed access of DECL, using DIAG_DECL
    8470              :    in the diagnostics.
    8471              : 
    8472              :    If ISSUE_ERROR is true, then issue an error about the access, followed
    8473              :    by a note showing the declaration.  Otherwise, just show the note.
    8474              : 
    8475              :    DIAG_DECL and DIAG_LOCATION will almost always be the same.
    8476              :    DIAG_LOCATION is just another DECL.  NO_ACCESS_REASON is an optional
    8477              :    parameter used to specify why DECL wasn't accessible (e.g. ak_private
    8478              :    would be because DECL was private).  If not using NO_ACCESS_REASON,
    8479              :    then it must be ak_none, and the access failure reason will be
    8480              :    figured out by looking at the protection of DECL.  */
    8481              : 
    8482              : void
    8483         1187 : complain_about_access (tree decl, tree diag_decl, tree diag_location,
    8484              :                        bool issue_error, access_kind no_access_reason)
    8485              : {
    8486              :   /* If we have not already figured out why DECL is inaccessible...  */
    8487         1187 :   if (no_access_reason == ak_none)
    8488              :     {
    8489              :       /* Examine the access of DECL to find out why.  */
    8490         1005 :       if (TREE_PRIVATE (decl))
    8491              :         no_access_reason = ak_private;
    8492          225 :       else if (TREE_PROTECTED (decl))
    8493          180 :         no_access_reason = ak_protected;
    8494              :     }
    8495              : 
    8496              :   /* Now generate an error message depending on calculated access.  */
    8497         1187 :   auto_diagnostic_group d;
    8498         1187 :   if (no_access_reason == ak_private)
    8499              :     {
    8500          962 :       if (issue_error)
    8501          948 :         error ("%q#D is private within this context", diag_decl);
    8502          962 :       inform (DECL_SOURCE_LOCATION (diag_location), "declared private here");
    8503              :     }
    8504          225 :   else if (no_access_reason == ak_protected)
    8505              :     {
    8506          180 :       if (issue_error)
    8507          166 :         error ("%q#D is protected within this context", diag_decl);
    8508          180 :       inform (DECL_SOURCE_LOCATION (diag_location), "declared protected here");
    8509              :     }
    8510              :   /* Couldn't figure out why DECL is inaccessible, so just say it's
    8511              :      inaccessible.  */
    8512              :   else
    8513              :     {
    8514           45 :       if (issue_error)
    8515           45 :         error ("%q#D is inaccessible within this context", diag_decl);
    8516           45 :       inform (DECL_SOURCE_LOCATION (diag_decl), "declared here");
    8517              :     }
    8518         1187 : }
    8519              : 
    8520              : /* Initialize a temporary of type TYPE with EXPR.  The FLAGS are a
    8521              :    bitwise or of LOOKUP_* values.  If any errors are warnings are
    8522              :    generated, set *DIAGNOSTIC_FN to "error" or "warning",
    8523              :    respectively.  If no diagnostics are generated, set *DIAGNOSTIC_FN
    8524              :    to NULL.  */
    8525              : 
    8526              : static tree
    8527     14378690 : build_temp (tree expr, tree type, int flags,
    8528              :             enum diagnostics::kind *diagnostic_kind, tsubst_flags_t complain)
    8529              : {
    8530     14378690 :   int savew, savee;
    8531              : 
    8532     14378690 :   *diagnostic_kind = diagnostics::kind::unspecified;
    8533              : 
    8534              :   /* If the source is a packed field, calling the copy constructor will require
    8535              :      binding the field to the reference parameter to the copy constructor, and
    8536              :      we'll end up with an infinite loop.  If we can use a bitwise copy, then
    8537              :      do that now.  */
    8538     14378690 :   if ((lvalue_kind (expr) & clk_packed)
    8539            6 :       && CLASS_TYPE_P (TREE_TYPE (expr))
    8540     14378696 :       && !type_has_nontrivial_copy_init (TREE_TYPE (expr)))
    8541            3 :     return get_target_expr (expr, complain);
    8542              : 
    8543              :   /* In decltype, we might have decided not to wrap this call in a TARGET_EXPR.
    8544              :      But it turns out to be a subexpression, so perform temporary
    8545              :      materialization now.  */
    8546     14378687 :   if (TREE_CODE (expr) == CALL_EXPR
    8547            6 :       && CLASS_TYPE_P (type)
    8548     14378693 :       && same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (expr)))
    8549            3 :     expr = build_cplus_new (type, expr, complain);
    8550              : 
    8551     14378687 :   savew = warningcount + werrorcount, savee = errorcount;
    8552     14378687 :   releasing_vec args (make_tree_vector_single (expr));
    8553     14378687 :   expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
    8554              :                                     &args, type, flags, complain);
    8555     14378687 :   if (warningcount + werrorcount > savew)
    8556            0 :     *diagnostic_kind = diagnostics::kind::warning;
    8557     14378687 :   else if (errorcount > savee)
    8558           78 :     *diagnostic_kind = diagnostics::kind::error;
    8559     14378687 :   return expr;
    8560     14378687 : }
    8561              : 
    8562              : /* Get any location for EXPR, falling back to input_location.
    8563              : 
    8564              :    If the result is in a system header and is the virtual location for
    8565              :    a token coming from the expansion of a macro, unwind it to the
    8566              :    location of the expansion point of the macro (e.g. to avoid the
    8567              :    diagnostic being suppressed for expansions of NULL where "NULL" is
    8568              :    in a system header).  */
    8569              : 
    8570              : static location_t
    8571      2440279 : get_location_for_expr_unwinding_for_system_header (tree expr)
    8572              : {
    8573      2440279 :   location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
    8574      2440279 :   loc = expansion_point_location_if_in_system_header (loc);
    8575      2440279 :   return loc;
    8576              : }
    8577              : 
    8578              : /* Perform warnings about peculiar, but valid, conversions from/to NULL.
    8579              :    Also handle a subset of zero as null warnings.
    8580              :    EXPR is implicitly converted to type TOTYPE.
    8581              :    FN and ARGNUM are used for diagnostics.  */
    8582              : 
    8583              : static void
    8584    551061777 : conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
    8585              : {
    8586              :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    8587    551061777 :   if (TREE_CODE (totype) != BOOLEAN_TYPE
    8588              :       && ARITHMETIC_TYPE_P (totype)
    8589    188883975 :       && null_node_p (expr))
    8590              :     {
    8591           94 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8592           94 :       if (fn)
    8593              :         {
    8594           33 :           auto_diagnostic_group d;
    8595           33 :           if (warning_at (loc, OPT_Wconversion_null,
    8596              :                           "passing NULL to non-pointer argument %P of %qD",
    8597              :                           argnum, fn))
    8598           27 :             inform (get_fndecl_argument_location (fn, argnum),
    8599              :                     "declared here");
    8600           33 :         }
    8601              :       else
    8602           61 :         warning_at (loc, OPT_Wconversion_null,
    8603              :                     "converting to non-pointer type %qT from NULL", totype);
    8604              :     }
    8605              : 
    8606              :   /* Issue warnings if "false" is converted to a NULL pointer */
    8607    551061683 :   else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
    8608    551061683 :            && TYPE_PTR_P (totype))
    8609              :     {
    8610            7 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8611            7 :       if (fn)
    8612              :         {
    8613            3 :           auto_diagnostic_group d;
    8614            3 :           if (warning_at (loc, OPT_Wconversion_null,
    8615              :                           "converting %<false%> to pointer type for argument "
    8616              :                           "%P of %qD", argnum, fn))
    8617            3 :             inform (get_fndecl_argument_location (fn, argnum),
    8618              :                     "declared here");
    8619            3 :         }
    8620              :       else
    8621            4 :         warning_at (loc, OPT_Wconversion_null,
    8622              :                     "converting %<false%> to pointer type %qT", totype);
    8623              :     }
    8624              :   /* Handle zero as null pointer warnings for cases other
    8625              :      than EQ_EXPR and NE_EXPR */
    8626    507672153 :   else if ((TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype))
    8627    551378901 :            && null_ptr_cst_p (expr))
    8628              :     {
    8629      2440178 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8630      2440178 :       maybe_warn_zero_as_null_pointer_constant (expr, loc);
    8631              :     }
    8632    551061777 : }
    8633              : 
    8634              : /* We gave a diagnostic during a conversion.  If this was in the second
    8635              :    standard conversion sequence of a user-defined conversion sequence, say
    8636              :    which user-defined conversion.  */
    8637              : 
    8638              : static void
    8639         5275 : maybe_print_user_conv_context (conversion *convs)
    8640              : {
    8641         5275 :   if (convs->user_conv_p)
    8642          167 :     for (conversion *t = convs; t; t = next_conversion (t))
    8643          142 :       if (t->kind == ck_user)
    8644              :         {
    8645           43 :           print_z_candidate (0, N_("  after user-defined conversion:"),
    8646              :                              t->cand);
    8647           43 :           break;
    8648              :         }
    8649         5275 : }
    8650              : 
    8651              : /* Locate the parameter with the given index within FNDECL.
    8652              :    ARGNUM is zero based, -1 indicates the `this' argument of a method.
    8653              :    Return the location of the FNDECL itself if there are problems.  */
    8654              : 
    8655              : location_t
    8656      9179062 : get_fndecl_argument_location (tree fndecl, int argnum)
    8657              : {
    8658              :   /* The locations of implicitly-declared functions are likely to be
    8659              :      more meaningful than those of their parameters.  */
    8660      9179062 :   if (DECL_ARTIFICIAL (fndecl))
    8661          297 :     return DECL_SOURCE_LOCATION (fndecl);
    8662              : 
    8663      9178765 :   if (argnum == -1)
    8664           51 :     return DECL_SOURCE_LOCATION (fndecl);
    8665              : 
    8666      9178714 :   int i;
    8667      9178714 :   tree param;
    8668              : 
    8669              :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8670      9178714 :   for (i = 0, param = FUNCTION_FIRST_USER_PARM (fndecl);
    8671     23052427 :        i < argnum && param;
    8672     13873713 :        i++, param = TREE_CHAIN (param))
    8673              :     ;
    8674              : 
    8675              :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    8676              :      return the location of FNDECL.  */
    8677      9178714 :   if (param == NULL)
    8678           40 :     return DECL_SOURCE_LOCATION (fndecl);
    8679              : 
    8680      9178674 :   return DECL_SOURCE_LOCATION (param);
    8681              : }
    8682              : 
    8683              : /* If FNDECL is non-NULL, issue a note highlighting ARGNUM
    8684              :    within its declaration (or the fndecl itself if something went
    8685              :    wrong).  */
    8686              : 
    8687              : void
    8688         7074 : maybe_inform_about_fndecl_for_bogus_argument_init (tree fn, int argnum,
    8689              :                                                    const char *highlight_color)
    8690              : {
    8691         7074 :   if (fn)
    8692              :     {
    8693         1171 :       gcc_rich_location richloc (get_fndecl_argument_location (fn, argnum));
    8694         1171 :       richloc.set_highlight_color (highlight_color);
    8695         1171 :       inform (&richloc,
    8696              :               "initializing argument %P of %qD", argnum, fn);
    8697         1171 :     }
    8698         7074 : }
    8699              : 
    8700              : /* Maybe warn about C++20 Conversions to arrays of unknown bound.  C is
    8701              :    the conversion, EXPR is the expression we're converting.  */
    8702              : 
    8703              : static void
    8704     39614010 : maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
    8705              : {
    8706     39614010 :   if (cxx_dialect >= cxx20)
    8707              :     return;
    8708              : 
    8709       437067 :   tree type = TREE_TYPE (expr);
    8710       437067 :   type = strip_pointer_operator (type);
    8711              : 
    8712       437067 :   if (TREE_CODE (type) != ARRAY_TYPE
    8713       437067 :       || TYPE_DOMAIN (type) == NULL_TREE)
    8714              :     return;
    8715              : 
    8716         1858 :   if (pedantic && conv_binds_to_array_of_unknown_bound (c))
    8717           10 :     pedwarn (loc, OPT_Wc__20_extensions,
    8718              :              "conversions to arrays of unknown bound "
    8719              :              "are only available with %<-std=c++20%> or %<-std=gnu++20%>");
    8720              : }
    8721              : 
    8722              : /* We call this recursively in convert_like_internal.  */
    8723              : static tree convert_like (conversion *, tree, tree, int, bool, bool, bool,
    8724              :                           tsubst_flags_t);
    8725              : 
    8726              : /* Adjust the result EXPR of a conversion to the expected type TOTYPE, which
    8727              :    must be equivalent but might be a typedef.  */
    8728              : 
    8729              : static tree
    8730    932952961 : maybe_adjust_type_name (tree type, tree expr, conversion_kind kind)
    8731              : {
    8732    932952961 :   if (expr == error_mark_node
    8733    932952910 :       || processing_template_decl)
    8734              :     return expr;
    8735              : 
    8736    819075636 :   tree etype = TREE_TYPE (expr);
    8737    819075636 :   if (etype == type)
    8738              :     return expr;
    8739              : 
    8740    108097089 :   gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p (etype, type)
    8741              :                        || is_bitfield_expr_with_lowered_type (expr)
    8742              :                        || seen_error ());
    8743              : 
    8744    108097089 :   if (SCALAR_TYPE_P (type)
    8745    102211859 :       && (kind == ck_rvalue
    8746              :           /* ??? We should be able to do this for ck_identity of more prvalue
    8747              :              expressions, but checking !obvalue_p here breaks, so for now let's
    8748              :              just handle NON_LVALUE_EXPR (such as the location wrapper for a
    8749              :              literal).  Maybe we want to express already-rvalue in the
    8750              :              conversion somehow?  */
    8751     91726414 :           || TREE_CODE (expr) == NON_LVALUE_EXPR))
    8752     12051587 :     expr = build_nop (type, expr);
    8753              : 
    8754              :   return expr;
    8755              : }
    8756              : 
    8757              : /* Perform the conversions in CONVS on the expression EXPR.  FN and
    8758              :    ARGNUM are used for diagnostics.  ARGNUM is zero based, -1
    8759              :    indicates the `this' argument of a method.  INNER is nonzero when
    8760              :    being called to continue a conversion chain. It is negative when a
    8761              :    reference binding will be applied, positive otherwise.  If
    8762              :    ISSUE_CONVERSION_WARNINGS is true, warnings about suspicious
    8763              :    conversions will be emitted if appropriate.  If C_CAST_P is true,
    8764              :    this conversion is coming from a C-style cast; in that case,
    8765              :    conversions to inaccessible bases are permitted.  */
    8766              : 
    8767              : static tree
    8768   1136583140 : convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
    8769              :                        bool issue_conversion_warnings, bool c_cast_p,
    8770              :                        bool nested_p, tsubst_flags_t complain)
    8771              : {
    8772   1136583140 :   tree totype = convs->type;
    8773   1136583140 :   enum diagnostics::kind diag_kind;
    8774   1136583140 :   int flags;
    8775   1136583140 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    8776   1136583140 :   const bool stub_object_p = is_stub_object (expr);
    8777              : 
    8778   1136583140 :   if (convs->bad_p && !(complain & tf_error))
    8779        46825 :     return error_mark_node;
    8780              : 
    8781   1136536315 :   gcc_checking_assert (!TYPE_REF_P (TREE_TYPE (expr)));
    8782              : 
    8783   1136536315 :   if (convs->bad_p
    8784         6997 :       && convs->kind != ck_user
    8785         6902 :       && convs->kind != ck_list
    8786         6896 :       && convs->kind != ck_ambig
    8787         6896 :       && (convs->kind != ck_ref_bind
    8788         5282 :           || (convs->user_conv_p && next_conversion (convs)->bad_p))
    8789         1635 :       && (convs->kind != ck_rvalue
    8790           15 :           || SCALAR_TYPE_P (totype))
    8791   1136537941 :       && convs->kind != ck_base)
    8792              :     {
    8793         1626 :       int complained = 0;
    8794         1626 :       conversion *t = convs;
    8795         1626 :       auto_diagnostic_group d;
    8796              : 
    8797              :       /* Give a helpful error if this is bad because of excess braces.  */
    8798           46 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8799           46 :           && SCALAR_TYPE_P (totype)
    8800           34 :           && CONSTRUCTOR_NELTS (expr) > 0
    8801         1660 :           && BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
    8802              :         {
    8803           11 :           complained = permerror (loc, "too many braces around initializer "
    8804              :                                   "for %qT", totype);
    8805           33 :           while (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8806           55 :                  && CONSTRUCTOR_NELTS (expr) == 1)
    8807           22 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    8808              :         }
    8809              : 
    8810              :       /* Give a helpful error if this is bad because a conversion to bool
    8811              :          from std::nullptr_t requires direct-initialization.  */
    8812         1626 :       if (NULLPTR_TYPE_P (TREE_TYPE (expr))
    8813         1626 :           && TREE_CODE (totype) == BOOLEAN_TYPE)
    8814           15 :         complained = permerror (loc, "converting to %qH from %qI requires "
    8815              :                                 "direct-initialization",
    8816           15 :                                 totype, TREE_TYPE (expr));
    8817              : 
    8818         1626 :       if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (expr))
    8819          105 :           && SCALAR_FLOAT_TYPE_P (totype)
    8820         1731 :           && (extended_float_type_p (TREE_TYPE (expr))
    8821           27 :               || extended_float_type_p (totype)))
    8822          105 :         switch (cp_compare_floating_point_conversion_ranks (TREE_TYPE (expr),
    8823              :                                                             totype))
    8824              :           {
    8825          102 :           case 2:
    8826          102 :             if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow "
    8827              :                          "converting to %qH from %qI with greater "
    8828          102 :                          "conversion rank", totype, TREE_TYPE (expr)))
    8829         1626 :               complained = 1;
    8830           21 :             else if (!complained)
    8831         1626 :               complained = -1;
    8832              :             break;
    8833            3 :           case 3:
    8834            3 :             if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow "
    8835              :                          "converting to %qH from %qI with unordered "
    8836            3 :                          "conversion rank", totype, TREE_TYPE (expr)))
    8837              :               complained = 1;
    8838            0 :             else if (!complained)
    8839         1626 :               complained = -1;
    8840              :             break;
    8841              :           default:
    8842              :             break;
    8843              :           }
    8844              : 
    8845         3268 :       for (; t ; t = next_conversion (t))
    8846              :         {
    8847         3259 :           if (t->kind == ck_user && t->cand->reason)
    8848              :             {
    8849           52 :               auto_diagnostic_group d;
    8850           52 :               complained = permerror (loc, "invalid user-defined conversion "
    8851           52 :                                       "from %qH to %qI", TREE_TYPE (expr),
    8852              :                                       totype);
    8853           52 :               if (complained)
    8854              :                 {
    8855           52 :                   auto_diagnostic_nesting_level sentinel;
    8856           52 :                   print_z_candidate (loc, N_("candidate is:"), t->cand);
    8857           52 :                 }
    8858           52 :               expr = convert_like (t, expr, fn, argnum,
    8859              :                                    /*issue_conversion_warnings=*/false,
    8860              :                                    /*c_cast_p=*/false, /*nested_p=*/true,
    8861              :                                    complain);
    8862           52 :               break;
    8863           52 :             }
    8864         3207 :           else if (t->kind == ck_user || !t->bad_p)
    8865              :             {
    8866         1565 :               expr = convert_like (t, expr, fn, argnum,
    8867              :                                    /*issue_conversion_warnings=*/false,
    8868              :                                    /*c_cast_p=*/false, /*nested_p=*/true,
    8869              :                                    complain);
    8870         1565 :               if (t->bad_p)
    8871            0 :                 complained = 1;
    8872              :               break;
    8873              :             }
    8874         1642 :           else if (t->kind == ck_ambig)
    8875            0 :             return convert_like (t, expr, fn, argnum,
    8876              :                                  /*issue_conversion_warnings=*/false,
    8877              :                                  /*c_cast_p=*/false, /*nested_p=*/true,
    8878            0 :                                  complain);
    8879         1642 :           else if (t->kind == ck_identity)
    8880              :             break;
    8881              :         }
    8882         1626 :       if (!complained && stub_object_p)
    8883              :         {
    8884              :           /* An error diagnosed within a trait, don't give extra labels.  */
    8885           12 :           error_at (loc, "invalid conversion from %qH to %qI",
    8886            6 :                     TREE_TYPE (expr), totype);
    8887            6 :           complained = 1;
    8888              :         }
    8889         1620 :       else if (!complained && expr != error_mark_node)
    8890              :         {
    8891         1435 :           range_label_for_type_mismatch label (TREE_TYPE (expr), totype);
    8892         1435 :           gcc_rich_location richloc (loc, &label, highlight_colors::percent_h);
    8893         1435 :           complained = permerror (&richloc,
    8894              :                                   "invalid conversion from %qH to %qI",
    8895         1435 :                                   TREE_TYPE (expr), totype);
    8896         1435 :           if (complained)
    8897         1380 :             maybe_emit_indirection_note (loc, expr, totype);
    8898         1435 :         }
    8899         1626 :       if (convs->kind == ck_ref_bind)
    8900           21 :         expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
    8901              :                                      LOOKUP_NORMAL, NULL_TREE,
    8902              :                                      complain);
    8903              :       else
    8904         1605 :         expr = cp_convert (totype, expr, complain);
    8905         1626 :       if (complained == 1)
    8906         1548 :         maybe_inform_about_fndecl_for_bogus_argument_init
    8907         1548 :           (fn, argnum, highlight_colors::percent_i);
    8908              :       return expr;
    8909         1626 :     }
    8910              : 
    8911   1136534689 :   if (issue_conversion_warnings && (complain & tf_warning))
    8912    551061777 :     conversion_null_warnings (totype, expr, fn, argnum);
    8913              : 
    8914   1136534689 :   switch (convs->kind)
    8915              :     {
    8916      6720563 :     case ck_user:
    8917      6720563 :       {
    8918      6720563 :         struct z_candidate *cand = convs->cand;
    8919              : 
    8920      6720563 :         if (cand == NULL)
    8921              :           /* We chose the surrogate function from add_conv_candidate, now we
    8922              :              actually need to build the conversion.  */
    8923           56 :           cand = build_user_type_conversion_1 (totype, expr,
    8924              :                                                LOOKUP_NO_CONVERSION, complain);
    8925              : 
    8926      6720563 :         tree convfn = cand->fn;
    8927              : 
    8928              :         /* When converting from an init list we consider explicit
    8929              :            constructors, but actually trying to call one is an error.  */
    8930      7210055 :         if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
    8931        10117 :             && BRACE_ENCLOSED_INITIALIZER_P (expr)
    8932              :             /* Unless this is for direct-list-initialization.  */
    8933        10114 :             && (!CONSTRUCTOR_IS_DIRECT_INIT (expr) || convs->need_temporary_p)
    8934              :             /* And in C++98 a default constructor can't be explicit.  */
    8935      6720803 :             && cxx_dialect >= cxx11)
    8936              :           {
    8937          238 :             if (!(complain & tf_error))
    8938           54 :               return error_mark_node;
    8939          184 :             location_t loc = location_of (expr);
    8940          184 :             if (CONSTRUCTOR_NELTS (expr) == 0
    8941          184 :                 && FUNCTION_FIRST_USER_PARMTYPE (convfn) != void_list_node)
    8942              :               {
    8943            9 :                 auto_diagnostic_group d;
    8944            9 :                 if (pedwarn (loc, 0, "converting to %qT from initializer list "
    8945              :                              "would use explicit constructor %qD",
    8946              :                              totype, convfn))
    8947              :                   {
    8948            9 :                     inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8949              :                             convfn);
    8950            9 :                     inform (loc, "in C++11 and above a default constructor "
    8951              :                             "can be explicit");
    8952              :                   }
    8953            9 :               }
    8954              :             else
    8955              :               {
    8956          175 :                 auto_diagnostic_group d;
    8957          175 :                 error ("converting to %qT from initializer list would use "
    8958              :                        "explicit constructor %qD", totype, convfn);
    8959          175 :                 inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8960              :                         convfn);
    8961          175 :               }
    8962              :           }
    8963              : 
    8964              :         /* If we're initializing from {}, it's value-initialization.  */
    8965       881363 :         if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8966       881341 :             && CONSTRUCTOR_NELTS (expr) == 0
    8967       149974 :             && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)
    8968      6870456 :             && !processing_template_decl)
    8969              :           {
    8970       149947 :             if (abstract_virtuals_error (NULL_TREE, totype, complain))
    8971           12 :               return error_mark_node;
    8972       149935 :             expr = build_value_init (totype, complain);
    8973       149935 :             expr = get_target_expr (expr, complain);
    8974       149935 :             if (expr != error_mark_node)
    8975       149792 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8976              :             return expr;
    8977              :           }
    8978              : 
    8979              :         /* We don't know here whether EXPR is being used as an lvalue or
    8980              :            rvalue, but we know it's read.  */
    8981      6570562 :         mark_exp_read (expr);
    8982              : 
    8983              :         /* Give the conversion call the location of EXPR rather than the
    8984              :            location of the context that caused the conversion.  */
    8985      6570562 :         iloc_sentinel ils (loc);
    8986              : 
    8987              :         /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow
    8988              :            any more UDCs.  */
    8989      6570562 :         expr = build_over_call (cand, LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
    8990              :                                 complain);
    8991              : 
    8992              :         /* If this is a constructor or a function returning an aggr type,
    8993              :            we need to build up a TARGET_EXPR.  */
    8994     13141124 :         if (DECL_CONSTRUCTOR_P (convfn))
    8995              :           {
    8996      2940989 :             expr = build_cplus_new (totype, expr, complain);
    8997              : 
    8998              :             /* Remember that this was list-initialization.  */
    8999      2940989 :             if (convs->check_narrowing && expr != error_mark_node)
    9000       756657 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    9001              :           }
    9002              : 
    9003      6570562 :         return expr;
    9004      6570562 :       }
    9005    802250182 :     case ck_identity:
    9006    802250182 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    9007              :         {
    9008      1170147 :           int nelts = CONSTRUCTOR_NELTS (expr);
    9009       181187 :           if (nelts == 0)
    9010       988960 :             expr = build_value_init (totype, complain);
    9011       181187 :           else if (nelts == 1)
    9012       181187 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    9013              :           else
    9014            0 :             gcc_unreachable ();
    9015              :         }
    9016    802250182 :       expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p,
    9017              :                        /*read_p=*/true, UNKNOWN_LOCATION,
    9018              :                        /*reject_builtin=*/true);
    9019              : 
    9020    802250182 :       if (type_unknown_p (expr))
    9021        35372 :         expr = instantiate_type (totype, expr, complain);
    9022    802250182 :       if (!nested_p && TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9023       105433 :         expr = cp_convert (totype, TREE_OPERAND (expr, 0), complain);
    9024    802250182 :       if (expr == null_node
    9025    802250182 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype))
    9026              :         /* If __null has been converted to an integer type, we do not want to
    9027              :            continue to warn about uses of EXPR as an integer, rather than as a
    9028              :            pointer.  */
    9029       153314 :         expr = build_int_cst (totype, 0);
    9030    802250182 :       return maybe_adjust_type_name (totype, expr, convs->kind);
    9031           53 :     case ck_ambig:
    9032              :       /* We leave bad_p off ck_ambig because overload resolution considers
    9033              :          it valid, it just fails when we try to perform it.  So we need to
    9034              :          check complain here, too.  */
    9035           53 :       if (complain & tf_error)
    9036              :         {
    9037              :           /* Call build_user_type_conversion again for the error.  */
    9038           53 :           auto_diagnostic_group d;
    9039            3 :           int flags = (convs->need_temporary_p
    9040           53 :                        ? LOOKUP_IMPLICIT : LOOKUP_NORMAL);
    9041           53 :           build_user_type_conversion (totype, convs->u.expr, flags, complain);
    9042           53 :           gcc_assert (seen_error ());
    9043           53 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9044           53 :         }
    9045           53 :       return error_mark_node;
    9046              : 
    9047        16193 :     case ck_list:
    9048        16193 :       {
    9049              :         /* Conversion to std::initializer_list<T>.  */
    9050        16193 :         tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (totype), 0);
    9051        16193 :         unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (expr);
    9052        16193 :         tree array;
    9053              : 
    9054        16193 :         if (tree init = maybe_init_list_as_array (elttype, expr))
    9055              :           {
    9056          132 :             elttype
    9057          132 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    9058              :                                                    | TYPE_QUAL_CONST));
    9059          132 :             tree index_type = TYPE_DOMAIN (TREE_TYPE (init));
    9060          132 :             array = build_cplus_array_type (elttype, index_type);
    9061          132 :             len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (index_type)) + 1;
    9062          132 :             array = build_vec_init_expr (array, init, complain);
    9063          132 :             array = get_target_expr (array);
    9064          132 :             array = cp_build_addr_expr (array, complain);
    9065              :           }
    9066        16061 :         else if (len)
    9067              :           {
    9068        15367 :             tree val;
    9069        15367 :             unsigned ix;
    9070        15367 :             tree new_ctor = build_constructor (init_list_type_node, NULL);
    9071              : 
    9072              :             /* Convert all the elements.  */
    9073       124145 :             FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val)
    9074              :               {
    9075        93426 :                 if (TREE_CODE (val) == RAW_DATA_CST)
    9076              :                   {
    9077              :                     /* For conversion to initializer_list<unsigned char> or
    9078              :                        initializer_list<char> or initializer_list<signed char>
    9079              :                        we can optimize and keep RAW_DATA_CST with adjusted
    9080              :                        type if we report narrowing errors if needed, for
    9081              :                        others this converts each element separately.  */
    9082           48 :                     if (convs->u.list[ix]->kind == ck_std)
    9083              :                       {
    9084           18 :                         tree et = convs->u.list[ix]->type;
    9085           18 :                         conversion *next = next_conversion (convs->u.list[ix]);
    9086           18 :                         gcc_assert (et
    9087              :                                     && (TREE_CODE (et) == INTEGER_TYPE
    9088              :                                         || is_byte_access_type (et))
    9089              :                                     && TYPE_PRECISION (et) == CHAR_BIT
    9090              :                                     && next
    9091              :                                     && next->kind == ck_identity);
    9092           18 :                         if (!TYPE_UNSIGNED (et)
    9093              :                             /* For RAW_DATA_CST, TREE_TYPE (val) can be
    9094              :                                either integer_type_node (when it has been
    9095              :                                created by the lexer from CPP_EMBED) or
    9096              :                                after digestion/conversion some integral
    9097              :                                type with CHAR_BIT precision.  For int with
    9098              :                                precision higher than CHAR_BIT or unsigned char
    9099              :                                diagnose narrowing conversions from
    9100              :                                that int/unsigned char to signed char if any
    9101              :                                byte has most significant bit set.  */
    9102           18 :                             && (TYPE_UNSIGNED (TREE_TYPE (val))
    9103           12 :                                 || (TYPE_PRECISION (TREE_TYPE (val))
    9104              :                                     > CHAR_BIT)))
    9105         2460 :                           for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
    9106              :                             {
    9107         2454 :                               if (RAW_DATA_SCHAR_ELT (val, i) >= 0)
    9108         2448 :                                 continue;
    9109            6 :                               else if (complain & tf_error)
    9110              :                                 {
    9111            6 :                                   location_t loc
    9112            6 :                                     = cp_expr_loc_or_input_loc (val);
    9113            6 :                                   int savederrorcount = errorcount;
    9114           18 :                                   permerror_opt (loc, OPT_Wnarrowing,
    9115              :                                                  "narrowing conversion of "
    9116              :                                                  "%qd from %qH to %qI",
    9117            6 :                                                  RAW_DATA_UCHAR_ELT (val, i),
    9118            6 :                                                  TREE_TYPE (val), et);
    9119            6 :                                   if (errorcount != savederrorcount)
    9120            6 :                                     return error_mark_node;
    9121              :                                 }
    9122              :                               else
    9123            0 :                                 return error_mark_node;
    9124              :                             }
    9125           12 :                         tree sub = copy_node (val);
    9126           12 :                         TREE_TYPE (sub) = et;
    9127           12 :                         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    9128              :                                                 NULL_TREE, sub);
    9129              :                       }
    9130              :                     else
    9131              :                       {
    9132           30 :                         conversion *conv = convs->u.list[ix];
    9133           30 :                         gcc_assert (conv->kind == ck_list);
    9134        15495 :                         for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
    9135              :                           {
    9136        15465 :                             tree elt
    9137        15465 :                               = build_int_cst (TREE_TYPE (val),
    9138        15465 :                                                RAW_DATA_UCHAR_ELT (val, i));
    9139        15465 :                             tree sub
    9140        15465 :                               = convert_like (conv->u.list[i], elt,
    9141              :                                               fn, argnum, false, false,
    9142              :                                               /*nested_p=*/true, complain);
    9143        15465 :                             if (sub == error_mark_node)
    9144              :                               return sub;
    9145        15465 :                             if (!check_narrowing (TREE_TYPE (sub), elt,
    9146              :                                                   complain))
    9147            0 :                               return error_mark_node;
    9148        15465 :                             tree nc = new_ctor;
    9149        15465 :                             CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (nc),
    9150              :                                                     NULL_TREE, sub);
    9151        15465 :                             if (!TREE_CONSTANT (sub))
    9152        11679 :                               TREE_CONSTANT (new_ctor) = false;
    9153              :                           }
    9154              :                       }
    9155           42 :                     len += RAW_DATA_LENGTH (val) - 1;
    9156           42 :                     continue;
    9157           42 :                   }
    9158        93378 :                 tree sub = convert_like (convs->u.list[ix], val, fn,
    9159              :                                          argnum, false, false,
    9160              :                                          /*nested_p=*/true, complain);
    9161        93378 :                 if (sub == error_mark_node)
    9162              :                   return sub;
    9163         1652 :                 if (!BRACE_ENCLOSED_INITIALIZER_P (val)
    9164        93389 :                     && !check_narrowing (TREE_TYPE (sub), val, complain))
    9165            0 :                   return error_mark_node;
    9166        93369 :                 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    9167              :                                         NULL_TREE, sub);
    9168        93369 :                 if (!TREE_CONSTANT (sub))
    9169        11452 :                   TREE_CONSTANT (new_ctor) = false;
    9170              :               }
    9171              :             /* Build up the array.  */
    9172        15352 :             elttype
    9173        15352 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    9174              :                                                    | TYPE_QUAL_CONST));
    9175        15352 :             array = build_array_of_n_type (elttype, len);
    9176        15352 :             array = finish_compound_literal (array, new_ctor, complain);
    9177              :             /* This is dubious now, should be blessed by P2752.  */
    9178        15352 :             DECL_MERGEABLE (TARGET_EXPR_SLOT (array)) = true;
    9179        15352 :             array = cp_build_addr_expr (array, complain);
    9180              :           }
    9181              :         else
    9182          694 :           array = nullptr_node;
    9183              : 
    9184        16178 :         array = cp_convert (build_pointer_type (elttype), array, complain);
    9185        16178 :         if (array == error_mark_node)
    9186              :           return error_mark_node;
    9187              : 
    9188              :         /* Build up the initializer_list object.  Note: fail gracefully
    9189              :            if the object cannot be completed because, for example, no
    9190              :            definition is provided (c++/80956).  */
    9191        16178 :         totype = complete_type_or_maybe_complain (totype, NULL_TREE, complain);
    9192        16178 :         if (!totype)
    9193            0 :           return error_mark_node;
    9194        16178 :         tree field = next_aggregate_field (TYPE_FIELDS (totype));
    9195        16178 :         vec<constructor_elt, va_gc> *vec = NULL;
    9196        16178 :         CONSTRUCTOR_APPEND_ELT (vec, field, array);
    9197        16178 :         field = next_aggregate_field (DECL_CHAIN (field));
    9198        16178 :         CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len));
    9199        16178 :         tree new_ctor = build_constructor (totype, vec);
    9200        16178 :         return get_target_expr (new_ctor, complain);
    9201              :       }
    9202              : 
    9203      1329875 :     case ck_aggr:
    9204      1329875 :       if (TREE_CODE (totype) == COMPLEX_TYPE)
    9205              :         {
    9206        28656 :           tree real = CONSTRUCTOR_ELT (expr, 0)->value;
    9207        28656 :           tree imag = CONSTRUCTOR_ELT (expr, 1)->value;
    9208        28656 :           real = perform_implicit_conversion (TREE_TYPE (totype),
    9209              :                                               real, complain);
    9210        28656 :           imag = perform_implicit_conversion (TREE_TYPE (totype),
    9211              :                                               imag, complain);
    9212        28656 :           expr = build2 (COMPLEX_EXPR, totype, real, imag);
    9213        28656 :           return expr;
    9214              :         }
    9215      1301219 :       expr = reshape_init (totype, expr, complain);
    9216      1301219 :       expr = get_target_expr (digest_init (totype, expr, complain),
    9217              :                                      complain);
    9218      1301219 :       if (expr != error_mark_node)
    9219      1301208 :         TARGET_EXPR_LIST_INIT_P (expr) = true;
    9220              :       return expr;
    9221              : 
    9222    326217823 :     default:
    9223    326217823 :       break;
    9224    326217823 :     };
    9225              : 
    9226    326217823 :   conversion *nc = next_conversion (convs);
    9227    326217823 :   if (convs->kind == ck_ref_bind && nc->kind == ck_qual
    9228         8934 :       && !convs->need_temporary_p)
    9229              :     /* direct_reference_binding might have inserted a ck_qual under
    9230              :        this ck_ref_bind for the benefit of conversion sequence ranking.
    9231              :        Don't actually perform that conversion.  */
    9232         6505 :     nc = next_conversion (nc);
    9233              : 
    9234    588641329 :   expr = convert_like (nc, expr, fn, argnum,
    9235              :                        convs->kind == ck_ref_bind
    9236              :                        ? issue_conversion_warnings : false,
    9237              :                        c_cast_p, /*nested_p=*/true, complain & ~tf_no_cleanup);
    9238    326217823 :   if (expr == error_mark_node)
    9239              :     return error_mark_node;
    9240              : 
    9241    326216993 :   switch (convs->kind)
    9242              :     {
    9243    144856199 :     case ck_rvalue:
    9244    144856199 :       expr = decay_conversion (expr, complain);
    9245    144856199 :       if (expr == error_mark_node)
    9246              :         {
    9247           15 :           if (complain & tf_error)
    9248              :             {
    9249           12 :               auto_diagnostic_group d;
    9250           12 :               maybe_print_user_conv_context (convs);
    9251           12 :               maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9252           12 :             }
    9253           15 :           return error_mark_node;
    9254              :         }
    9255              : 
    9256    144856184 :       if ((complain & tf_warning) && fn
    9257     41725622 :           && warn_suggest_attribute_format)
    9258              :         {
    9259          706 :           tree rhstype = TREE_TYPE (expr);
    9260          706 :           const enum tree_code coder = TREE_CODE (rhstype);
    9261          706 :           const enum tree_code codel = TREE_CODE (totype);
    9262          706 :           if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    9263          250 :               && coder == codel
    9264          956 :               && check_missing_format_attribute (totype, rhstype))
    9265            6 :             warning (OPT_Wsuggest_attribute_format,
    9266              :                      "argument of function call might be a candidate "
    9267              :                      "for a format attribute");
    9268              :         }
    9269              : 
    9270    144856184 :       if (! MAYBE_CLASS_TYPE_P (totype))
    9271    130702779 :         return maybe_adjust_type_name (totype, expr, convs->kind);
    9272              : 
    9273              :       /* Don't introduce copies when passing arguments along to the inherited
    9274              :          constructor.  */
    9275     14153405 :       if (current_function_decl
    9276     11186112 :           && flag_new_inheriting_ctors
    9277     36525149 :           && DECL_INHERITED_CTOR (current_function_decl))
    9278              :         return expr;
    9279              : 
    9280     14148677 :       if (TREE_CODE (expr) == TARGET_EXPR
    9281     14148677 :           && TARGET_EXPR_LIST_INIT_P (expr))
    9282              :         /* Copy-list-initialization doesn't actually involve a copy.  */
    9283              :         return expr;
    9284              : 
    9285              :       /* Fall through.  */
    9286     16214382 :     case ck_base:
    9287     16214382 :       if (convs->kind == ck_base && !convs->need_temporary_p)
    9288              :         {
    9289              :           /* We are going to bind a reference directly to a base-class
    9290              :              subobject of EXPR.  */
    9291              :           /* Build an expression for `*((base*) &expr)'.  */
    9292      1835692 :           expr = convert_to_base (expr, totype,
    9293              :                                   !c_cast_p, /*nonnull=*/true, complain);
    9294      1835692 :           return expr;
    9295              :         }
    9296              : 
    9297              :       /* Copy-initialization where the cv-unqualified version of the source
    9298              :          type is the same class as, or a derived class of, the class of the
    9299              :          destination [is treated as direct-initialization].  [dcl.init] */
    9300     14378690 :       flags = LOOKUP_NORMAL;
    9301              :       /* This conversion is being done in the context of a user-defined
    9302              :          conversion (i.e. the second step of copy-initialization), so
    9303              :          don't allow any more.  */
    9304     14378690 :       if (convs->user_conv_p)
    9305       265117 :         flags |= LOOKUP_NO_CONVERSION;
    9306              :       /* We might be performing a conversion of the argument
    9307              :          to the user-defined conversion, i.e., not a conversion of the
    9308              :          result of the user-defined conversion.  In which case we skip
    9309              :          explicit constructors.  */
    9310     14378690 :       if (convs->copy_init_p)
    9311     14104472 :         flags |= LOOKUP_ONLYCONVERTING;
    9312     14378690 :       expr = build_temp (expr, totype, flags, &diag_kind, complain);
    9313     14378690 :       if (diag_kind != diagnostics::kind::unspecified && complain)
    9314              :         {
    9315           78 :           auto_diagnostic_group d;
    9316           78 :           maybe_print_user_conv_context (convs);
    9317           78 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9318           78 :         }
    9319              : 
    9320     14378690 :       return build_cplus_new (totype, expr, complain);
    9321              : 
    9322     63793545 :     case ck_ref_bind:
    9323     63793545 :       {
    9324     63793545 :         tree ref_type = totype;
    9325              : 
    9326     63793545 :         if (convs->bad_p && !next_conversion (convs)->bad_p)
    9327              :           {
    9328         5185 :             tree extype = TREE_TYPE (expr);
    9329         5185 :             auto_diagnostic_group d;
    9330         5185 :             if (TYPE_REF_IS_RVALUE (ref_type)
    9331         5185 :                 && lvalue_p (expr))
    9332         1646 :               error_at (loc, "cannot bind rvalue reference of type %qH to "
    9333              :                         "lvalue of type %qI", totype, extype);
    9334         6232 :             else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr)
    9335         5034 :                      && !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type)))
    9336              :               {
    9337         1246 :                 conversion *next = next_conversion (convs);
    9338         1246 :                 if (next->kind == ck_std)
    9339              :                   {
    9340           59 :                     next = next_conversion (next);
    9341           59 :                     error_at (loc, "cannot bind non-const lvalue reference of "
    9342              :                               "type %qH to a value of type %qI",
    9343              :                               totype, next->type);
    9344              :                   }
    9345         1187 :                 else if (!CP_TYPE_CONST_P (TREE_TYPE (ref_type)))
    9346          843 :                   error_at (loc, "cannot bind non-const lvalue reference of "
    9347              :                             "type %qH to an rvalue of type %qI", totype, extype);
    9348              :                 else // extype is volatile
    9349          344 :                   error_at (loc, "cannot bind lvalue reference of type "
    9350              :                             "%qH to an rvalue of type %qI", totype,
    9351              :                             extype);
    9352              :               }
    9353         2293 :             else if (!reference_compatible_p (TREE_TYPE (totype), extype))
    9354              :               {
    9355              :                 /* If we're converting from T[] to T[N], don't talk
    9356              :                    about discarding qualifiers.  (Converting from T[N] to
    9357              :                    T[] is allowed by P0388R4.)  */
    9358         2293 :                 if (TREE_CODE (extype) == ARRAY_TYPE
    9359           27 :                     && TYPE_DOMAIN (extype) == NULL_TREE
    9360           15 :                     && TREE_CODE (TREE_TYPE (totype)) == ARRAY_TYPE
    9361         2308 :                     && TYPE_DOMAIN (TREE_TYPE (totype)) != NULL_TREE)
    9362           15 :                   error_at (loc, "cannot bind reference of type %qH to %qI "
    9363              :                             "due to different array bounds", totype, extype);
    9364              :                 else
    9365         2278 :                   error_at (loc, "binding reference of type %qH to %qI "
    9366              :                             "discards qualifiers", totype, extype);
    9367              :               }
    9368              :             else
    9369            0 :               gcc_unreachable ();
    9370         5185 :             maybe_print_user_conv_context (convs);
    9371         5185 :             maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9372              : 
    9373         5185 :             return error_mark_node;
    9374         5185 :           }
    9375     63788360 :         else if (complain & tf_warning)
    9376     38167044 :           maybe_warn_array_conv (loc, convs, expr);
    9377              : 
    9378              :         /* If necessary, create a temporary.
    9379              : 
    9380              :            VA_ARG_EXPR and CONSTRUCTOR expressions are special cases
    9381              :            that need temporaries, even when their types are reference
    9382              :            compatible with the type of reference being bound, so the
    9383              :            upcoming call to cp_build_addr_expr doesn't fail.  */
    9384     63788360 :         if (convs->need_temporary_p
    9385     61245308 :             || TREE_CODE (expr) == CONSTRUCTOR
    9386     61245102 :             || TREE_CODE (expr) == VA_ARG_EXPR)
    9387              :           {
    9388              :             /* Otherwise, a temporary of type "cv1 T1" is created and
    9389              :                initialized from the initializer expression using the rules
    9390              :                for a non-reference copy-initialization (8.5).  */
    9391              : 
    9392      2543258 :             tree type = TREE_TYPE (ref_type);
    9393      2543258 :             cp_lvalue_kind lvalue = lvalue_kind (expr);
    9394              : 
    9395      2543258 :             gcc_assert (similar_type_p (type, next_conversion (convs)->type));
    9396      2543258 :             if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
    9397      3432802 :                 && !TYPE_REF_IS_RVALUE (ref_type))
    9398              :               {
    9399              :                 /* If the reference is volatile or non-const, we
    9400              :                    cannot create a temporary.  */
    9401          105 :                 if (complain & tf_error)
    9402              :                   {
    9403          103 :                     if (lvalue & clk_bitfield)
    9404           30 :                       error_at (loc, "cannot bind bit-field %qE to %qT",
    9405              :                                 expr, ref_type);
    9406           73 :                     else if (lvalue & clk_packed)
    9407            9 :                       error_at (loc, "cannot bind packed field %qE to %qT",
    9408              :                                 expr, ref_type);
    9409              :                     else
    9410           64 :                       error_at (loc, "cannot bind rvalue %qE to %qT",
    9411              :                                 expr, ref_type);
    9412              :                   }
    9413          105 :                 return error_mark_node;
    9414              :               }
    9415              :             /* If the source is a packed field, and we must use a copy
    9416              :                constructor, then building the target expr will require
    9417              :                binding the field to the reference parameter to the
    9418              :                copy constructor, and we'll end up with an infinite
    9419              :                loop.  If we can use a bitwise copy, then we'll be
    9420              :                OK.  */
    9421      2543153 :             if ((lvalue & clk_packed)
    9422           20 :                 && CLASS_TYPE_P (type)
    9423      2543170 :                 && type_has_nontrivial_copy_init (type))
    9424              :               {
    9425            6 :                 error_at (loc, "cannot bind packed field %qE to %qT",
    9426              :                           expr, ref_type);
    9427            6 :                 return error_mark_node;
    9428              :               }
    9429      2543147 :             if (lvalue & clk_bitfield)
    9430              :               {
    9431           24 :                 expr = convert_bitfield_to_declared_type (expr);
    9432           24 :                 expr = fold_convert (type, expr);
    9433              :               }
    9434              : 
    9435              :             /* Creating &TARGET_EXPR<> in a template would break when
    9436              :                tsubsting the expression, so use an IMPLICIT_CONV_EXPR
    9437              :                instead.  This can happen even when there's no class
    9438              :                involved, e.g., when converting an integer to a reference
    9439              :                type.  */
    9440      2543147 :             if (processing_template_decl)
    9441         9695 :               return build1 (IMPLICIT_CONV_EXPR, totype, expr);
    9442      2533452 :             expr = build_target_expr_with_type (expr, type, complain);
    9443              :           }
    9444              : 
    9445              :         /* Take the address of the thing to which we will bind the
    9446              :            reference.  */
    9447     63778554 :         expr = cp_build_addr_expr (expr, complain);
    9448     63778554 :         if (expr == error_mark_node)
    9449              :           return error_mark_node;
    9450              : 
    9451              :         /* Convert it to a pointer to the type referred to by the
    9452              :            reference.  This will adjust the pointer if a derived to
    9453              :            base conversion is being performed.  */
    9454     63778554 :         expr = cp_convert (build_pointer_type (TREE_TYPE (ref_type)),
    9455              :                            expr, complain);
    9456              :         /* Convert the pointer to the desired reference type.  */
    9457     63778554 :         return build_nop (ref_type, expr);
    9458              :       }
    9459              : 
    9460      2938302 :     case ck_lvalue:
    9461      2938302 :       return decay_conversion (expr, complain);
    9462              : 
    9463       242260 :     case ck_fnptr:
    9464              :       /* ??? Should the address of a transaction-safe pointer point to the TM
    9465              :         clone, and this conversion look up the primary function?  */
    9466       242260 :       return build_nop (totype, expr);
    9467              : 
    9468      1646424 :     case ck_qual:
    9469              :       /* Warn about deprecated conversion if appropriate.  */
    9470      1646424 :       if (complain & tf_warning)
    9471              :         {
    9472      1446966 :           string_conv_p (totype, expr, 1);
    9473      1446966 :           maybe_warn_array_conv (loc, convs, expr);
    9474              :         }
    9475              :       break;
    9476              : 
    9477      3065592 :     case ck_ptr:
    9478      3065592 :       if (convs->base_p)
    9479       220073 :         expr = convert_to_base (expr, totype, !c_cast_p,
    9480              :                                 /*nonnull=*/false, complain);
    9481      3065592 :       return build_nop (totype, expr);
    9482              : 
    9483        28915 :     case ck_pmem:
    9484        28915 :       return convert_ptrmem (totype, expr, /*allow_inverse_p=*/false,
    9485        28915 :                              c_cast_p, complain);
    9486              : 
    9487              :     default:
    9488              :       break;
    9489              :     }
    9490              : 
    9491    109199767 :   if (convs->check_narrowing
    9492    109199767 :       && !check_narrowing (totype, expr, complain,
    9493              :                            convs->check_narrowing_const_only))
    9494          449 :     return error_mark_node;
    9495              : 
    9496    218398636 :   warning_sentinel w (warn_zero_as_null_pointer_constant);
    9497    109199318 :   if (issue_conversion_warnings)
    9498     85905995 :     expr = cp_convert_and_check (totype, expr, complain);
    9499              :   else
    9500              :     {
    9501     23293323 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9502           39 :         expr = TREE_OPERAND (expr, 0);
    9503     23293323 :       expr = cp_convert (totype, expr, complain);
    9504              :     }
    9505              : 
    9506    109199318 :   return expr;
    9507              : }
    9508              : 
    9509              : /* Return true if converting FROM to TO is unsafe in a template.  */
    9510              : 
    9511              : static bool
    9512      2023417 : conv_unsafe_in_template_p (tree to, tree from)
    9513              : {
    9514              :   /* Converting classes involves TARGET_EXPR.  */
    9515      2023417 :   if (CLASS_TYPE_P (to) || CLASS_TYPE_P (from))
    9516              :     return true;
    9517              : 
    9518              :   /* Converting real to integer produces FIX_TRUNC_EXPR which tsubst
    9519              :      doesn't handle.  */
    9520      1607860 :   if (SCALAR_FLOAT_TYPE_P (from) && INTEGRAL_OR_ENUMERATION_TYPE_P (to))
    9521              :     return true;
    9522              : 
    9523              :   /* Converting integer to real isn't a trivial conversion, either.  */
    9524      1607857 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (from) && SCALAR_FLOAT_TYPE_P (to))
    9525            3 :     return true;
    9526              : 
    9527              :   return false;
    9528              : }
    9529              : 
    9530              : /* Wrapper for convert_like_internal that handles creating
    9531              :    IMPLICIT_CONV_EXPR.  */
    9532              : 
    9533              : static tree
    9534   1136998694 : convert_like (conversion *convs, tree expr, tree fn, int argnum,
    9535              :               bool issue_conversion_warnings, bool c_cast_p, bool nested_p,
    9536              :               tsubst_flags_t complain)
    9537              : {
    9538              :   /* Creating &TARGET_EXPR<> in a template breaks when substituting,
    9539              :      and creating a CALL_EXPR in a template breaks in finish_call_expr
    9540              :      so use an IMPLICIT_CONV_EXPR for this conversion.  We would have
    9541              :      created such codes e.g. when calling a user-defined conversion
    9542              :      function.  */
    9543   1136998694 :   tree conv_expr = NULL_TREE;
    9544   1136998694 :   if (processing_template_decl
    9545    115137748 :       && convs->kind != ck_identity
    9546   1139022111 :       && conv_unsafe_in_template_p (convs->type, TREE_TYPE (expr)))
    9547              :     {
    9548       415563 :       conv_expr = build1 (IMPLICIT_CONV_EXPR, convs->type, expr);
    9549       415563 :       if (convs->kind != ck_ref_bind)
    9550        29113 :         conv_expr = convert_from_reference (conv_expr);
    9551       415563 :       if (!convs->bad_p)
    9552              :         return conv_expr;
    9553              :       /* Do the normal processing to give the bad_p errors.  But we still
    9554              :          need to return the IMPLICIT_CONV_EXPR, unless we're returning
    9555              :          error_mark_node.  */
    9556              :     }
    9557   1136583140 :   expr = convert_like_internal (convs, expr, fn, argnum,
    9558              :                                 issue_conversion_warnings, c_cast_p,
    9559              :                                 nested_p, complain);
    9560   1136583140 :   if (expr == error_mark_node)
    9561              :     return error_mark_node;
    9562   1136528140 :   return conv_expr ? conv_expr : expr;
    9563              : }
    9564              : 
    9565              : /* Convenience wrapper for convert_like.  */
    9566              : 
    9567              : static inline tree
    9568    632615056 : convert_like (conversion *convs, tree expr, tsubst_flags_t complain)
    9569              : {
    9570    632615056 :   return convert_like (convs, expr, NULL_TREE, 0,
    9571              :                        /*issue_conversion_warnings=*/true,
    9572    632615056 :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9573              : }
    9574              : 
    9575              : /* Convenience wrapper for convert_like.  */
    9576              : 
    9577              : static inline tree
    9578    137523436 : convert_like_with_context (conversion *convs, tree expr, tree fn, int argnum,
    9579              :                            tsubst_flags_t complain)
    9580              : {
    9581            0 :   return convert_like (convs, expr, fn, argnum,
    9582              :                        /*issue_conversion_warnings=*/true,
    9583              :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9584              : }
    9585              : 
    9586              : /* ARG is being passed to a varargs function.  Perform any conversions
    9587              :    required.  Return the converted value.  */
    9588              : 
    9589              : tree
    9590      1448256 : convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
    9591              : {
    9592      1448256 :   tree arg_type = TREE_TYPE (arg);
    9593      1448256 :   location_t loc = cp_expr_loc_or_input_loc (arg);
    9594              : 
    9595              :   /* [expr.call]
    9596              : 
    9597              :      If the argument has integral or enumeration type that is subject
    9598              :      to the integral promotions (_conv.prom_), or a floating-point
    9599              :      type that is subject to the floating-point promotion
    9600              :      (_conv.fpprom_), the value of the argument is converted to the
    9601              :      promoted type before the call.  */
    9602      1448256 :   if (SCALAR_FLOAT_TYPE_P (arg_type)
    9603        48734 :       && (TYPE_PRECISION (arg_type)
    9604        48734 :           < TYPE_PRECISION (double_type_node))
    9605        12066 :       && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (arg_type))
    9606      1459644 :       && !extended_float_type_p (arg_type))
    9607              :     {
    9608        11382 :       if ((complain & tf_warning)
    9609        11379 :           && warn_double_promotion && !c_inhibit_evaluation_warnings)
    9610            3 :         warning_at (loc, OPT_Wdouble_promotion,
    9611              :                     "implicit conversion from %qH to %qI when passing "
    9612              :                     "argument to function",
    9613              :                     arg_type, double_type_node);
    9614        11382 :       if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    9615            3 :         arg = TREE_OPERAND (arg, 0);
    9616        11382 :       arg = mark_rvalue_use (arg);
    9617        11382 :       arg = convert_to_real_nofold (double_type_node, arg);
    9618              :     }
    9619      1436874 :   else if (NULLPTR_TYPE_P (arg_type))
    9620              :     {
    9621           80 :       arg = mark_rvalue_use (arg);
    9622           80 :       if (TREE_SIDE_EFFECTS (arg))
    9623              :         {
    9624            6 :           warning_sentinel w(warn_unused_result);
    9625            6 :           arg = cp_build_compound_expr (arg, null_pointer_node, complain);
    9626            6 :         }
    9627              :       else
    9628           74 :         arg = null_pointer_node;
    9629              :     }
    9630      1436794 :   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type))
    9631              :     {
    9632       940040 :       if (SCOPED_ENUM_P (arg_type))
    9633              :         {
    9634           64 :           tree prom = cp_convert (ENUM_UNDERLYING_TYPE (arg_type), arg,
    9635              :                                   complain);
    9636           64 :           prom = cp_perform_integral_promotions (prom, complain);
    9637          125 :           if (abi_version_crosses (6)
    9638           30 :               && TYPE_MODE (TREE_TYPE (prom)) != TYPE_MODE (arg_type)
    9639           94 :               && (complain & tf_warning))
    9640           60 :             warning_at (loc, OPT_Wabi, "scoped enum %qT passed through %<...%>"
    9641              :                         " as %qT before %<-fabi-version=6%>, %qT after",
    9642              :                         arg_type,
    9643           30 :                         TREE_TYPE (prom), ENUM_UNDERLYING_TYPE (arg_type));
    9644           64 :           if (!abi_version_at_least (6))
    9645      1448256 :             arg = prom;
    9646              :         }
    9647              :       else
    9648       939976 :         arg = cp_perform_integral_promotions (arg, complain);
    9649              :     }
    9650              :   else
    9651              :     /* [expr.call]
    9652              : 
    9653              :        The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
    9654              :        standard conversions are performed.  */
    9655       496754 :     arg = decay_conversion (arg, complain);
    9656              : 
    9657      1448256 :   arg = require_complete_type (arg, complain);
    9658      1448256 :   arg_type = TREE_TYPE (arg);
    9659              : 
    9660      1448256 :   if (arg != error_mark_node
    9661              :       /* In a template (or ill-formed code), we can have an incomplete type
    9662              :          even after require_complete_type, in which case we don't know
    9663              :          whether it has trivial copy or not.  */
    9664      1448244 :       && COMPLETE_TYPE_P (arg_type)
    9665      2896500 :       && !cp_unevaluated_operand)
    9666              :     {
    9667              :       /* [expr.call] 5.2.2/7:
    9668              :          Passing a potentially-evaluated argument of class type (Clause 9)
    9669              :          with a non-trivial copy constructor or a non-trivial destructor
    9670              :          with no corresponding parameter is conditionally-supported, with
    9671              :          implementation-defined semantics.
    9672              : 
    9673              :          We support it as pass-by-invisible-reference, just like a normal
    9674              :          value parameter.
    9675              : 
    9676              :          If the call appears in the context of a sizeof expression,
    9677              :          it is not potentially-evaluated.  */
    9678       700154 :       if (type_has_nontrivial_copy_init (arg_type)
    9679       700154 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))
    9680              :         {
    9681           37 :           arg = force_rvalue (arg, complain);
    9682           37 :           if (complain & tf_warning)
    9683           37 :             warning (OPT_Wconditionally_supported,
    9684              :                      "passing objects of non-trivially-copyable "
    9685              :                      "type %q#T through %<...%> is conditionally supported",
    9686              :                      arg_type);
    9687           37 :           return build1 (ADDR_EXPR, build_reference_type (arg_type), arg);
    9688              :         }
    9689              :       /* Build up a real lvalue-to-rvalue conversion in case the
    9690              :          copy constructor is trivial but not callable.  */
    9691       700117 :       else if (CLASS_TYPE_P (arg_type))
    9692        44258 :         force_rvalue (arg, complain);
    9693              : 
    9694              :     }
    9695              : 
    9696              :   return arg;
    9697              : }
    9698              : 
    9699              : /* va_arg (EXPR, TYPE) is a builtin. Make sure it is not abused.  */
    9700              : 
    9701              : tree
    9702        31298 : build_x_va_arg (location_t loc, tree expr, tree type)
    9703              : {
    9704        31298 :   if (processing_template_decl)
    9705              :     {
    9706           39 :       tree r = build_min (VA_ARG_EXPR, type, expr);
    9707           39 :       SET_EXPR_LOCATION (r, loc);
    9708           39 :       return r;
    9709              :     }
    9710              : 
    9711        31259 :   type = complete_type_or_else (type, NULL_TREE);
    9712              : 
    9713        31259 :   if (expr == error_mark_node || !type)
    9714              :     return error_mark_node;
    9715              : 
    9716        31238 :   expr = mark_lvalue_use (expr);
    9717              : 
    9718        31238 :   if (TYPE_REF_P (type))
    9719              :     {
    9720            6 :       error ("cannot receive reference type %qT through %<...%>", type);
    9721            6 :       return error_mark_node;
    9722              :     }
    9723              : 
    9724        31232 :   if (type_has_nontrivial_copy_init (type)
    9725        31232 :       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    9726              :     {
    9727              :       /* conditionally-supported behavior [expr.call] 5.2.2/7.  Let's treat
    9728              :          it as pass by invisible reference.  */
    9729           12 :       warning_at (loc, OPT_Wconditionally_supported,
    9730              :                  "receiving objects of non-trivially-copyable type %q#T "
    9731              :                  "through %<...%> is conditionally-supported", type);
    9732              : 
    9733           12 :       tree ref = cp_build_reference_type (type, false);
    9734           12 :       expr = build_va_arg (loc, expr, ref);
    9735           12 :       return convert_from_reference (expr);
    9736              :     }
    9737              : 
    9738        31220 :   tree ret = build_va_arg (loc, expr, type);
    9739        31220 :   if (CLASS_TYPE_P (type))
    9740              :     /* Wrap the VA_ARG_EXPR in a TARGET_EXPR now so other code doesn't need to
    9741              :        know how to handle it.  */
    9742        12094 :     ret = get_target_expr (ret);
    9743              :   return ret;
    9744              : }
    9745              : 
    9746              : /* TYPE has been given to va_arg.  Apply the default conversions which
    9747              :    would have happened when passed via ellipsis.  Return the promoted
    9748              :    type, or the passed type if there is no change.  */
    9749              : 
    9750              : tree
    9751      2723619 : cxx_type_promotes_to (tree type)
    9752              : {
    9753      2723619 :   tree promote;
    9754              : 
    9755              :   /* Perform the array-to-pointer and function-to-pointer
    9756              :      conversions.  */
    9757      2723619 :   type = type_decays_to (type);
    9758              : 
    9759      2723619 :   promote = type_promotes_to (type);
    9760      2723619 :   if (same_type_p (type, promote))
    9761      2723595 :     promote = type;
    9762              : 
    9763      2723619 :   return promote;
    9764              : }
    9765              : 
    9766              : /* ARG is a default argument expression being passed to a parameter of
    9767              :    the indicated TYPE, which is a parameter to FN.  PARMNUM is the
    9768              :    zero-based argument number.  Do any required conversions.  Return
    9769              :    the converted value.  */
    9770              : 
    9771              : static GTY(()) vec<tree, va_gc> *default_arg_context;
    9772              : void
    9773      8086156 : push_defarg_context (tree fn)
    9774      8086156 : { vec_safe_push (default_arg_context, fn); }
    9775              : 
    9776              : void
    9777      8086156 : pop_defarg_context (void)
    9778      8086156 : { default_arg_context->pop (); }
    9779              : 
    9780              : tree
    9781      1150575 : convert_default_arg (tree type, tree arg, tree fn, int parmnum,
    9782              :                      tsubst_flags_t complain)
    9783              : {
    9784      1150575 :   int i;
    9785      1150575 :   tree t;
    9786              : 
    9787              :   /* See through clones.  */
    9788      1150575 :   fn = DECL_ORIGIN (fn);
    9789              :   /* And inheriting ctors.  */
    9790      1150575 :   if (flag_new_inheriting_ctors)
    9791      1149935 :     fn = strip_inheriting_ctors (fn);
    9792              : 
    9793              :   /* Detect recursion.  */
    9794      1154046 :   FOR_EACH_VEC_SAFE_ELT (default_arg_context, i, t)
    9795         3477 :     if (t == fn)
    9796              :       {
    9797            6 :         if (complain & tf_error)
    9798            6 :           error ("recursive evaluation of default argument for %q#D", fn);
    9799            6 :         return error_mark_node;
    9800              :       }
    9801              : 
    9802              :   /* If the ARG is an unparsed default argument expression, the
    9803              :      conversion cannot be performed.  */
    9804      1150569 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
    9805              :     {
    9806           15 :       if (complain & tf_error)
    9807           15 :         error ("call to %qD uses the default argument for parameter %P, which "
    9808              :                "is not yet defined", fn, parmnum);
    9809           15 :       return error_mark_node;
    9810              :     }
    9811              : 
    9812      1150554 :   push_defarg_context (fn);
    9813              : 
    9814      1150554 :   if (fn && DECL_TEMPLATE_INFO (fn))
    9815       845937 :     arg = tsubst_default_argument (fn, parmnum, type, arg, complain);
    9816              : 
    9817              :   /* Due to:
    9818              : 
    9819              :        [dcl.fct.default]
    9820              : 
    9821              :        The names in the expression are bound, and the semantic
    9822              :        constraints are checked, at the point where the default
    9823              :        expressions appears.
    9824              : 
    9825              :      we must not perform access checks here.  */
    9826      1150554 :   push_deferring_access_checks (dk_no_check);
    9827              :   /* We must make a copy of ARG, in case subsequent processing
    9828              :      alters any part of it.  */
    9829      1150554 :   arg = break_out_target_exprs (arg, /*clear location*/true);
    9830              : 
    9831      1150554 :   arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT,
    9832              :                                     ICR_DEFAULT_ARGUMENT, fn, parmnum,
    9833              :                                     complain);
    9834      1150554 :   arg = convert_for_arg_passing (type, arg, complain);
    9835      1150554 :   pop_deferring_access_checks();
    9836              : 
    9837      1150554 :   pop_defarg_context ();
    9838              : 
    9839      1150554 :   return arg;
    9840              : }
    9841              : 
    9842              : /* Returns the type which will really be used for passing an argument of
    9843              :    type TYPE.  */
    9844              : 
    9845              : tree
    9846    680156741 : type_passed_as (tree type)
    9847              : {
    9848              :   /* Pass classes with copy ctors by invisible reference.  */
    9849    680156741 :   if (TREE_ADDRESSABLE (type))
    9850       629731 :     type = build_reference_type (type);
    9851              : 
    9852    680156741 :   return type;
    9853              : }
    9854              : 
    9855              : /* Actually perform the appropriate conversion.  */
    9856              : 
    9857              : tree
    9858    143580031 : convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain)
    9859              : {
    9860    143580031 :   tree bitfield_type;
    9861              : 
    9862              :   /* If VAL is a bitfield, then -- since it has already been converted
    9863              :      to TYPE -- it cannot have a precision greater than TYPE.
    9864              : 
    9865              :      If it has a smaller precision, we must widen it here.  For
    9866              :      example, passing "int f:3;" to a function expecting an "int" will
    9867              :      not result in any conversion before this point.
    9868              : 
    9869              :      If the precision is the same we must not risk widening.  For
    9870              :      example, the COMPONENT_REF for a 32-bit "long long" bitfield will
    9871              :      often have type "int", even though the C++ type for the field is
    9872              :      "long long".  If the value is being passed to a function
    9873              :      expecting an "int", then no conversions will be required.  But,
    9874              :      if we call convert_bitfield_to_declared_type, the bitfield will
    9875              :      be converted to "long long".  */
    9876    143580031 :   bitfield_type = is_bitfield_expr_with_lowered_type (val);
    9877    143580031 :   if (bitfield_type
    9878    143580031 :       && TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type))
    9879            0 :     val = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type), val);
    9880              : 
    9881    143580031 :   if (val == error_mark_node)
    9882              :     ;
    9883              :   /* Pass classes with copy ctors by invisible reference.  */
    9884    143576330 :   else if (TREE_ADDRESSABLE (type))
    9885       213938 :     val = build1 (ADDR_EXPR, build_reference_type (type), val);
    9886    143580031 :   if (complain & tf_warning)
    9887    131826452 :     maybe_warn_parm_abi (type, cp_expr_loc_or_input_loc (val));
    9888              : 
    9889    105953620 :   if (complain & tf_warning)
    9890    105953620 :     warn_for_address_of_packed_member (type, val);
    9891              : 
    9892              :   /* gimplify_arg elides TARGET_EXPRs that initialize a function argument,
    9893              :      unless the initializer is a CONSTRUCTOR.  In that case, we fail to
    9894              :      elide the copy anyway.  See that function for more information.  */
    9895      7934441 :   if (SIMPLE_TARGET_EXPR_P (val)
    9896    150082311 :       && TREE_CODE (TARGET_EXPR_INITIAL (val)) != CONSTRUCTOR)
    9897      3826615 :     set_target_expr_eliding (val);
    9898              : 
    9899    143580031 :   return val;
    9900              : }
    9901              : 
    9902              : /* Returns non-zero iff FN is a function with magic varargs, i.e. ones for
    9903              :    which just decay_conversion or no conversions at all should be done.
    9904              :    This is true for some builtins which don't act like normal functions.
    9905              :    Return 2 if just decay_conversion and removal of excess precision should
    9906              :    be done, 1 if just decay_conversion.  Return 3 for special treatment of
    9907              :    the 3rd argument for __builtin_*_overflow_p.  Return 4 for special
    9908              :    treatment of the 1st argument for
    9909              :    __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g.  */
    9910              : 
    9911              : int
    9912    175219217 : magic_varargs_p (tree fn)
    9913              : {
    9914    175219217 :   if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
    9915      6113813 :     switch (DECL_FUNCTION_CODE (fn))
    9916              :       {
    9917              :       case BUILT_IN_CLASSIFY_TYPE:
    9918              :       case BUILT_IN_CONSTANT_P:
    9919              :       case BUILT_IN_NEXT_ARG:
    9920              :       case BUILT_IN_VA_START:
    9921              :         return 1;
    9922              : 
    9923        20842 :       case BUILT_IN_ADD_OVERFLOW_P:
    9924        20842 :       case BUILT_IN_SUB_OVERFLOW_P:
    9925        20842 :       case BUILT_IN_MUL_OVERFLOW_P:
    9926        20842 :         return 3;
    9927              : 
    9928       320970 :       case BUILT_IN_ISFINITE:
    9929       320970 :       case BUILT_IN_ISINF:
    9930       320970 :       case BUILT_IN_ISINF_SIGN:
    9931       320970 :       case BUILT_IN_ISNAN:
    9932       320970 :       case BUILT_IN_ISNORMAL:
    9933       320970 :       case BUILT_IN_FPCLASSIFY:
    9934       320970 :         return 2;
    9935              : 
    9936       101729 :       case BUILT_IN_CLZG:
    9937       101729 :       case BUILT_IN_CTZG:
    9938       101729 :       case BUILT_IN_CLRSBG:
    9939       101729 :       case BUILT_IN_FFSG:
    9940       101729 :       case BUILT_IN_PARITYG:
    9941       101729 :       case BUILT_IN_POPCOUNTG:
    9942       101729 :         return 4;
    9943              : 
    9944      5462951 :       default:
    9945      5462951 :         return lookup_attribute ("type generic",
    9946     10925902 :                                  TYPE_ATTRIBUTES (TREE_TYPE (fn))) != 0;
    9947              :       }
    9948              : 
    9949              :   return 0;
    9950              : }
    9951              : 
    9952              : /* Returns the decl of the dispatcher function if FN is a function version.  */
    9953              : 
    9954              : tree
    9955          240 : get_function_version_dispatcher (tree fn)
    9956              : {
    9957          240 :   tree dispatcher_decl = NULL;
    9958              : 
    9959          240 :   if (DECL_LOCAL_DECL_P (fn))
    9960            9 :     fn = DECL_LOCAL_DECL_ALIAS (fn);
    9961              : 
    9962          240 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
    9963              :               && DECL_FUNCTION_VERSIONED (fn));
    9964              : 
    9965          240 :   gcc_assert (targetm.get_function_versions_dispatcher);
    9966          240 :   dispatcher_decl = targetm.get_function_versions_dispatcher (fn);
    9967              : 
    9968          240 :   if (dispatcher_decl == NULL)
    9969              :     {
    9970            9 :       error_at (input_location, "use of multiversioned function "
    9971              :                                 "without a default");
    9972            9 :       return NULL;
    9973              :     }
    9974              : 
    9975          231 :   retrofit_lang_decl (dispatcher_decl);
    9976          231 :   gcc_assert (dispatcher_decl != NULL);
    9977              :   return dispatcher_decl;
    9978              : }
    9979              : 
    9980              : /* fn is a function version dispatcher that is marked used. Mark all the
    9981              :    semantically identical function versions it will dispatch as used.  */
    9982              : 
    9983              : void
    9984          159 : mark_versions_used (tree fn)
    9985              : {
    9986          159 :   struct cgraph_node *node;
    9987          159 :   struct cgraph_function_version_info *node_v;
    9988          159 :   struct cgraph_function_version_info *it_v;
    9989              : 
    9990          159 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    9991              : 
    9992          159 :   node = cgraph_node::get (fn);
    9993          159 :   if (node == NULL)
    9994              :     return;
    9995              : 
    9996          159 :   gcc_assert (node->dispatcher_function);
    9997              : 
    9998          159 :   node_v = node->function_version ();
    9999          159 :   if (node_v == NULL)
   10000              :     return;
   10001              : 
   10002              :   /* All semantically identical versions are chained.  Traverse and mark each
   10003              :      one of them as used.  */
   10004          159 :   it_v = node_v->next;
   10005         1146 :   while (it_v != NULL)
   10006              :     {
   10007          987 :       mark_used (it_v->this_node->decl);
   10008          987 :       it_v = it_v->next;
   10009              :     }
   10010              : }
   10011              : 
   10012              : /* Build a call to "the copy constructor" for the type of A, even if it
   10013              :    wouldn't be selected by normal overload resolution.  Used for
   10014              :    diagnostics.  */
   10015              : 
   10016              : static tree
   10017            3 : call_copy_ctor (tree a, tsubst_flags_t complain)
   10018              : {
   10019            3 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (a));
   10020            3 :   tree binfo = TYPE_BINFO (ctype);
   10021            3 :   tree copy = get_copy_ctor (ctype, complain);
   10022            3 :   copy = build_baselink (binfo, binfo, copy, NULL_TREE);
   10023            3 :   tree ob = build_dummy_object (ctype);
   10024            3 :   releasing_vec args (make_tree_vector_single (a));
   10025            3 :   tree r = build_new_method_call (ob, copy, &args, NULL_TREE,
   10026              :                                   LOOKUP_NORMAL, NULL, complain);
   10027            3 :   return r;
   10028            3 : }
   10029              : 
   10030              : /* Return the base constructor corresponding to COMPLETE_CTOR or NULL_TREE.  */
   10031              : 
   10032              : static tree
   10033           48 : base_ctor_for (tree complete_ctor)
   10034              : {
   10035           48 :   tree clone;
   10036           48 :   FOR_EACH_CLONE (clone, DECL_CLONED_FUNCTION (complete_ctor))
   10037           48 :     if (DECL_BASE_CONSTRUCTOR_P (clone))
   10038              :       return clone;
   10039              :   return NULL_TREE;
   10040              : }
   10041              : 
   10042              : /* Try to make EXP suitable to be used as the initializer for a base subobject,
   10043              :    and return whether we were successful.  EXP must have already been cleared
   10044              :    by unsafe_copy_elision_p{,_opt}.  */
   10045              : 
   10046              : static bool
   10047          224 : make_base_init_ok (tree exp)
   10048              : {
   10049          224 :   if (TREE_CODE (exp) == TARGET_EXPR)
   10050          224 :     exp = TARGET_EXPR_INITIAL (exp);
   10051          227 :   while (TREE_CODE (exp) == COMPOUND_EXPR)
   10052            3 :     exp = TREE_OPERAND (exp, 1);
   10053          224 :   if (TREE_CODE (exp) == COND_EXPR)
   10054              :     {
   10055            3 :       bool ret = make_base_init_ok (TREE_OPERAND (exp, 2));
   10056            3 :       if (tree op1 = TREE_OPERAND (exp, 1))
   10057              :         {
   10058            3 :           bool r1 = make_base_init_ok (op1);
   10059              :           /* If unsafe_copy_elision_p was false, the arms should match.  */
   10060            3 :           gcc_assert (r1 == ret);
   10061              :         }
   10062              :       return ret;
   10063              :     }
   10064          221 :   if (TREE_CODE (exp) != AGGR_INIT_EXPR)
   10065              :     /* A trivial copy is OK.  */
   10066              :     return true;
   10067           70 :   if (!AGGR_INIT_VIA_CTOR_P (exp))
   10068              :     /* unsafe_copy_elision_p_opt must have said this is OK.  */
   10069              :     return true;
   10070           48 :   tree fn = cp_get_callee_fndecl_nofold (exp);
   10071           48 :   if (DECL_BASE_CONSTRUCTOR_P (fn))
   10072              :     return true;
   10073           48 :   gcc_assert (DECL_COMPLETE_CONSTRUCTOR_P (fn));
   10074           48 :   fn = base_ctor_for (fn);
   10075           48 :   if (!fn || DECL_HAS_VTT_PARM_P (fn))
   10076              :     /* The base constructor has more parameters, so we can't just change the
   10077              :        call target.  It would be possible to splice in the appropriate
   10078              :        arguments, but probably not worth the complexity.  */
   10079              :     return false;
   10080           39 :   mark_used (fn);
   10081           39 :   AGGR_INIT_EXPR_FN (exp) = build_address (fn);
   10082           39 :   return true;
   10083              : }
   10084              : 
   10085              : /* Return 2 if T refers to a base, 1 if a potentially-overlapping field,
   10086              :    neither of which can be used for return by invisible reference.  We avoid
   10087              :    doing C++17 mandatory copy elision for either of these cases.
   10088              : 
   10089              :    This returns non-zero even if the type of T has no tail padding that other
   10090              :    data could be allocated into, because that depends on the particular ABI.
   10091              :    unsafe_copy_elision_p_opt does consider whether there is padding.  */
   10092              : 
   10093              : int
   10094     43119808 : unsafe_return_slot_p (tree t)
   10095              : {
   10096              :   /* Check empty bases separately, they don't have fields.  */
   10097     43119808 :   if (is_empty_base_ref (t))
   10098              :     return 2;
   10099              : 
   10100              :   /* A delegating constructor might be used to initialize a base.  */
   10101     42632903 :   if (current_function_decl
   10102     57824812 :       && DECL_CONSTRUCTOR_P (current_function_decl)
   10103     46883124 :       && (t == current_class_ref
   10104      4078167 :           || tree_strip_nop_conversions (t) == current_class_ptr))
   10105              :     return 2;
   10106              : 
   10107     42410117 :   STRIP_NOPS (t);
   10108     42410117 :   if (TREE_CODE (t) == ADDR_EXPR)
   10109        67096 :     t = TREE_OPERAND (t, 0);
   10110     42410117 :   if (TREE_CODE (t) == COMPONENT_REF)
   10111      3561853 :     t = TREE_OPERAND (t, 1);
   10112     42410117 :   if (TREE_CODE (t) != FIELD_DECL)
   10113              :     return false;
   10114      3608307 :   if (!CLASS_TYPE_P (TREE_TYPE (t)))
   10115              :     /* The middle-end will do the right thing for scalar types.  */
   10116              :     return false;
   10117      3067296 :   if (DECL_FIELD_IS_BASE (t))
   10118              :     return 2;
   10119      2242223 :   if (lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (t)))
   10120       164709 :     return 1;
   10121              :   return 0;
   10122              : }
   10123              : 
   10124              : /* True IFF EXP is a prvalue that represents return by invisible reference.  */
   10125              : 
   10126              : static bool
   10127       287226 : init_by_return_slot_p (tree exp)
   10128              : {
   10129              :   /* Copy elision only happens with a TARGET_EXPR.  */
   10130       287229 :   if (TREE_CODE (exp) != TARGET_EXPR)
   10131              :     return false;
   10132        15603 :   tree init = TARGET_EXPR_INITIAL (exp);
   10133              :   /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR.  */
   10134        15609 :   while (TREE_CODE (init) == COMPOUND_EXPR)
   10135            6 :     init = TREE_OPERAND (init, 1);
   10136        15603 :   if (TREE_CODE (init) == COND_EXPR)
   10137              :     {
   10138              :       /* We'll end up copying from each of the arms of the COND_EXPR directly
   10139              :          into the target, so look at them.  */
   10140            6 :       if (tree op = TREE_OPERAND (init, 1))
   10141            6 :         if (init_by_return_slot_p (op))
   10142              :           return true;
   10143            3 :       return init_by_return_slot_p (TREE_OPERAND (init, 2));
   10144              :     }
   10145        15597 :   return (TREE_CODE (init) == AGGR_INIT_EXPR
   10146        15597 :           && !AGGR_INIT_VIA_CTOR_P (init));
   10147              : }
   10148              : 
   10149              : /* We can't elide a copy from a function returning by value to a
   10150              :    potentially-overlapping subobject, as the callee might clobber tail padding.
   10151              :    Return true iff this could be that case.
   10152              : 
   10153              :    Places that use this function (or _opt) to decide to elide a copy should
   10154              :    probably use make_safe_copy_elision instead.  */
   10155              : 
   10156              : bool
   10157      2437822 : unsafe_copy_elision_p (tree target, tree exp)
   10158              : {
   10159      2437822 :   return unsafe_return_slot_p (target) && init_by_return_slot_p (exp);
   10160              : }
   10161              : 
   10162              : /* As above, but for optimization allow more cases that are actually safe.  */
   10163              : 
   10164              : static bool
   10165      8279396 : unsafe_copy_elision_p_opt (tree target, tree exp)
   10166              : {
   10167      8279396 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
   10168              :   /* It's safe to elide the copy for a class with no tail padding.  */
   10169      8279396 :   if (!is_empty_class (type)
   10170      8279396 :       && tree_int_cst_equal (TYPE_SIZE (type), CLASSTYPE_SIZE (type)))
   10171              :     return false;
   10172      2391368 :   return unsafe_copy_elision_p (target, exp);
   10173              : }
   10174              : 
   10175              : /* Try to make EXP suitable to be used as the initializer for TARGET,
   10176              :    and return whether we were successful.  */
   10177              : 
   10178              : bool
   10179           22 : make_safe_copy_elision (tree target, tree exp)
   10180              : {
   10181           22 :   int uns = unsafe_return_slot_p (target);
   10182           22 :   if (!uns)
   10183              :     return true;
   10184           22 :   if (init_by_return_slot_p (exp))
   10185              :     return false;
   10186           22 :   if (uns == 1)
   10187              :     return true;
   10188           22 :   return make_base_init_ok (exp);
   10189              : }
   10190              : 
   10191              : /* True IFF the result of the conversion C is a prvalue.  */
   10192              : 
   10193              : static bool
   10194     14360178 : conv_is_prvalue (conversion *c)
   10195              : {
   10196     14360178 :   if (c->kind == ck_rvalue)
   10197              :     return true;
   10198     14360178 :   if (c->kind == ck_base && c->need_temporary_p)
   10199              :     return true;
   10200     14360178 :   if (c->kind == ck_user && !TYPE_REF_P (c->type))
   10201              :     return true;
   10202     14224950 :   if (c->kind == ck_identity && c->u.expr
   10203     13970948 :       && TREE_CODE (c->u.expr) == TARGET_EXPR)
   10204           69 :     return true;
   10205              : 
   10206              :   return false;
   10207              : }
   10208              : 
   10209              : /* True iff C is a conversion that binds a reference to a prvalue.  */
   10210              : 
   10211              : static bool
   10212     14361480 : conv_binds_ref_to_prvalue (conversion *c)
   10213              : {
   10214     14361480 :   if (c->kind != ck_ref_bind)
   10215              :     return false;
   10216     14361480 :   if (c->need_temporary_p)
   10217              :     return true;
   10218              : 
   10219     14360178 :   return conv_is_prvalue (next_conversion (c));
   10220              : }
   10221              : 
   10222              : /* True iff EXPR represents a (subobject of a) temporary.  */
   10223              : 
   10224              : static bool
   10225        14977 : expr_represents_temporary_p (tree expr)
   10226              : {
   10227        15081 :   while (handled_component_p (expr))
   10228          104 :     expr = TREE_OPERAND (expr, 0);
   10229        14977 :   return TREE_CODE (expr) == TARGET_EXPR;
   10230              : }
   10231              : 
   10232              : /* True iff C is a conversion that binds a reference to a temporary.
   10233              :    This is a superset of conv_binds_ref_to_prvalue: here we're also
   10234              :    interested in xvalues.  */
   10235              : 
   10236              : static bool
   10237        14320 : conv_binds_ref_to_temporary (conversion *c)
   10238              : {
   10239        14320 :   if (conv_binds_ref_to_prvalue (c))
   10240              :     return true;
   10241        13833 :   if (c->kind != ck_ref_bind)
   10242              :     return false;
   10243        13833 :   c = next_conversion (c);
   10244              :   /* This is the case for
   10245              :        struct Base {};
   10246              :        struct Derived : Base {};
   10247              :        const Base& b(Derived{});
   10248              :      where we bind 'b' to the Base subobject of a temporary object of type
   10249              :      Derived.  The subobject is an xvalue; the whole object is a prvalue.
   10250              : 
   10251              :      The ck_base doesn't have to be present for cases like X{}.m.  */
   10252        13833 :   if (c->kind == ck_base)
   10253           14 :     c = next_conversion (c);
   10254        13754 :   if (c->kind == ck_identity && c->u.expr
   10255        27587 :       && expr_represents_temporary_p (c->u.expr))
   10256              :     return true;
   10257              :   return false;
   10258              : }
   10259              : 
   10260              : /* Return tristate::TS_TRUE if converting EXPR to a reference type TYPE binds
   10261              :    the reference to a temporary.  Return tristate::TS_FALSE if converting
   10262              :    EXPR to a reference type TYPE doesn't bind the reference to a temporary.  If
   10263              :    the conversion is invalid or bad, return tristate::TS_UNKNOWN.  DIRECT_INIT_P
   10264              :    says whether the conversion should be done in direct- or copy-initialization
   10265              :    context.  */
   10266              : 
   10267              : tristate
   10268        14849 : ref_conv_binds_to_temporary (tree type, tree expr, bool direct_init_p/*=false*/)
   10269              : {
   10270        14849 :   gcc_assert (TYPE_REF_P (type));
   10271              : 
   10272        14849 :   conversion_obstack_sentinel cos;
   10273              : 
   10274        14849 :   const int flags = direct_init_p ? LOOKUP_NORMAL : LOOKUP_IMPLICIT;
   10275        14849 :   conversion *conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   10276              :                                           /*c_cast_p=*/false, flags, tf_none);
   10277        14849 :   if (!conv || conv->bad_p)
   10278          529 :     return tristate::unknown ();
   10279              : 
   10280        14320 :   if (conv_binds_ref_to_temporary (conv))
   10281              :     {
   10282              :       /* Actually perform the conversion to check access control.  */
   10283          499 :       if (convert_like (conv, expr, tf_none) != error_mark_node)
   10284          487 :         return tristate (true);
   10285              :       else
   10286           12 :         return tristate::unknown ();
   10287              :     }
   10288              : 
   10289        13821 :   return tristate (false);
   10290        14849 : }
   10291              : 
   10292              : /* Call the trivial destructor for INSTANCE, which can be either an lvalue of
   10293              :    class type or a pointer to class type.  If NO_PTR_DEREF is true and
   10294              :    INSTANCE has pointer type, clobber the pointer rather than what it points
   10295              :    to.  */
   10296              : 
   10297              : tree
   10298      3359182 : build_trivial_dtor_call (tree instance, bool no_ptr_deref)
   10299              : {
   10300      3359182 :   gcc_assert (!is_dummy_object (instance));
   10301              : 
   10302      3359182 :   if (!flag_lifetime_dse)
   10303              :     {
   10304           58 :     no_clobber:
   10305           77 :       return fold_convert (void_type_node, instance);
   10306              :     }
   10307              : 
   10308      3404630 :   if (INDIRECT_TYPE_P (TREE_TYPE (instance))
   10309      3359124 :       && (!no_ptr_deref || TYPE_REF_P (TREE_TYPE (instance))))
   10310              :     {
   10311      3195173 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
   10312           19 :         goto no_clobber;
   10313      3195154 :       instance = cp_build_fold_indirect_ref (instance);
   10314              :     }
   10315              : 
   10316              :   /* A trivial destructor should still clobber the object.  */
   10317      3359105 :   tree clobber = build_clobber (TREE_TYPE (instance), CLOBBER_OBJECT_END);
   10318      3359105 :   return build2 (MODIFY_EXPR, void_type_node,
   10319      3359105 :                  instance, clobber);
   10320              : }
   10321              : 
   10322              : /* Return true if in an immediate function context, or an unevaluated operand,
   10323              :    or a default argument/member initializer, or a subexpression of an immediate
   10324              :    invocation.  */
   10325              : 
   10326              : bool
   10327     10948152 : in_immediate_context ()
   10328              : {
   10329     10948152 :   return (cp_unevaluated_operand != 0
   10330      9990572 :           || (current_function_decl != NULL_TREE
   10331     18026056 :               && DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
   10332              :           /* DR 2631: default args and DMI aren't immediately evaluated.
   10333              :              Return true here so immediate_invocation_p returns false.  */
   10334      9792296 :           || current_binding_level->kind == sk_function_parms
   10335      9789413 :           || current_binding_level->kind == sk_template_parms
   10336      9788403 :           || parsing_nsdmi ()
   10337     20733962 :           || in_consteval_if_p);
   10338              : }
   10339              : 
   10340              : /* Return true if a call to FN with number of arguments NARGS
   10341              :    is an immediate invocation.  */
   10342              : 
   10343              : bool
   10344    214355358 : immediate_invocation_p (tree fn)
   10345              : {
   10346    214355358 :   return (TREE_CODE (fn) == FUNCTION_DECL
   10347    214355358 :           && DECL_IMMEDIATE_FUNCTION_P (fn)
   10348    217143691 :           && !in_immediate_context ());
   10349              : }
   10350              : 
   10351              : /* Subroutine of the various build_*_call functions.  Overload resolution
   10352              :    has chosen a winning candidate CAND; build up a CALL_EXPR accordingly.
   10353              :    ARGS is a TREE_LIST of the unconverted arguments to the call.  FLAGS is a
   10354              :    bitmask of various LOOKUP_* flags which apply to the call itself.  */
   10355              : 
   10356              : static tree
   10357    232647535 : build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
   10358              : {
   10359    232647535 :   tree fn = cand->fn;
   10360    232647535 :   const vec<tree, va_gc> *args = cand->args;
   10361    232647535 :   tree first_arg = cand->first_arg;
   10362    232647535 :   conversion **convs = cand->convs;
   10363    232647535 :   tree parm = TYPE_ARG_TYPES (TREE_TYPE (fn));
   10364    232647535 :   int parmlen;
   10365    232647535 :   tree val;
   10366    232647535 :   int nargs;
   10367    232647535 :   tree *argarray;
   10368    232647535 :   bool already_used = false;
   10369              : 
   10370              :   /* In a template, there is no need to perform all of the work that
   10371              :      is normally done.  We are only interested in the type of the call
   10372              :      expression, i.e., the return type of the function.  Any semantic
   10373              :      errors will be deferred until the template is instantiated.  */
   10374    232647535 :   if (processing_template_decl)
   10375              :     {
   10376     30281781 :       if (undeduced_auto_decl (fn))
   10377        12964 :         mark_used (fn, complain);
   10378              :       else
   10379              :         /* Otherwise set TREE_USED for the benefit of -Wunused-function.
   10380              :            See PR80598.  */
   10381     30268817 :         TREE_USED (fn) = 1;
   10382              : 
   10383     30281781 :       tree return_type = TREE_TYPE (TREE_TYPE (fn));
   10384     30281781 :       tree callee;
   10385     30281781 :       if (first_arg == NULL_TREE)
   10386              :         {
   10387     22648211 :           callee = build_addr_func (fn, complain);
   10388     22648211 :           if (callee == error_mark_node)
   10389              :             return error_mark_node;
   10390              :         }
   10391              :       else
   10392              :         {
   10393      7633570 :           callee = build_baselink (cand->conversion_path, cand->access_path,
   10394              :                                    fn, NULL_TREE);
   10395      7633570 :           callee = build_min (COMPONENT_REF, TREE_TYPE (fn),
   10396              :                               first_arg, callee, NULL_TREE);
   10397              :         }
   10398              : 
   10399     30281781 :       tree expr = build_call_vec (return_type, callee, args);
   10400     30281781 :       SET_EXPR_LOCATION (expr, input_location);
   10401     30281781 :       if (TREE_THIS_VOLATILE (fn) && cfun)
   10402      2622003 :         current_function_returns_abnormally = 1;
   10403     30281781 :       if (TREE_DEPRECATED (fn)
   10404     30281781 :           && warning_suppressed_at (input_location,
   10405              :                                     OPT_Wdeprecated_declarations))
   10406              :         /* Make the expr consistent with the location.  */
   10407        19984 :         TREE_NO_WARNING (expr) = true;
   10408     30281781 :       if (immediate_invocation_p (fn))
   10409              :         {
   10410       205199 :           tree obj_arg = NULL_TREE;
   10411       410398 :           if (DECL_CONSTRUCTOR_P (fn))
   10412            0 :             obj_arg = first_arg;
   10413              :           /* Look through *(const T *)&obj.  */
   10414            0 :           if (obj_arg && INDIRECT_REF_P (obj_arg))
   10415              :             {
   10416            0 :               tree addr = TREE_OPERAND (obj_arg, 0);
   10417            0 :               STRIP_NOPS (addr);
   10418            0 :               if (TREE_CODE (addr) == ADDR_EXPR)
   10419              :                 {
   10420            0 :                   tree typeo = TREE_TYPE (obj_arg);
   10421            0 :                   tree typei = TREE_TYPE (TREE_OPERAND (addr, 0));
   10422            0 :                   if (same_type_ignoring_top_level_qualifiers_p (typeo, typei))
   10423            0 :                     obj_arg = TREE_OPERAND (addr, 0);
   10424              :                 }
   10425              :             }
   10426       205199 :           fold_non_dependent_expr (expr, complain,
   10427              :                                    /*manifestly_const_eval=*/true,
   10428              :                                    obj_arg);
   10429              :         }
   10430     30281781 :       return convert_from_reference (expr);
   10431              :     }
   10432              : 
   10433              :   /* Give any warnings we noticed during overload resolution.  */
   10434    202365754 :   if (cand->warnings && (complain & tf_warning))
   10435              :     {
   10436              :       struct candidate_warning *w;
   10437           98 :       for (w = cand->warnings; w; w = w->next)
   10438           49 :         joust (cand, w->loser, 1, complain);
   10439              :     }
   10440              : 
   10441              :   /* Core issue 2327: P0135 doesn't say how to handle the case where the
   10442              :      argument to the copy constructor ends up being a prvalue after
   10443              :      conversion.  Let's do the normal processing, but pretend we aren't
   10444              :      actually using the copy constructor.  */
   10445    202365754 :   bool force_elide = false;
   10446    202365754 :   if (cxx_dialect >= cxx17
   10447    200321797 :       && cand->num_convs == 1
   10448    113284890 :       && DECL_COMPLETE_CONSTRUCTOR_P (fn)
   10449     39660450 :       && (DECL_COPY_CONSTRUCTOR_P (fn)
   10450     21515074 :           || DECL_MOVE_CONSTRUCTOR_P (fn))
   10451     14418951 :       && !unsafe_return_slot_p (first_arg)
   10452    216712848 :       && conv_binds_ref_to_prvalue (convs[0]))
   10453              :     {
   10454       136109 :       force_elide = true;
   10455       136109 :       goto not_really_used;
   10456              :     }
   10457              : 
   10458              :   /* OK, we're actually calling this inherited constructor; set its deletedness
   10459              :      appropriately.  We can get away with doing this here because calling is
   10460              :      the only way to refer to a constructor.  */
   10461    404459290 :   if (DECL_INHERITED_CTOR (fn)
   10462     29393360 :       && !deduce_inheriting_ctor (fn))
   10463              :     {
   10464            2 :       if (complain & tf_error)
   10465            2 :         mark_used (fn);
   10466            2 :       return error_mark_node;
   10467              :     }
   10468              : 
   10469              :   /* Make =delete work with SFINAE.  */
   10470    202229643 :   if (DECL_DELETED_FN (fn))
   10471              :     {
   10472      1034261 :       if (complain & tf_error)
   10473              :         {
   10474         2303 :           mark_used (fn);
   10475         2303 :           if (cand->next)
   10476              :             {
   10477         2086 :               if (flag_diagnostics_all_candidates)
   10478            9 :                 print_z_candidates (input_location, cand, /*only_viable_p=*/false);
   10479              :               else
   10480         2077 :                 inform (input_location,
   10481              :                         "use %<-fdiagnostics-all-candidates%> to display "
   10482              :                         "considered candidates");
   10483              :             }
   10484              :         }
   10485      1034261 :       return error_mark_node;
   10486              :     }
   10487              : 
   10488    201195382 :   if (DECL_FUNCTION_MEMBER_P (fn))
   10489              :     {
   10490    107272934 :       tree access_fn;
   10491              :       /* If FN is a template function, two cases must be considered.
   10492              :          For example:
   10493              : 
   10494              :            struct A {
   10495              :              protected:
   10496              :                template <class T> void f();
   10497              :            };
   10498              :            template <class T> struct B {
   10499              :              protected:
   10500              :                void g();
   10501              :            };
   10502              :            struct C : A, B<int> {
   10503              :              using A::f;        // #1
   10504              :              using B<int>::g;     // #2
   10505              :            };
   10506              : 
   10507              :          In case #1 where `A::f' is a member template, DECL_ACCESS is
   10508              :          recorded in the primary template but not in its specialization.
   10509              :          We check access of FN using its primary template.
   10510              : 
   10511              :          In case #2, where `B<int>::g' has a DECL_TEMPLATE_INFO simply
   10512              :          because it is a member of class template B, DECL_ACCESS is
   10513              :          recorded in the specialization `B<int>::g'.  We cannot use its
   10514              :          primary template because `B<T>::g' and `B<int>::g' may have
   10515              :          different access.  */
   10516    107272934 :       if (DECL_TEMPLATE_INFO (fn)
   10517    107272934 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   10518      8072531 :         access_fn = DECL_TI_TEMPLATE (fn);
   10519              :       else
   10520              :         access_fn = fn;
   10521    107272934 :       if (!perform_or_defer_access_check (cand->access_path, access_fn,
   10522              :                                           fn, complain))
   10523        21113 :         return error_mark_node;
   10524              :     }
   10525              : 
   10526              :   /* If we're checking for implicit delete, don't bother with argument
   10527              :      conversions.  */
   10528    201174269 :   if (flags & LOOKUP_SPECULATIVE)
   10529              :     {
   10530     26087952 :       if (cand->viable == 1)
   10531              :         return fn;
   10532          178 :       else if (!(complain & tf_error))
   10533              :         /* Reject bad conversions now.  */
   10534          146 :         return error_mark_node;
   10535              :       /* else continue to get conversion error.  */
   10536              :     }
   10537              : 
   10538    175086317 :  not_really_used:
   10539              : 
   10540              :   /* N3276 magic doesn't apply to nested calls.  */
   10541    175222458 :   tsubst_flags_t decltype_flag = (complain & tf_decltype);
   10542    175222458 :   complain &= ~tf_decltype;
   10543              :   /* No-Cleanup doesn't apply to nested calls either.  */
   10544    175222458 :   tsubst_flags_t no_cleanup_complain = complain;
   10545    175222458 :   complain &= ~tf_no_cleanup;
   10546              : 
   10547              :   /* Find maximum size of vector to hold converted arguments.  */
   10548    175222458 :   parmlen = list_length (parm);
   10549    329757156 :   nargs = vec_safe_length (args) + (first_arg != NULL_TREE ? 1 : 0);
   10550    175222458 :   if (parmlen > nargs)
   10551              :     nargs = parmlen;
   10552    175222458 :   argarray = XALLOCAVEC (tree, nargs);
   10553              : 
   10554    350444913 :   in_consteval_if_p_temp_override icip;
   10555              :   /* If the call is immediate function invocation, make sure
   10556              :      taking address of immediate functions is allowed in its arguments.  */
   10557    175222458 :   if (immediate_invocation_p (STRIP_TEMPLATE (fn)))
   10558      1512755 :     in_consteval_if_p = true;
   10559              : 
   10560    175222458 :   int argarray_size = 0;
   10561    175222458 :   unsigned int arg_index = 0;
   10562    175222458 :   int conv_index = 0;
   10563    175222458 :   int param_index = 0;
   10564    175222458 :   tree parmd = DECL_ARGUMENTS (fn);
   10565              : 
   10566    243475859 :   auto consume_object_arg = [&arg_index, &first_arg, args]()
   10567              :     {
   10568     68253401 :       if (!first_arg)
   10569            0 :         return (*args)[arg_index++];
   10570     68253401 :       tree object_arg = first_arg;
   10571     68253401 :       first_arg = NULL_TREE;
   10572     68253401 :       return object_arg;
   10573    175222458 :     };
   10574              : 
   10575              :   /* The implicit parameters to a constructor are not considered by overload
   10576              :      resolution, and must be of the proper type.  */
   10577    175222458 :   if (DECL_CONSTRUCTOR_P (fn))
   10578              :     {
   10579     20900856 :       tree object_arg = consume_object_arg ();
   10580     20900856 :       argarray[argarray_size++] = build_this (object_arg);
   10581     20900856 :       parm = TREE_CHAIN (parm);
   10582     20900856 :       if (parmd)
   10583     20900856 :         parmd = DECL_CHAIN (parmd);
   10584              :       /* We should never try to call the abstract constructor.  */
   10585     20900856 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (fn));
   10586              : 
   10587     20900856 :       if (DECL_HAS_VTT_PARM_P (fn))
   10588              :         {
   10589        17661 :           argarray[argarray_size++] = (*args)[arg_index];
   10590        17661 :           ++arg_index;
   10591        17661 :           parm = TREE_CHAIN (parm);
   10592        17661 :           if (parmd)
   10593        17661 :             parmd = DECL_CHAIN (parmd);
   10594              :         }
   10595              :     }
   10596              :   /* Bypass access control for 'this' parameter.  */
   10597    154321602 :   else if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
   10598              :     {
   10599     47343288 :       tree arg = build_this (consume_object_arg ());
   10600     47343288 :       tree argtype = TREE_TYPE (arg);
   10601              : 
   10602     47343288 :       if (arg == error_mark_node)
   10603              :         return error_mark_node;
   10604     47343285 :       if (convs[conv_index++]->bad_p)
   10605              :         {
   10606         1236 :           if (complain & tf_error)
   10607              :             {
   10608          105 :               auto_diagnostic_group d;
   10609          105 :               if (permerror (input_location, "passing %qT as %<this%> "
   10610              :                              "argument discards qualifiers",
   10611          105 :                              TREE_TYPE (argtype)))
   10612          102 :                 inform (DECL_SOURCE_LOCATION (fn), "  in call to %qD", fn);
   10613          105 :             }
   10614              :           else
   10615              :             return error_mark_node;
   10616              :         }
   10617              : 
   10618              :       /* The class where FN is defined.  */
   10619     47342154 :       tree ctx = DECL_CONTEXT (fn);
   10620              : 
   10621              :       /* See if the function member or the whole class type is declared
   10622              :          final and the call can be devirtualized.  */
   10623     47342154 :       if (DECL_FINAL_P (fn) || CLASSTYPE_FINAL (ctx))
   10624       134127 :         flags |= LOOKUP_NONVIRTUAL;
   10625              : 
   10626              :       /* [class.mfct.non-static]: If a non-static member function of a class
   10627              :          X is called for an object that is not of type X, or of a type
   10628              :          derived from X, the behavior is undefined.
   10629              : 
   10630              :          So we can assume that anything passed as 'this' is non-null, and
   10631              :          optimize accordingly.  */
   10632              :       /* Check that the base class is accessible.  */
   10633     47342154 :       if (!accessible_base_p (TREE_TYPE (argtype),
   10634     47342154 :                               BINFO_TYPE (cand->conversion_path), true))
   10635              :         {
   10636           33 :           if (complain & tf_error)
   10637           30 :             error ("%qT is not an accessible base of %qT",
   10638           30 :                    BINFO_TYPE (cand->conversion_path),
   10639           30 :                    TREE_TYPE (argtype));
   10640              :           else
   10641            3 :             return error_mark_node;
   10642              :         }
   10643              :       /* If fn was found by a using declaration, the conversion path
   10644              :          will be to the derived class, not the base declaring fn. We
   10645              :          must convert to the base.  */
   10646     47342151 :       tree base_binfo = cand->conversion_path;
   10647     47342151 :       if (BINFO_TYPE (base_binfo) != ctx)
   10648              :         {
   10649       122925 :           base_binfo = lookup_base (base_binfo, ctx, ba_unique, NULL, complain);
   10650       122925 :           if (base_binfo == error_mark_node)
   10651              :             return error_mark_node;
   10652              :         }
   10653              : 
   10654              :       /* If we know the dynamic type of the object, look up the final overrider
   10655              :          in the BINFO.  */
   10656     48265945 :       if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
   10657     47846921 :           && resolves_to_fixed_type_p (arg))
   10658              :         {
   10659         1217 :           tree ov = lookup_vfn_in_binfo (DECL_VINDEX (fn), base_binfo);
   10660              : 
   10661              :           /* And unwind base_binfo to match.  If we don't find the type we're
   10662              :              looking for in BINFO_INHERITANCE_CHAIN, we're looking at diamond
   10663              :              inheritance; for now do a normal virtual call in that case.  */
   10664         1217 :           tree octx = DECL_CONTEXT (ov);
   10665         1217 :           tree obinfo = base_binfo;
   10666         2527 :           while (obinfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (obinfo), octx))
   10667           48 :             obinfo = BINFO_INHERITANCE_CHAIN (obinfo);
   10668         1217 :           if (obinfo)
   10669              :             {
   10670         1214 :               fn = ov;
   10671         1214 :               base_binfo = obinfo;
   10672         1214 :               flags |= LOOKUP_NONVIRTUAL;
   10673              :             }
   10674              :         }
   10675              : 
   10676     47342145 :       tree converted_arg = build_base_path (PLUS_EXPR, arg,
   10677              :                                             base_binfo, 1, complain);
   10678              : 
   10679     47342145 :       argarray[argarray_size++] = converted_arg;
   10680     47342145 :       parm = TREE_CHAIN (parm);
   10681     47342145 :       if (parmd)
   10682     47342145 :         parmd = DECL_CHAIN (parmd);
   10683              :     }
   10684              : 
   10685    312744751 :   auto handle_arg = [fn, flags](tree type,
   10686              :                                 tree arg,
   10687              :                                 int const param_index,
   10688              :                                 conversion *conv,
   10689              :                                 tsubst_flags_t const arg_complain)
   10690              :     {
   10691              :       /* Set user_conv_p on the argument conversions, so rvalue/base handling
   10692              :          knows not to allow any more UDCs.  This needs to happen after we
   10693              :          process cand->warnings.  */
   10694    137523436 :       if (flags & LOOKUP_NO_CONVERSION)
   10695      3743078 :         conv->user_conv_p = true;
   10696              : 
   10697    137523436 :       if (arg_complain & tf_warning)
   10698    100330238 :         maybe_warn_pessimizing_move (arg, type, /*return_p=*/false);
   10699              : 
   10700    137523436 :       tree val = convert_like_with_context (conv, arg, fn,
   10701              :                                             param_index, arg_complain);
   10702    137523436 :       val = convert_for_arg_passing (type, val, arg_complain);
   10703    137523436 :       return val;
   10704    175221315 :     };
   10705              : 
   10706    313893211 :   auto handle_indeterminate_arg = [](tree parmd, tree val)
   10707              :     {
   10708    138671896 :       if (parmd
   10709    138671896 :           && lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (parmd)))
   10710              :         {
   10711           48 :           STRIP_NOPS (val);
   10712           48 :           if (TREE_CODE (val) == ADDR_EXPR
   10713           48 :               && TREE_CODE (TREE_OPERAND (val, 0)) == TARGET_EXPR)
   10714              :             {
   10715           48 :               val = TARGET_EXPR_SLOT (TREE_OPERAND (val, 0));
   10716           48 :               if (auto_var_p (val) && DECL_ARTIFICIAL (val))
   10717              :                 {
   10718           48 :                   tree id = get_identifier ("indeterminate");
   10719           48 :                   DECL_ATTRIBUTES (val)
   10720           96 :                     = tree_cons (build_tree_list (NULL_TREE, id), NULL_TREE,
   10721           48 :                                  DECL_ATTRIBUTES (val));
   10722              :                 }
   10723              :             }
   10724              :         }
   10725    138671896 :     };
   10726              : 
   10727    175221315 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   10728              :     {
   10729         9257 :       gcc_assert (cand->num_convs > 0);
   10730         9257 :       tree object_arg = consume_object_arg ();
   10731         9257 :       val = handle_arg (TREE_VALUE (parm),
   10732              :                         object_arg,
   10733              :                         param_index++,
   10734         9257 :                         convs[conv_index++],
   10735              :                         complain);
   10736              : 
   10737         9257 :       if (val == error_mark_node)
   10738              :         return error_mark_node;
   10739              :       else
   10740              :         {
   10741         9089 :           argarray[argarray_size++] = val;
   10742         9089 :           handle_indeterminate_arg (parmd, val);
   10743              :         }
   10744         9089 :       parm = TREE_CHAIN (parm);
   10745         9089 :       if (parmd)
   10746         9089 :         parmd = DECL_CHAIN (parmd);
   10747              :     }
   10748              : 
   10749    175221147 :   gcc_assert (first_arg == NULL_TREE);
   10750    312733496 :   for (; arg_index < vec_safe_length (args) && parm;
   10751    137512349 :        parm = TREE_CHAIN (parm), ++arg_index, ++param_index, ++conv_index)
   10752              :     {
   10753    137514179 :       tree current_arg = (*args)[arg_index];
   10754              : 
   10755              :       /* If the argument is NULL and used to (implicitly) instantiate a
   10756              :          template function (and bind one of the template arguments to
   10757              :          the type of 'long int'), we don't want to warn about passing NULL
   10758              :          to non-pointer argument.
   10759              :          For example, if we have this template function:
   10760              : 
   10761              :            template<typename T> void func(T x) {}
   10762              : 
   10763              :          we want to warn (when -Wconversion is enabled) in this case:
   10764              : 
   10765              :            void foo() {
   10766              :              func<int>(NULL);
   10767              :            }
   10768              : 
   10769              :          but not in this case:
   10770              : 
   10771              :            void foo() {
   10772              :              func(NULL);
   10773              :            }
   10774              :       */
   10775    137514179 :       bool conversion_warning = !(null_node_p (current_arg)
   10776        48382 :                                   && DECL_TEMPLATE_INFO (fn)
   10777           61 :                                   && cand->template_decl
   10778           30 :                                   && !cand->explicit_targs);
   10779              : 
   10780              :       /* Also don't warn about (x <=> y) < 0 (c++/100903).  */
   10781              :       if (conversion_warning
   10782    137514164 :           && integer_zerop (current_arg)
   10783     10655328 :           && warn_zero_as_null_pointer_constant
   10784          195 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (fn),
   10785          195 :                                   OPT_Wzero_as_null_pointer_constant))
   10786          120 :         conversion_warning = false;
   10787              : 
   10788          135 :       tsubst_flags_t const arg_complain
   10789    137514059 :         = conversion_warning ? complain : complain & ~tf_warning;
   10790              : 
   10791    137514179 :       val = handle_arg (TREE_VALUE (parm),
   10792              :                         current_arg,
   10793              :                         param_index,
   10794    137514179 :                         convs[conv_index],
   10795              :                         arg_complain);
   10796              : 
   10797    137514179 :       if (val == error_mark_node)
   10798              :         return error_mark_node;
   10799              :       else
   10800              :         {
   10801    137512349 :           argarray[argarray_size++] = val;
   10802    137512349 :           handle_indeterminate_arg (parmd, val);
   10803              :         }
   10804    137512349 :       if (parmd)
   10805    126254334 :         parmd = DECL_CHAIN (parmd);
   10806              :     }
   10807              : 
   10808              :   /* Default arguments */
   10809    176369775 :   for (; parm && parm != void_list_node;
   10810      1150458 :        parm = TREE_CHAIN (parm), param_index++)
   10811              :     {
   10812      1150579 :       if (TREE_VALUE (parm) == error_mark_node)
   10813              :         return error_mark_node;
   10814      2301134 :       val = convert_default_arg (TREE_VALUE (parm),
   10815      1150567 :                                  TREE_PURPOSE (parm),
   10816              :                                  fn, param_index,
   10817              :                                  complain);
   10818      1150567 :       if (val == error_mark_node)
   10819              :         return error_mark_node;
   10820      1150458 :       argarray[argarray_size++] = val;
   10821      1150458 :       handle_indeterminate_arg (parmd, val);
   10822      1150458 :       if (parmd)
   10823      1150458 :         parmd = DECL_CHAIN (parmd);
   10824              :     }
   10825              : 
   10826              :   /* Ellipsis */
   10827    175219196 :   int magic = magic_varargs_p (fn);
   10828    353515127 :   for (; arg_index < vec_safe_length (args); ++arg_index)
   10829              :     {
   10830      3076756 :       tree a = (*args)[arg_index];
   10831      3076756 :       if ((magic == 3 && arg_index == 2) || (magic == 4 && arg_index == 0))
   10832              :         {
   10833              :           /* Do no conversions for certain magic varargs.  */
   10834       122535 :           a = mark_type_use (a);
   10835       122535 :           if (TREE_CODE (a) == FUNCTION_DECL && reject_gcc_builtin (a))
   10836            0 :             return error_mark_node;
   10837              :         }
   10838      2954221 :       else if (magic != 0)
   10839              :         {
   10840              :           /* Don't truncate excess precision to the semantic type.  */
   10841      1506408 :           if (magic == 1 && TREE_CODE (a) == EXCESS_PRECISION_EXPR)
   10842           84 :             a = TREE_OPERAND (a, 0);
   10843              :           /* For other magic varargs only do decay_conversion.  */
   10844      1506408 :           a = decay_conversion (a, complain);
   10845              :         }
   10846      1447813 :       else if (DECL_CONSTRUCTOR_P (fn)
   10847          387 :                && vec_safe_length (args) == 1
   10848      1448014 :                && same_type_ignoring_top_level_qualifiers_p (DECL_CONTEXT (fn),
   10849          201 :                                                              TREE_TYPE (a)))
   10850              :         {
   10851              :           /* Avoid infinite recursion trying to call A(...).  */
   10852            3 :           if (complain & tf_error)
   10853              :             /* Try to call the actual copy constructor for a good error.  */
   10854            3 :             call_copy_ctor (a, complain);
   10855            3 :           return error_mark_node;
   10856              :         }
   10857              :       else
   10858      1447810 :         a = convert_arg_to_ellipsis (a, complain);
   10859      3076753 :       if (a == error_mark_node)
   10860              :         return error_mark_node;
   10861      3076735 :       argarray[argarray_size++] = a;
   10862              :     }
   10863              : 
   10864    175219175 :   gcc_assert (argarray_size <= nargs);
   10865    175219175 :   nargs = argarray_size;
   10866    175219175 :   icip.reset ();
   10867              : 
   10868              :   /* Avoid performing argument transformation if warnings are disabled.
   10869              :      When tf_warning is set and at least one of the warnings is active
   10870              :      the check_function_arguments function might warn about something.  */
   10871              : 
   10872    175219175 :   bool warned_p = false;
   10873    175219175 :   if ((complain & tf_warning)
   10874    114101247 :       && (warn_nonnull
   10875    112112603 :           || warn_format
   10876    112112600 :           || warn_suggest_attribute_format
   10877    112112504 :           || warn_restrict))
   10878              :     {
   10879      1990990 :       tree *fargs = (!nargs ? argarray
   10880      1640964 :                             : (tree *) alloca (nargs * sizeof (tree)));
   10881      6053168 :       for (int j = 0; j < nargs; j++)
   10882              :         {
   10883              :           /* For -Wformat undo the implicit passing by hidden reference
   10884              :              done by convert_arg_to_ellipsis.  */
   10885      4062178 :           if (TREE_CODE (argarray[j]) == ADDR_EXPR
   10886      4062178 :               && TYPE_REF_P (TREE_TYPE (argarray[j])))
   10887         1501 :             fargs[j] = TREE_OPERAND (argarray[j], 0);
   10888              :           else
   10889      4060677 :             fargs[j] = argarray[j];
   10890              :         }
   10891              : 
   10892      1990990 :       warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn),
   10893              :                                            nargs, fargs, NULL,
   10894              :                                            cp_comp_parm_types);
   10895              :     }
   10896              : 
   10897    350438350 :   if (DECL_INHERITED_CTOR (fn))
   10898              :     {
   10899              :       /* Check for passing ellipsis arguments to an inherited constructor.  We
   10900              :          could handle this by open-coding the inherited constructor rather than
   10901              :          defining it, but let's not bother now.  */
   10902        64928 :       if (!cp_unevaluated_operand
   10903        64505 :           && cand->num_convs
   10904        64505 :           && cand->convs[cand->num_convs-1]->ellipsis_p)
   10905              :         {
   10906           15 :           if (complain & tf_error)
   10907              :             {
   10908           15 :               auto_diagnostic_group d;
   10909           15 :               sorry ("passing arguments to ellipsis of inherited constructor "
   10910              :                      "%qD", cand->fn);
   10911           15 :               inform (DECL_SOURCE_LOCATION (cand->fn), "declared here");
   10912           15 :             }
   10913           15 :           return error_mark_node;
   10914              :         }
   10915              : 
   10916              :       /* A base constructor inheriting from a virtual base doesn't get the
   10917              :          inherited arguments, just this and __vtt.  */
   10918        64913 :       if (ctor_omit_inherited_parms (fn))
   10919    175219160 :         nargs = 2;
   10920              :     }
   10921              : 
   10922              :   /* Avoid actually calling copy constructors and copy assignment operators,
   10923              :      if possible.  */
   10924              : 
   10925    175219160 :   if (!force_elide
   10926    175083619 :       && (!flag_elide_constructors
   10927              :           /* It's unsafe to elide the operation when handling
   10928              :              a noexcept-expression, it may evaluate to the wrong
   10929              :              value (c++/53025, c++/96090).  */
   10930    175083415 :           || cp_noexcept_operand != 0))
   10931              :     /* Do things the hard way.  */;
   10932    172423090 :   else if (cand->num_convs == 1
   10933    263281487 :            && (DECL_COPY_CONSTRUCTOR_P (fn)
   10934    170860326 :                || DECL_MOVE_CONSTRUCTOR_P (fn)))
   10935              :     {
   10936      8279396 :       tree targ;
   10937      8279396 :       tree arg = argarray[num_artificial_parms_for (fn)];
   10938      8279396 :       tree fa = argarray[0];
   10939      8279396 :       bool trivial = trivial_fn_p (fn);
   10940              : 
   10941              :       /* Pull out the real argument, disregarding const-correctness.  */
   10942      8279396 :       targ = arg;
   10943              :       /* Strip the reference binding for the constructor parameter.  */
   10944            0 :       if (CONVERT_EXPR_P (targ)
   10945      8279396 :           && TYPE_REF_P (TREE_TYPE (targ)))
   10946      8279396 :         targ = TREE_OPERAND (targ, 0);
   10947              :       /* But don't strip any other reference bindings; binding a temporary to a
   10948              :          reference prevents copy elision.  */
   10949     13712556 :       while ((CONVERT_EXPR_P (targ)
   10950     11556058 :               && !TYPE_REF_P (TREE_TYPE (targ)))
   10951     28765908 :              || TREE_CODE (targ) == NON_LVALUE_EXPR)
   10952     10348039 :         targ = TREE_OPERAND (targ, 0);
   10953      8279396 :       if (TREE_CODE (targ) == ADDR_EXPR)
   10954              :         {
   10955      2509707 :           targ = TREE_OPERAND (targ, 0);
   10956      2509707 :           if (!same_type_ignoring_top_level_qualifiers_p
   10957      2509707 :               (TREE_TYPE (TREE_TYPE (arg)), TREE_TYPE (targ)))
   10958              :             targ = NULL_TREE;
   10959              :         }
   10960              :       else
   10961              :         targ = NULL_TREE;
   10962              : 
   10963      2509255 :       if (targ)
   10964              :         arg = targ;
   10965              :       else
   10966      5770141 :         arg = cp_build_fold_indirect_ref (arg);
   10967              : 
   10968              :       /* In C++17 we shouldn't be copying a TARGET_EXPR except into a
   10969              :          potentially-overlapping subobject.  */
   10970      8279396 :       if (CHECKING_P && cxx_dialect >= cxx17)
   10971      8199939 :         gcc_assert (TREE_CODE (arg) != TARGET_EXPR
   10972              :                     || force_elide
   10973              :                     /* It's from binding the ref parm to a packed field. */
   10974              :                     || convs[0]->need_temporary_p
   10975              :                     || seen_error ()
   10976              :                     /* See unsafe_copy_elision_p.  */
   10977              :                     || unsafe_return_slot_p (fa));
   10978              : 
   10979      8279396 :       bool unsafe = unsafe_copy_elision_p_opt (fa, arg);
   10980      8279396 :       bool eliding_temp = (TREE_CODE (arg) == TARGET_EXPR && !unsafe);
   10981              : 
   10982              :       /* [class.copy]: the copy constructor is implicitly defined even if the
   10983              :          implementation elided its use.  But don't warn about deprecation when
   10984              :          eliding a temporary, as then no copy is actually performed.  */
   10985      8279396 :       warning_sentinel s (warn_deprecated_copy, eliding_temp);
   10986      8279396 :       if (force_elide)
   10987              :         /* The language says this isn't called.  */;
   10988      8143855 :       else if (!trivial)
   10989              :         {
   10990      1373000 :           if (!mark_used (fn, complain) && !(complain & tf_error))
   10991            0 :             return error_mark_node;
   10992              :           already_used = true;
   10993              :         }
   10994              :       else
   10995      6770855 :         cp_handle_deprecated_or_unavailable (fn, complain);
   10996              : 
   10997       197809 :       if (eliding_temp && DECL_BASE_CONSTRUCTOR_P (fn)
   10998      8279592 :           && !make_base_init_ok (arg))
   10999              :         unsafe = true;
   11000              : 
   11001              :       /* If we're creating a temp and we already have one, don't create a
   11002              :          new one.  If we're not creating a temp but we get one, use
   11003              :          INIT_EXPR to collapse the temp into our target.  Otherwise, if the
   11004              :          ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
   11005              :          temp or an INIT_EXPR otherwise.  */
   11006      8279396 :       if (is_dummy_object (fa))
   11007              :         {
   11008      6103884 :           if (TREE_CODE (arg) == TARGET_EXPR)
   11009              :             return arg;
   11010      5937479 :           else if (trivial)
   11011      5361401 :             return force_target_expr (DECL_CONTEXT (fn), arg, complain);
   11012              :         }
   11013      2175512 :       else if ((trivial || TREE_CODE (arg) == TARGET_EXPR)
   11014      1385110 :                && !unsafe)
   11015              :         {
   11016      1385012 :           tree to = cp_build_fold_indirect_ref (fa);
   11017      1385012 :           val = cp_build_init_expr (to, arg);
   11018      1385012 :           return val;
   11019              :         }
   11020      8279396 :     }
   11021    164143694 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
   11022      3257526 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR)
   11023    166355124 :            && trivial_fn_p (fn))
   11024              :     {
   11025      1558365 :       tree to = cp_build_fold_indirect_ref (argarray[0]);
   11026      1558365 :       tree type = TREE_TYPE (to);
   11027      1558365 :       tree as_base = CLASSTYPE_AS_BASE (type);
   11028      1558365 :       tree arg = argarray[1];
   11029      1558365 :       location_t loc = cp_expr_loc_or_input_loc (arg);
   11030              : 
   11031      1558365 :       if (is_really_empty_class (type, /*ignore_vptr*/true))
   11032              :         {
   11033              :           /* Avoid copying empty classes, but ensure op= returns an lvalue even
   11034              :              if the object argument isn't one.  */
   11035       239231 :           to = force_lvalue (to, complain);
   11036       239231 :           val = build2 (COMPOUND_EXPR, type, arg, to);
   11037       239231 :           suppress_warning (val, OPT_Wunused);
   11038              :         }
   11039      1319134 :       else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
   11040              :         {
   11041      1024793 :           if (is_std_init_list (type)
   11042      1024793 :               && conv_binds_ref_to_prvalue (convs[1]))
   11043            3 :             warning_at (loc, OPT_Winit_list_lifetime,
   11044              :                         "assignment from temporary %<initializer_list%> does "
   11045              :                         "not extend the lifetime of the underlying array");
   11046      1024793 :           arg = cp_build_fold_indirect_ref (arg);
   11047      1024793 :           val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
   11048              :         }
   11049              :       else
   11050              :         {
   11051              :           /* We must only copy the non-tail padding parts.  */
   11052       294341 :           tree arg0, arg2, t;
   11053       294341 :           tree array_type, alias_set;
   11054              : 
   11055       294341 :           arg2 = TYPE_SIZE_UNIT (as_base);
   11056              :           /* Ensure op= returns an lvalue even if the object argument isn't
   11057              :              one.  */
   11058       294341 :           to = force_lvalue (to, complain);
   11059       294341 :           to = cp_stabilize_reference (to);
   11060       294341 :           arg0 = cp_build_addr_expr (to, complain);
   11061              : 
   11062       294341 :           array_type = build_array_type (unsigned_char_type_node,
   11063              :                                          build_index_type
   11064              :                                            (size_binop (MINUS_EXPR,
   11065              :                                                         arg2, size_int (1))));
   11066       294341 :           alias_set = build_int_cst (build_pointer_type (type), 0);
   11067       294341 :           t = build2 (MODIFY_EXPR, void_type_node,
   11068              :                       build2 (MEM_REF, array_type, arg0, alias_set),
   11069              :                       build2 (MEM_REF, array_type, arg, alias_set));
   11070       294341 :           val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to);
   11071       294341 :           suppress_warning (val, OPT_Wunused);
   11072              :         }
   11073              : 
   11074      1558365 :       cp_handle_deprecated_or_unavailable (fn, complain);
   11075              : 
   11076      1558365 :       return val;
   11077              :     }
   11078    162585329 :   else if (trivial_fn_p (fn))
   11079              :     {
   11080      7935866 :       if (DECL_DESTRUCTOR_P (fn))
   11081      3178474 :         return build_trivial_dtor_call (argarray[0]);
   11082       789459 :       else if (default_ctor_p (fn))
   11083              :         {
   11084       789459 :           if (is_dummy_object (argarray[0]))
   11085       310227 :             return force_target_expr (DECL_CONTEXT (fn), void_node,
   11086       310227 :                                       no_cleanup_complain);
   11087              :           else
   11088       479232 :             return cp_build_fold_indirect_ref (argarray[0]);
   11089              :         }
   11090              :     }
   11091              : 
   11092    162780044 :   gcc_assert (!force_elide);
   11093              : 
   11094    162780044 :   if (!already_used
   11095    162780044 :       && !mark_used (fn, complain))
   11096          795 :     return error_mark_node;
   11097              : 
   11098              :   /* Warn if the built-in writes to an object of a non-trivial type.  */
   11099    162779246 :   if (warn_class_memaccess
   11100      2048095 :       && vec_safe_length (args) >= 2
   11101    163758215 :       && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
   11102        69680 :     maybe_warn_class_memaccess (input_location, fn, args);
   11103              : 
   11104    162779246 :   if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
   11105              :     {
   11106       503562 :       tree t;
   11107       503562 :       tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (argarray[0])),
   11108       503562 :                                 DECL_CONTEXT (fn),
   11109              :                                 ba_any, NULL, complain);
   11110       503562 :       gcc_assert (binfo && binfo != error_mark_node);
   11111              : 
   11112       503562 :       argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1,
   11113              :                                      complain);
   11114       503562 :       if (TREE_SIDE_EFFECTS (argarray[0]))
   11115        47732 :         argarray[0] = save_expr (argarray[0]);
   11116       503562 :       t = build_pointer_type (TREE_TYPE (fn));
   11117       503562 :       fn = build_vfn_ref (argarray[0], DECL_VINDEX (fn));
   11118       503562 :       TREE_TYPE (fn) = t;
   11119              :     }
   11120              :   else
   11121              :     {
   11122              :       /* If FN is marked deprecated or unavailable, then we've already
   11123              :          issued a diagnostic from mark_used above, so avoid redundantly
   11124              :          issuing another one from build_addr_func.  */
   11125    162275684 :       auto w = make_temp_override (deprecated_state,
   11126    162275684 :                                    UNAVAILABLE_DEPRECATED_SUPPRESS);
   11127              : 
   11128    162275684 :       fn = build_addr_func (fn, complain);
   11129    162275684 :       if (fn == error_mark_node)
   11130            0 :         return error_mark_node;
   11131              : 
   11132              :       /* We're actually invoking the function.  (Immediate functions get an
   11133              :          & when invoking it even though the user didn't use &.)  */
   11134    162275684 :       ADDR_EXPR_DENOTES_CALL_P (fn) = true;
   11135    162275684 :     }
   11136              : 
   11137    162779246 :   tree call = build_cxx_call (fn, nargs, argarray, complain|decltype_flag);
   11138    162779246 :   if (call == error_mark_node)
   11139              :     return call;
   11140    162778272 :   if (cand->flags & LOOKUP_LIST_INIT_CTOR)
   11141              :     {
   11142      2044359 :       tree c = extract_call_expr (call);
   11143              :       /* build_new_op will clear this when appropriate.  */
   11144      2044359 :       CALL_EXPR_ORDERED_ARGS (c) = true;
   11145              :     }
   11146    162778272 :   if (warned_p)
   11147              :     {
   11148          253 :       tree c = extract_call_expr (call);
   11149          253 :       if (TREE_CODE (c) == CALL_EXPR)
   11150          253 :         suppress_warning (c /* Suppress all warnings.  */);
   11151              :     }
   11152    162778019 :   else if (TREE_DEPRECATED (fn)
   11153    162778019 :            && warning_suppressed_at (input_location,
   11154              :                                      OPT_Wdeprecated_declarations))
   11155              :     {
   11156            0 :       tree c = extract_call_expr (call);
   11157            0 :       if (TREE_CODE (c) == CALL_EXPR)
   11158            0 :         TREE_NO_WARNING (c) = true;
   11159              :     }
   11160              : 
   11161              :   return call;
   11162              : }
   11163              : 
   11164              : namespace
   11165              : {
   11166              : 
   11167              : /* Return the DECL of the first non-static subobject of class TYPE
   11168              :    that satisfies the predicate PRED or null if none can be found.  */
   11169              : 
   11170              : template <class Predicate>
   11171              : tree
   11172         3556 : first_non_static_field (tree type, Predicate pred)
   11173              : {
   11174         3556 :   if (!type || !CLASS_TYPE_P (type))
   11175              :     return NULL_TREE;
   11176              : 
   11177        71398 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   11178              :     {
   11179        68436 :       if (TREE_CODE (field) != FIELD_DECL)
   11180        43330 :         continue;
   11181        25106 :       if (TREE_STATIC (field))
   11182            0 :         continue;
   11183        25106 :       if (pred (field))
   11184              :         return field;
   11185              :     }
   11186              : 
   11187         2962 :   int i = 0;
   11188              : 
   11189         3082 :   for (tree base_binfo, binfo = TYPE_BINFO (type);
   11190         3082 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   11191              :     {
   11192          126 :       tree base = TREE_TYPE (base_binfo);
   11193          126 :       if (pred (base))
   11194              :         return base;
   11195          120 :       if (tree field = first_non_static_field (base, pred))
   11196              :         return field;
   11197              :     }
   11198              : 
   11199              :   return NULL_TREE;
   11200              : }
   11201              : 
   11202              : struct NonPublicField
   11203              : {
   11204        24356 :   bool operator() (const_tree t) const
   11205              :   {
   11206        24356 :     return DECL_P (t) && (TREE_PRIVATE (t) || TREE_PROTECTED (t));
   11207              :   }
   11208              : };
   11209              : 
   11210              : /* Return the DECL of the first non-public subobject of class TYPE
   11211              :    or null if none can be found.  */
   11212              : 
   11213              : static inline tree
   11214         3262 : first_non_public_field (tree type)
   11215              : {
   11216         3262 :   return first_non_static_field (type, NonPublicField ());
   11217              : }
   11218              : 
   11219              : struct NonTrivialField
   11220              : {
   11221          876 :   bool operator() (const_tree t) const
   11222              :   {
   11223          876 :     return !trivial_type_p (DECL_P (t) ? TREE_TYPE (t) : t);
   11224              :   }
   11225              : };
   11226              : 
   11227              : /* Return the DECL of the first non-trivial subobject of class TYPE
   11228              :    or null if none can be found.  */
   11229              : 
   11230              : static inline tree
   11231          174 : first_non_trivial_field (tree type)
   11232              : {
   11233          174 :   return first_non_static_field (type, NonTrivialField ());
   11234              : }
   11235              : 
   11236              : }   /* unnamed namespace */
   11237              : 
   11238              : /* Return true if all copy and move assignment operator overloads for
   11239              :    class TYPE are trivial and at least one of them is not deleted and,
   11240              :    when ACCESS is set, accessible.  Return false otherwise.  Set
   11241              :    HASASSIGN to true when the TYPE has a (not necessarily trivial)
   11242              :    copy or move assignment.  */
   11243              : 
   11244              : static bool
   11245         5021 : has_trivial_copy_assign_p (tree type, bool access, bool *hasassign)
   11246              : {
   11247         5021 :   tree fns = get_class_binding (type, assign_op_identifier);
   11248         5021 :   bool all_trivial = true;
   11249              : 
   11250              :   /* Iterate over overloads of the assignment operator, checking
   11251              :      accessible copy assignments for triviality.  */
   11252              : 
   11253        16515 :   for (tree f : ovl_range (fns))
   11254              :     {
   11255              :       /* Skip operators that aren't copy assignments.  */
   11256         8571 :       if (!copy_fn_p (f))
   11257         3046 :         continue;
   11258              : 
   11259         5525 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11260         5813 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11261              : 
   11262              :       /* Skip template assignment operators and deleted functions.  */
   11263         5525 :       if (TREE_CODE (f) != FUNCTION_DECL || DECL_DELETED_FN (f))
   11264          694 :         continue;
   11265              : 
   11266         4831 :       if (accessible)
   11267         4579 :         *hasassign = true;
   11268              : 
   11269         4579 :       if (!accessible || !trivial_fn_p (f))
   11270              :         all_trivial = false;
   11271              : 
   11272              :       /* Break early when both properties have been determined.  */
   11273         4831 :       if (*hasassign && !all_trivial)
   11274              :         break;
   11275              :     }
   11276              : 
   11277              :   /* Return true if they're all trivial and one of the expressions
   11278              :      TYPE() = TYPE() or TYPE() = (TYPE&)() is valid.  */
   11279         5021 :   tree ref = cp_build_reference_type (type, false);
   11280         5021 :   return (all_trivial
   11281         5021 :           && (is_trivially_xible (MODIFY_EXPR, type, type)
   11282          333 :               || is_trivially_xible (MODIFY_EXPR, type, ref)));
   11283              : }
   11284              : 
   11285              : /* Return true if all copy and move ctor overloads for class TYPE are
   11286              :    trivial and at least one of them is not deleted and, when ACCESS is
   11287              :    set, accessible.  Return false otherwise.  Set each element of HASCTOR[]
   11288              :    to true when the TYPE has a (not necessarily trivial) default and copy
   11289              :    (or move) ctor, respectively.  */
   11290              : 
   11291              : static bool
   11292         5021 : has_trivial_copy_p (tree type, bool access, bool hasctor[2])
   11293              : {
   11294         5021 :   tree fns = get_class_binding (type, complete_ctor_identifier);
   11295         5021 :   bool all_trivial = true;
   11296              : 
   11297        25141 :   for (tree f : ovl_range (fns))
   11298              :     {
   11299              :       /* Skip template constructors.  */
   11300        12602 :       if (TREE_CODE (f) != FUNCTION_DECL)
   11301          105 :         continue;
   11302              : 
   11303        12497 :       bool cpy_or_move_ctor_p = copy_fn_p (f);
   11304              : 
   11305              :       /* Skip ctors other than default, copy, and move.  */
   11306        12497 :       if (!cpy_or_move_ctor_p && !default_ctor_p (f))
   11307         2757 :         continue;
   11308              : 
   11309         9740 :       if (DECL_DELETED_FN (f))
   11310          306 :         continue;
   11311              : 
   11312         9434 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11313         9626 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11314              : 
   11315              :       if (accessible)
   11316         9314 :         hasctor[cpy_or_move_ctor_p] = true;
   11317              : 
   11318         9434 :       if (cpy_or_move_ctor_p && (!accessible || !trivial_fn_p (f)))
   11319              :         all_trivial = false;
   11320              : 
   11321              :       /* Break early when both properties have been determined.  */
   11322         9434 :       if (hasctor[0] && hasctor[1] && !all_trivial)
   11323              :         break;
   11324              :     }
   11325              : 
   11326         5021 :   return all_trivial;
   11327              : }
   11328              : 
   11329              : /* Issue a warning on a call to the built-in function FNDECL if it is
   11330              :    a raw memory write whose destination is not an object of (something
   11331              :    like) trivial or standard layout type with a non-deleted assignment
   11332              :    and copy ctor.  Detects const correctness violations, corrupting
   11333              :    references, virtual table pointers, and bypassing non-trivial
   11334              :    assignments.  */
   11335              : 
   11336              : static void
   11337        69680 : maybe_warn_class_memaccess (location_t loc, tree fndecl,
   11338              :                             const vec<tree, va_gc> *args)
   11339              : {
   11340              :   /* Except for bcopy where it's second, the destination pointer is
   11341              :      the first argument for all functions handled here.  Compute
   11342              :      the index of the destination and source arguments.  */
   11343        69680 :   unsigned dstidx = DECL_FUNCTION_CODE (fndecl) == BUILT_IN_BCOPY;
   11344        69680 :   unsigned srcidx = !dstidx;
   11345              : 
   11346        69680 :   tree dest = (*args)[dstidx];
   11347        69680 :   if (!TREE_TYPE (dest)
   11348        69680 :       || (TREE_CODE (TREE_TYPE (dest)) != ARRAY_TYPE
   11349        68488 :           && !INDIRECT_TYPE_P (TREE_TYPE (dest))))
   11350        66305 :     return;
   11351              : 
   11352        22354 :   tree srctype = NULL_TREE;
   11353              : 
   11354              :   /* Determine the type of the pointed-to object and whether it's
   11355              :      a complete class type.  */
   11356        22354 :   tree desttype = TREE_TYPE (TREE_TYPE (dest));
   11357              : 
   11358        22354 :   if (!desttype || !COMPLETE_TYPE_P (desttype) || !CLASS_TYPE_P (desttype))
   11359              :     return;
   11360              : 
   11361              :   /* Check to see if the raw memory call is made by a non-static member
   11362              :      function with THIS as the destination argument for the destination
   11363              :      type.  If so, and if the class has no non-trivial bases or members,
   11364              :      be more permissive.  */
   11365         5123 :   if (current_function_decl
   11366         5123 :       && DECL_OBJECT_MEMBER_FUNCTION_P (current_function_decl)
   11367         5390 :       && is_object_parameter (tree_strip_nop_conversions (dest)))
   11368              :     {
   11369          204 :       tree ctx = DECL_CONTEXT (current_function_decl);
   11370          204 :       bool special = same_type_ignoring_top_level_qualifiers_p (ctx, desttype);
   11371          204 :       tree binfo = TYPE_BINFO (ctx);
   11372              : 
   11373          204 :       if (special
   11374          204 :           && !BINFO_VTABLE (binfo)
   11375          378 :           && !first_non_trivial_field (desttype))
   11376              :         return;
   11377              :     }
   11378              : 
   11379              :   /* True if the class is trivial.  */
   11380         5021 :   bool trivial = trivial_type_p (desttype);
   11381              : 
   11382              :   /* Set to true if DESTYPE has an accessible copy assignment.  */
   11383         5021 :   bool hasassign = false;
   11384              :   /* True if all of the class' overloaded copy assignment operators
   11385              :      are all trivial (and not deleted) and at least one of them is
   11386              :      accessible.  */
   11387         5021 :   bool trivassign = has_trivial_copy_assign_p (desttype, true, &hasassign);
   11388              : 
   11389              :   /* Set to true if DESTTYPE has an accessible default and copy ctor,
   11390              :      respectively.  */
   11391         5021 :   bool hasctors[2] = { false, false };
   11392              : 
   11393              :   /* True if all of the class' overloaded copy constructors are all
   11394              :      trivial (and not deleted) and at least one of them is accessible.  */
   11395         5021 :   bool trivcopy = has_trivial_copy_p (desttype, true, hasctors);
   11396              : 
   11397              :   /* Set FLD to the first private/protected member of the class.  */
   11398         5021 :   tree fld = trivial ? first_non_public_field (desttype) : NULL_TREE;
   11399              : 
   11400              :   /* The warning format string.  */
   11401         5021 :   const char *warnfmt = NULL;
   11402              :   /* A suggested alternative to offer instead of the raw memory call.
   11403              :      Empty string when none can be come up with.  */
   11404         5021 :   const char *suggest = "";
   11405         5021 :   bool warned = false;
   11406              : 
   11407         5021 :   auto_diagnostic_group d;
   11408         5021 :   switch (DECL_FUNCTION_CODE (fndecl))
   11409              :     {
   11410          560 :     case BUILT_IN_MEMSET:
   11411          560 :       if (!integer_zerop (maybe_constant_value ((*args)[1])))
   11412              :         {
   11413              :           /* Diagnose setting non-copy-assignable or non-trivial types,
   11414              :              or types with a private member, to (potentially) non-zero
   11415              :              bytes.  Since the value of the bytes being written is unknown,
   11416              :              suggest using assignment instead (if one exists).  Also warn
   11417              :              for writes into objects for which zero-initialization doesn't
   11418              :              mean all bits clear (pointer-to-member data, where null is all
   11419              :              bits set).  Since the value being written is (most likely)
   11420              :              non-zero, simply suggest assignment (but not copy assignment).  */
   11421          196 :           suggest = "; use assignment instead";
   11422          196 :           if (!trivassign)
   11423              :             warnfmt = G_("%qD writing to an object of type %#qT with "
   11424              :                          "no trivial copy-assignment");
   11425          125 :           else if (!trivial)
   11426              :             warnfmt = G_("%qD writing to an object of non-trivial type %#qT%s");
   11427           85 :           else if (fld)
   11428              :             {
   11429           24 :               const char *access = TREE_PRIVATE (fld) ? "private" : "protected";
   11430           24 :               warned = warning_at (loc, OPT_Wclass_memaccess,
   11431              :                                    "%qD writing to an object of type %#qT with "
   11432              :                                    "%qs member %qD",
   11433              :                                    fndecl, desttype, access, fld);
   11434              :             }
   11435           61 :           else if (!zero_init_p (desttype))
   11436              :             warnfmt = G_("%qD writing to an object of type %#qT containing "
   11437              :                          "a pointer to data member%s");
   11438              : 
   11439              :           break;
   11440              :         }
   11441              :       /* Fall through.  */
   11442              : 
   11443          481 :     case BUILT_IN_BZERO:
   11444              :       /* Similarly to the above, diagnose clearing non-trivial or non-
   11445              :          standard layout objects, or objects of types with no assignmenmt.
   11446              :          Since the value being written is known to be zero, suggest either
   11447              :          copy assignment, copy ctor, or default ctor as an alternative,
   11448              :          depending on what's available.  */
   11449              : 
   11450          481 :       if (hasassign && hasctors[0])
   11451              :         suggest = G_("; use assignment or value-initialization instead");
   11452           49 :       else if (hasassign)
   11453              :         suggest = G_("; use assignment instead");
   11454           31 :       else if (hasctors[0])
   11455           16 :         suggest = G_("; use value-initialization instead");
   11456              : 
   11457          481 :       if (!trivassign)
   11458              :         warnfmt = G_("%qD clearing an object of type %#qT with "
   11459              :                      "no trivial copy-assignment%s");
   11460          374 :       else if (!trivial)
   11461              :         warnfmt =  G_("%qD clearing an object of non-trivial type %#qT%s");
   11462          304 :       else if (!zero_init_p (desttype))
   11463              :         warnfmt = G_("%qD clearing an object of type %#qT containing "
   11464              :                      "a pointer-to-member%s");
   11465              :       break;
   11466              : 
   11467         2437 :     case BUILT_IN_BCOPY:
   11468         2437 :     case BUILT_IN_MEMCPY:
   11469         2437 :     case BUILT_IN_MEMMOVE:
   11470         2437 :     case BUILT_IN_MEMPCPY:
   11471              :       /* Determine the type of the source object.  */
   11472         2437 :       srctype = TREE_TYPE ((*args)[srcidx]);
   11473         2437 :       if (!srctype || !INDIRECT_TYPE_P (srctype))
   11474            0 :         srctype = void_type_node;
   11475              :       else
   11476         2437 :         srctype = TREE_TYPE (srctype);
   11477              : 
   11478              :       /* Since it's impossible to determine whether the byte copy is
   11479              :          being used in place of assignment to an existing object or
   11480              :          as a substitute for initialization, assume it's the former.
   11481              :          Determine the best alternative to use instead depending on
   11482              :          what's not deleted.  */
   11483         2437 :       if (hasassign && hasctors[1])
   11484              :         suggest = G_("; use copy-assignment or copy-initialization instead");
   11485          488 :       else if (hasassign)
   11486              :         suggest = G_("; use copy-assignment instead");
   11487          341 :       else if (hasctors[1])
   11488          290 :         suggest = G_("; use copy-initialization instead");
   11489              : 
   11490         2437 :       if (!trivassign)
   11491              :         warnfmt = G_("%qD writing to an object of type %#qT with no trivial "
   11492              :                      "copy-assignment%s");
   11493         1639 :       else if (!trivially_copyable_p (desttype))
   11494              :         warnfmt = G_("%qD writing to an object of non-trivially copyable "
   11495              :                      "type %#qT%s");
   11496         1315 :       else if (!trivcopy)
   11497              :         warnfmt = G_("%qD writing to an object with a deleted copy constructor");
   11498              : 
   11499         1315 :       else if (!trivial
   11500          211 :                && !VOID_TYPE_P (srctype)
   11501          160 :                && !is_byte_access_type (srctype)
   11502         1412 :                && !same_type_ignoring_top_level_qualifiers_p (desttype,
   11503              :                                                               srctype))
   11504              :         {
   11505              :           /* Warn when copying into a non-trivial object from an object
   11506              :              of a different type other than void or char.  */
   11507           54 :           warned = warning_at (loc, OPT_Wclass_memaccess,
   11508              :                                "%qD copying an object of non-trivial type "
   11509              :                                "%#qT from an array of %#qT",
   11510              :                                fndecl, desttype, srctype);
   11511              :         }
   11512         1261 :       else if (fld
   11513          432 :                && !VOID_TYPE_P (srctype)
   11514          384 :                && !is_byte_access_type (srctype)
   11515         1549 :                && !same_type_ignoring_top_level_qualifiers_p (desttype,
   11516              :                                                               srctype))
   11517              :         {
   11518          216 :           const char *access = TREE_PRIVATE (fld) ? "private" : "protected";
   11519          216 :           warned = warning_at (loc, OPT_Wclass_memaccess,
   11520              :                                "%qD copying an object of type %#qT with "
   11521              :                                "%qs member %qD from an array of %#qT; use "
   11522              :                                "assignment or copy-initialization instead",
   11523              :                                fndecl, desttype, access, fld, srctype);
   11524              :         }
   11525         1045 :       else if (!trivial && vec_safe_length (args) > 2)
   11526              :         {
   11527          157 :           tree sz = maybe_constant_value ((*args)[2]);
   11528          157 :           if (!tree_fits_uhwi_p (sz))
   11529              :             break;
   11530              : 
   11531              :           /* Finally, warn on partial copies.  */
   11532           99 :           unsigned HOST_WIDE_INT typesize
   11533           99 :             = tree_to_uhwi (TYPE_SIZE_UNIT (desttype));
   11534           99 :           if (typesize == 0)
   11535              :             break;
   11536           96 :           if (unsigned HOST_WIDE_INT partial = tree_to_uhwi (sz) % typesize)
   11537           12 :             warned = warning_at (loc, OPT_Wclass_memaccess,
   11538              :                                  (typesize - partial > 1
   11539              :                                   ? G_("%qD writing to an object of "
   11540              :                                        "a non-trivial type %#qT leaves %wu "
   11541              :                                        "bytes unchanged")
   11542              :                                   : G_("%qD writing to an object of "
   11543              :                                        "a non-trivial type %#qT leaves %wu "
   11544              :                                        "byte unchanged")),
   11545              :                                  fndecl, desttype, typesize - partial);
   11546              :         }
   11547              :       break;
   11548              : 
   11549          261 :     case BUILT_IN_REALLOC:
   11550              : 
   11551          261 :       if (!trivially_copyable_p (desttype))
   11552              :         warnfmt = G_("%qD moving an object of non-trivially copyable type "
   11553              :                      "%#qT; use %<new%> and %<delete%> instead");
   11554          138 :       else if (!trivcopy)
   11555              :         warnfmt = G_("%qD moving an object of type %#qT with deleted copy "
   11556              :                      "constructor; use %<new%> and %<delete%> instead");
   11557          135 :       else if (!get_dtor (desttype, tf_none))
   11558              :         warnfmt = G_("%qD moving an object of type %#qT with deleted "
   11559              :                      "destructor");
   11560          126 :       else if (!trivial)
   11561              :         {
   11562           33 :           tree sz = maybe_constant_value ((*args)[1]);
   11563           33 :           if (TREE_CODE (sz) == INTEGER_CST
   11564           33 :               && tree_int_cst_lt (sz, TYPE_SIZE_UNIT (desttype)))
   11565              :             /* Finally, warn on reallocation into insufficient space.  */
   11566            7 :             warned = warning_at (loc, OPT_Wclass_memaccess,
   11567              :                                  "%qD moving an object of non-trivial type "
   11568              :                                  "%#qT and size %E into a region of size %E",
   11569            7 :                                  fndecl, desttype, TYPE_SIZE_UNIT (desttype),
   11570              :                                  sz);
   11571              :         }
   11572              :       break;
   11573              : 
   11574         1646 :     default:
   11575         1646 :       return;
   11576              :     }
   11577              : 
   11578          310 :   if (warnfmt)
   11579              :     {
   11580         1569 :       if (suggest)
   11581         1569 :         warned = warning_at (loc, OPT_Wclass_memaccess,
   11582              :                              warnfmt, fndecl, desttype, suggest);
   11583              :       else
   11584              :         warned = warning_at (loc, OPT_Wclass_memaccess,
   11585              :                              warnfmt, fndecl, desttype);
   11586              :     }
   11587              : 
   11588         3375 :   if (warned)
   11589         1879 :     inform (location_of (desttype), "%#qT declared here", desttype);
   11590         5021 : }
   11591              : 
   11592              : /* Build and return a call to FN, using NARGS arguments in ARGARRAY.
   11593              :    If FN is the result of resolving an overloaded target built-in,
   11594              :    ORIG_FNDECL is the original function decl, otherwise it is null.
   11595              :    This function performs no overload resolution, conversion, or other
   11596              :    high-level operations.  */
   11597              : 
   11598              : tree
   11599    171755342 : build_cxx_call (tree fn, int nargs, tree *argarray,
   11600              :                 tsubst_flags_t complain, tree orig_fndecl)
   11601              : {
   11602    171755342 :   tree fndecl;
   11603              : 
   11604              :   /* Remember roughly where this call is.  */
   11605    171755342 :   location_t loc = cp_expr_loc_or_input_loc (fn);
   11606    171755342 :   fn = build_call_a (fn, nargs, argarray);
   11607    171755342 :   SET_EXPR_LOCATION (fn, loc);
   11608              : 
   11609    171755342 :   fndecl = get_callee_fndecl (fn);
   11610    171755342 :   if (!orig_fndecl)
   11611    171755342 :     orig_fndecl = fndecl;
   11612              : 
   11613              :   /* Check that arguments to builtin functions match the expectations.  */
   11614    171755342 :   if (fndecl
   11615    165022741 :       && !processing_template_decl
   11616    336723272 :       && fndecl_built_in_p (fndecl))
   11617              :     {
   11618              :       int i;
   11619              : 
   11620              :       /* We need to take care that values to BUILT_IN_NORMAL
   11621              :          are reduced.  */
   11622     22595006 :       for (i = 0; i < nargs; i++)
   11623     14796944 :         argarray[i] = maybe_constant_value (argarray[i]);
   11624              : 
   11625      7798062 :       if (!check_builtin_function_arguments (EXPR_LOCATION (fn), vNULL, fndecl,
   11626              :                                              orig_fndecl, nargs, argarray,
   11627              :                                              complain & tf_error))
   11628          927 :         return error_mark_node;
   11629      7797135 :       else if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING))
   11630              :         {
   11631        14598 :           tree arg0 = argarray[0];
   11632        14598 :           STRIP_NOPS (arg0);
   11633        14598 :           if (TREE_CODE (arg0) == ADDR_EXPR
   11634          264 :               && DECL_P (TREE_OPERAND (arg0, 0))
   11635        14841 :               && same_type_ignoring_top_level_qualifiers_p
   11636          243 :                         (TREE_TYPE (TREE_TYPE (argarray[0])),
   11637          243 :                          TREE_TYPE (TREE_TYPE (arg0))))
   11638              :             /* For __builtin_clear_padding (&var) we know the type
   11639              :                is for a complete object, so there is no risk in clearing
   11640              :                padding that is reused in some derived class member.  */;
   11641        14362 :           else if (!trivially_copyable_p (TREE_TYPE (TREE_TYPE (argarray[0]))))
   11642              :             {
   11643           18 :               error_at (EXPR_LOC_OR_LOC (argarray[0], input_location),
   11644              :                         "argument %u in call to function %qE "
   11645              :                         "has pointer to a non-trivially-copyable type (%qT)",
   11646           18 :                         1, fndecl, TREE_TYPE (argarray[0]));
   11647           18 :               return error_mark_node;
   11648              :             }
   11649              :         }
   11650              :     }
   11651              : 
   11652    171754397 :   if (VOID_TYPE_P (TREE_TYPE (fn)))
   11653     38008404 :     return maybe_contract_wrap_call (fndecl, fn);
   11654              : 
   11655              :   /* 5.2.2/11: If a function call is a prvalue of object type: if the
   11656              :      function call is either the operand of a decltype-specifier or the
   11657              :      right operand of a comma operator that is the operand of a
   11658              :      decltype-specifier, a temporary object is not introduced for the
   11659              :      prvalue. The type of the prvalue may be incomplete.  */
   11660    133745993 :   if (!(complain & tf_decltype))
   11661              :     {
   11662    110630177 :       fn = require_complete_type (fn, complain);
   11663    110630177 :       if (fn == error_mark_node)
   11664              :         return error_mark_node;
   11665    110630151 :       fn = maybe_contract_wrap_call (fndecl, fn);
   11666              : 
   11667    110630151 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (fn)))
   11668              :         {
   11669     12567236 :           fn = build_cplus_new (TREE_TYPE (fn), fn, complain);
   11670     12567236 :           maybe_warn_parm_abi (TREE_TYPE (fn), loc);
   11671              :         }
   11672              :     }
   11673              :   else
   11674     23115816 :     fn = maybe_contract_wrap_call (fndecl, fn);
   11675    133745967 :   return convert_from_reference (fn);
   11676              : }
   11677              : 
   11678              : /* Returns the value to use for the in-charge parameter when making a
   11679              :    call to a function with the indicated NAME.
   11680              : 
   11681              :    FIXME:Can't we find a neater way to do this mapping?  */
   11682              : 
   11683              : tree
   11684        37208 : in_charge_arg_for_name (tree name)
   11685              : {
   11686        37208 :   if (IDENTIFIER_CTOR_P (name))
   11687              :     {
   11688        21290 :       if (name == complete_ctor_identifier)
   11689        10645 :         return integer_one_node;
   11690        10645 :       gcc_checking_assert (name == base_ctor_identifier);
   11691              :     }
   11692              :   else
   11693              :     {
   11694        15918 :       if (name == complete_dtor_identifier)
   11695         7959 :         return integer_two_node;
   11696         7959 :       else if (name == deleting_dtor_identifier)
   11697              :         /* The deleting dtor should now be handled by
   11698              :            build_delete_destructor_body.  */
   11699            0 :         gcc_unreachable ();
   11700         7959 :       gcc_checking_assert (name == base_dtor_identifier);
   11701              :     }
   11702              : 
   11703        18604 :   return integer_zero_node;
   11704              : }
   11705              : 
   11706              : /* We've built up a constructor call RET.  Complain if it delegates to the
   11707              :    constructor we're currently compiling.  */
   11708              : 
   11709              : static void
   11710       366965 : check_self_delegation (tree ret)
   11711              : {
   11712       366965 :   if (TREE_CODE (ret) == TARGET_EXPR)
   11713            0 :     ret = TARGET_EXPR_INITIAL (ret);
   11714       366965 :   tree fn = cp_get_callee_fndecl_nofold (ret);
   11715       366965 :   if (fn && DECL_ABSTRACT_ORIGIN (fn) == current_function_decl)
   11716           46 :     error ("constructor delegates to itself");
   11717       366965 : }
   11718              : 
   11719              : /* Build a call to a constructor, destructor, or an assignment
   11720              :    operator for INSTANCE, an expression with class type.  NAME
   11721              :    indicates the special member function to call; *ARGS are the
   11722              :    arguments.  ARGS may be NULL.  This may change ARGS.  BINFO
   11723              :    indicates the base of INSTANCE that is to be passed as the `this'
   11724              :    parameter to the member function called.
   11725              : 
   11726              :    FLAGS are the LOOKUP_* flags to use when processing the call.
   11727              : 
   11728              :    If NAME indicates a complete object constructor, INSTANCE may be
   11729              :    NULL_TREE.  In this case, the caller will call build_cplus_new to
   11730              :    store the newly constructed object into a VAR_DECL.  */
   11731              : 
   11732              : tree
   11733     40356707 : build_special_member_call (tree instance, tree name, vec<tree, va_gc> **args,
   11734              :                            tree binfo, int flags, tsubst_flags_t complain)
   11735              : {
   11736     40356707 :   tree fns;
   11737              :   /* The type of the subobject to be constructed or destroyed.  */
   11738     40356707 :   tree class_type;
   11739     40356707 :   vec<tree, va_gc> *allocated = NULL;
   11740     40356707 :   tree ret;
   11741              : 
   11742     40356707 :   gcc_assert (IDENTIFIER_CDTOR_P (name) || name == assign_op_identifier);
   11743              : 
   11744     40356707 :   if (error_operand_p (instance))
   11745            0 :     return error_mark_node;
   11746              : 
   11747     40356707 :   if (IDENTIFIER_DTOR_P (name))
   11748              :     {
   11749     10984890 :       gcc_assert (args == NULL || vec_safe_is_empty (*args));
   11750     10984890 :       if (!type_build_dtor_call (TREE_TYPE (instance)))
   11751              :         /* Shortcut to avoid lazy destructor declaration.  */
   11752         1502 :         return build_trivial_dtor_call (instance);
   11753              :     }
   11754              : 
   11755     40355205 :   if (TYPE_P (binfo))
   11756              :     {
   11757              :       /* Resolve the name.  */
   11758     32263157 :       if (!complete_type_or_maybe_complain (binfo, NULL_TREE, complain))
   11759            6 :         return error_mark_node;
   11760              : 
   11761     32263151 :       binfo = TYPE_BINFO (binfo);
   11762              :     }
   11763              : 
   11764     32263151 :   gcc_assert (binfo != NULL_TREE);
   11765              : 
   11766     40355199 :   class_type = BINFO_TYPE (binfo);
   11767              : 
   11768              :   /* Handle the special case where INSTANCE is NULL_TREE.  */
   11769     40355199 :   if (name == complete_ctor_identifier && !instance)
   11770     21405337 :     instance = build_dummy_object (class_type);
   11771              :   else
   11772              :     {
   11773              :       /* Convert to the base class, if necessary.  */
   11774     18949862 :       if (!same_type_ignoring_top_level_qualifiers_p
   11775     18949862 :           (TREE_TYPE (instance), BINFO_TYPE (binfo)))
   11776              :         {
   11777      1667070 :           if (IDENTIFIER_CDTOR_P (name))
   11778              :             /* For constructors and destructors, either the base is
   11779              :                non-virtual, or it is virtual but we are doing the
   11780              :                conversion from a constructor or destructor for the
   11781              :                complete object.  In either case, we can convert
   11782              :                statically.  */
   11783      1647077 :             instance = convert_to_base_statically (instance, binfo);
   11784              :           else
   11785              :             {
   11786              :               /* However, for assignment operators, we must convert
   11787              :                  dynamically if the base is virtual.  */
   11788        19993 :               gcc_checking_assert (name == assign_op_identifier);
   11789        19993 :               instance = build_base_path (PLUS_EXPR, instance,
   11790              :                                           binfo, /*nonnull=*/1, complain);
   11791              :             }
   11792              :         }
   11793              :     }
   11794              : 
   11795     40355199 :   gcc_assert (instance != NULL_TREE);
   11796              : 
   11797              :   /* In C++17, "If the initializer expression is a prvalue and the
   11798              :      cv-unqualified version of the source type is the same class as the class
   11799              :      of the destination, the initializer expression is used to initialize the
   11800              :      destination object."  Handle that here to avoid doing overload
   11801              :      resolution.  */
   11802     40355199 :   if (cxx_dialect >= cxx17
   11803     40155864 :       && args && vec_safe_length (*args) == 1
   11804     64454414 :       && !unsafe_return_slot_p (instance))
   11805              :     {
   11806     22788767 :       tree arg = (**args)[0];
   11807              : 
   11808      1729544 :       if (BRACE_ENCLOSED_INITIALIZER_P (arg)
   11809      1729172 :           && !TYPE_HAS_LIST_CTOR (class_type)
   11810      1652913 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (arg)
   11811     24441663 :           && CONSTRUCTOR_NELTS (arg) == 1)
   11812      1169217 :         arg = CONSTRUCTOR_ELT (arg, 0)->value;
   11813              : 
   11814     22788767 :       if ((TREE_CODE (arg) == TARGET_EXPR
   11815     11045078 :            || TREE_CODE (arg) == CONSTRUCTOR)
   11816     35092857 :           && (same_type_ignoring_top_level_qualifiers_p
   11817     12304090 :               (class_type, TREE_TYPE (arg))))
   11818              :         {
   11819     11116510 :           if (is_dummy_object (instance))
   11820              :             return arg;
   11821       236843 :           else if (TREE_CODE (arg) == TARGET_EXPR)
   11822       236843 :             TARGET_EXPR_DIRECT_INIT_P (arg) = true;
   11823              : 
   11824       236843 :           if ((complain & tf_error)
   11825       236841 :               && (flags & LOOKUP_DELEGATING_CONS))
   11826            0 :             check_self_delegation (arg);
   11827              :           /* Avoid change of behavior on Wunused-var-2.C.  */
   11828       236843 :           instance = mark_lvalue_use (instance);
   11829       236843 :           return cp_build_init_expr (instance, arg);
   11830              :         }
   11831              :     }
   11832              : 
   11833     29238689 :   fns = lookup_fnfields (binfo, name, 1, complain);
   11834              : 
   11835              :   /* When making a call to a constructor or destructor for a subobject
   11836              :      that uses virtual base classes, pass down a pointer to a VTT for
   11837              :      the subobject.  */
   11838     29238689 :   if ((name == base_ctor_identifier
   11839     26821117 :        || name == base_dtor_identifier)
   11840     30885846 :       && CLASSTYPE_VBASECLASSES (class_type))
   11841              :     {
   11842        48381 :       tree vtt;
   11843        48381 :       tree sub_vtt;
   11844              : 
   11845              :       /* If the current function is a complete object constructor
   11846              :          or destructor, then we fetch the VTT directly.
   11847              :          Otherwise, we look it up using the VTT we were given.  */
   11848        48381 :       vtt = DECL_CHAIN (CLASSTYPE_VTABLES (current_class_type));
   11849        48381 :       vtt = decay_conversion (vtt, complain);
   11850        48381 :       if (vtt == error_mark_node)
   11851            0 :         return error_mark_node;
   11852        48381 :       vtt = build_if_in_charge (vtt, current_vtt_parm);
   11853        48381 :       if (BINFO_SUBVTT_INDEX (binfo))
   11854        48201 :         sub_vtt = fold_build_pointer_plus (vtt, BINFO_SUBVTT_INDEX (binfo));
   11855              :       else
   11856              :         sub_vtt = vtt;
   11857              : 
   11858        48381 :       if (args == NULL)
   11859              :         {
   11860        30716 :           allocated = make_tree_vector ();
   11861        30716 :           args = &allocated;
   11862              :         }
   11863              : 
   11864        48381 :       vec_safe_insert (*args, 0, sub_vtt);
   11865              :     }
   11866              : 
   11867     58477378 :   ret = build_new_method_call (instance, fns, args,
   11868     29238689 :                                TYPE_BINFO (BINFO_TYPE (binfo)),
   11869              :                                flags, /*fn=*/NULL,
   11870              :                                complain);
   11871              : 
   11872     29238689 :   if (allocated != NULL)
   11873        30716 :     release_tree_vector (allocated);
   11874              : 
   11875     29238689 :   if ((complain & tf_error)
   11876     26010927 :       && (flags & LOOKUP_DELEGATING_CONS)
   11877       367065 :       && name == complete_ctor_identifier)
   11878       366965 :     check_self_delegation (ret);
   11879              : 
   11880              :   return ret;
   11881              : }
   11882              : 
   11883              : /* Return the NAME, as a C string.  The NAME indicates a function that
   11884              :    is a member of TYPE.  *FREE_P is set to true if the caller must
   11885              :    free the memory returned.
   11886              : 
   11887              :    Rather than go through all of this, we should simply set the names
   11888              :    of constructors and destructors appropriately, and dispense with
   11889              :    ctor_identifier, dtor_identifier, etc.  */
   11890              : 
   11891              : static char *
   11892           93 : name_as_c_string (tree name, tree type, bool *free_p)
   11893              : {
   11894           93 :   const char *pretty_name;
   11895              : 
   11896              :   /* Assume that we will not allocate memory.  */
   11897           93 :   *free_p = false;
   11898              :   /* Constructors and destructors are special.  */
   11899           93 :   if (IDENTIFIER_CDTOR_P (name))
   11900              :     {
   11901           42 :       pretty_name
   11902           42 :         = identifier_to_locale (IDENTIFIER_POINTER (constructor_name (type)));
   11903              :       /* For a destructor, add the '~'.  */
   11904           42 :       if (IDENTIFIER_DTOR_P (name))
   11905              :         {
   11906            0 :           pretty_name = concat ("~", pretty_name, NULL);
   11907              :           /* Remember that we need to free the memory allocated.  */
   11908            0 :           *free_p = true;
   11909              :         }
   11910              :     }
   11911           51 :   else if (IDENTIFIER_CONV_OP_P (name))
   11912              :     {
   11913            0 :       pretty_name = concat ("operator ",
   11914            0 :                             type_as_string_translate (TREE_TYPE (name),
   11915              :                                                       TFF_PLAIN_IDENTIFIER),
   11916              :                             NULL);
   11917              :       /* Remember that we need to free the memory allocated.  */
   11918            0 :       *free_p = true;
   11919              :     }
   11920              :   else
   11921           51 :     pretty_name = identifier_to_locale (IDENTIFIER_POINTER (name));
   11922              : 
   11923           93 :   return const_cast<char *> (pretty_name);
   11924              : }
   11925              : 
   11926              : /* If CANDIDATES contains exactly one candidate, return it, otherwise
   11927              :    return NULL.  */
   11928              : 
   11929              : static z_candidate *
   11930          683 : single_z_candidate (z_candidate *candidates)
   11931              : {
   11932            0 :   if (candidates == NULL)
   11933              :     return NULL;
   11934              : 
   11935          668 :   if (candidates->next)
   11936            0 :     return NULL;
   11937              : 
   11938              :   return candidates;
   11939              : }
   11940              : 
   11941              : /* If CANDIDATE is invalid due to a bad argument type, return the
   11942              :    pertinent conversion_info.
   11943              : 
   11944              :    Otherwise, return NULL.  */
   11945              : 
   11946              : static const conversion_info *
   11947          339 : maybe_get_bad_conversion_for_unmatched_call (const z_candidate *candidate)
   11948              : {
   11949              :   /* Must be an rr_arg_conversion or rr_bad_arg_conversion.  */
   11950          339 :   rejection_reason *r = candidate->reason;
   11951              : 
   11952          339 :   if (r == NULL)
   11953              :     return NULL;
   11954              : 
   11955          339 :   switch (r->code)
   11956              :     {
   11957              :     default:
   11958              :       return NULL;
   11959              : 
   11960           52 :     case rr_arg_conversion:
   11961           52 :       return &r->u.conversion;
   11962              : 
   11963            6 :     case rr_bad_arg_conversion:
   11964            6 :       return &r->u.bad_conversion;
   11965              :     }
   11966              : }
   11967              : 
   11968              : /* Issue an error and note complaining about a bad argument type at a
   11969              :    callsite with a single candidate FNDECL.
   11970              : 
   11971              :    ARG_LOC is the location of the argument (or UNKNOWN_LOCATION, in which
   11972              :    case input_location is used).
   11973              :    FROM_TYPE is the type of the actual argument; TO_TYPE is the type of
   11974              :    the formal parameter.  */
   11975              : 
   11976              : void
   11977          198 : complain_about_bad_argument (location_t arg_loc,
   11978              :                              tree from_type, tree to_type,
   11979              :                              tree fndecl, int parmnum)
   11980              : {
   11981          198 :   auto_diagnostic_group d;
   11982          198 :   range_label_for_type_mismatch rhs_label (from_type, to_type);
   11983          198 :   range_label *label = &rhs_label;
   11984          198 :   if (arg_loc == UNKNOWN_LOCATION)
   11985              :     {
   11986            6 :       arg_loc = input_location;
   11987            6 :       label = NULL;
   11988              :     }
   11989          198 :   gcc_rich_location richloc (arg_loc, label, highlight_colors::percent_h);
   11990          198 :   error_at (&richloc,
   11991              :             "cannot convert %qH to %qI",
   11992              :             from_type, to_type);
   11993          198 :   maybe_inform_about_fndecl_for_bogus_argument_init
   11994          198 :     (fndecl,
   11995              :      parmnum,
   11996              :      highlight_colors::percent_i);
   11997          198 : }
   11998              : 
   11999              : /* Subroutine of build_new_method_call_1, for where there are no viable
   12000              :    candidates for the call.  */
   12001              : 
   12002              : static void
   12003          689 : complain_about_no_candidates_for_method_call (tree instance,
   12004              :                                               z_candidate *candidates,
   12005              :                                               tree explicit_targs,
   12006              :                                               tree basetype,
   12007              :                                               tree optype, tree name,
   12008              :                                               bool skip_first_for_error,
   12009              :                                               vec<tree, va_gc> *user_args)
   12010              : {
   12011          689 :   auto_diagnostic_group d;
   12012          689 :   if (!COMPLETE_OR_OPEN_TYPE_P (basetype))
   12013            0 :     cxx_incomplete_type_error (instance, basetype);
   12014          689 :   else if (optype)
   12015            6 :     error ("no matching function for call to %<%T::operator %T(%A)%#V%>",
   12016              :            basetype, optype, build_tree_list_vec (user_args),
   12017            6 :            TREE_TYPE (instance));
   12018              :   else
   12019              :     {
   12020              :       /* Special-case for when there's a single candidate that's failing
   12021              :          due to a bad argument type.  */
   12022          683 :       if (z_candidate *candidate = single_z_candidate (candidates))
   12023          339 :           if (const conversion_info *conv
   12024          339 :                 = maybe_get_bad_conversion_for_unmatched_call (candidate))
   12025              :             {
   12026           58 :               tree from_type = conv->from;
   12027           58 :               if (!TYPE_P (conv->from))
   12028            6 :                 from_type = lvalue_type (conv->from);
   12029           58 :               complain_about_bad_argument (conv->loc,
   12030           58 :                                            from_type, conv->to_type,
   12031           58 :                                            candidate->fn, conv->n_arg);
   12032           58 :               return;
   12033              :             }
   12034              : 
   12035          625 :       tree arglist = build_tree_list_vec (user_args);
   12036          625 :       tree errname = name;
   12037          625 :       bool twiddle = false;
   12038          625 :       if (IDENTIFIER_CDTOR_P (errname))
   12039              :         {
   12040          322 :           twiddle = IDENTIFIER_DTOR_P (errname);
   12041          322 :           errname = constructor_name (basetype);
   12042              :         }
   12043          625 :       if (explicit_targs)
   12044           48 :         errname = lookup_template_function (errname, explicit_targs);
   12045          625 :       if (skip_first_for_error)
   12046            3 :         arglist = TREE_CHAIN (arglist);
   12047         1250 :       error ("no matching function for call to %<%T::%s%E(%A)%#V%>",
   12048          625 :              basetype, &"~"[!twiddle], errname, arglist,
   12049          625 :              TREE_TYPE (instance));
   12050              :     }
   12051          631 :   print_z_candidates (location_of (name), candidates);
   12052          689 : }
   12053              : 
   12054              : /* Build a call to "INSTANCE.FN (ARGS)".  If FN_P is non-NULL, it will
   12055              :    be set, upon return, to the function called.  ARGS may be NULL.
   12056              :    This may change ARGS.  */
   12057              : 
   12058              : tree
   12059    101875700 : build_new_method_call (tree instance, tree fns, vec<tree, va_gc> **args,
   12060              :                        tree conversion_path, int flags,
   12061              :                        tree *fn_p, tsubst_flags_t complain)
   12062              : {
   12063    101875700 :   struct z_candidate *candidates = 0, *cand;
   12064    101875700 :   tree explicit_targs = NULL_TREE;
   12065    101875700 :   tree basetype = NULL_TREE;
   12066    101875700 :   tree access_binfo;
   12067    101875700 :   tree optype;
   12068    101875700 :   tree first_mem_arg = NULL_TREE;
   12069    101875700 :   tree name;
   12070    101875700 :   bool skip_first_for_error;
   12071    101875700 :   vec<tree, va_gc> *user_args;
   12072    101875700 :   tree call;
   12073    101875700 :   tree fn;
   12074    101875700 :   int template_only = 0;
   12075    101875700 :   bool any_viable_p;
   12076    101875700 :   tree orig_instance;
   12077    101875700 :   tree orig_fns;
   12078    101875700 :   vec<tree, va_gc> *orig_args = NULL;
   12079              : 
   12080    101875700 :   auto_cond_timevar tv (TV_OVERLOAD);
   12081              : 
   12082    101875700 :   gcc_assert (instance != NULL_TREE);
   12083              : 
   12084              :   /* We don't know what function we're going to call, yet.  */
   12085    101875700 :   if (fn_p)
   12086     28590248 :     *fn_p = NULL_TREE;
   12087              : 
   12088    101875700 :   if (error_operand_p (instance)
   12089    101875700 :       || !fns || error_operand_p (fns))
   12090      1471152 :     return error_mark_node;
   12091              : 
   12092    100404548 :   if (!BASELINK_P (fns))
   12093              :     {
   12094            0 :       if (complain & tf_error)
   12095            0 :         error ("call to non-function %qD", fns);
   12096            0 :       return error_mark_node;
   12097              :     }
   12098              : 
   12099    100404548 :   orig_instance = instance;
   12100    100404548 :   orig_fns = fns;
   12101              : 
   12102              :   /* Dismantle the baselink to collect all the information we need.  */
   12103    100404548 :   if (!conversion_path)
   12104     44061042 :     conversion_path = BASELINK_BINFO (fns);
   12105    100404548 :   access_binfo = BASELINK_ACCESS_BINFO (fns);
   12106    100404548 :   optype = BASELINK_OPTYPE (fns);
   12107    100404548 :   fns = BASELINK_FUNCTIONS (fns);
   12108    100404548 :   if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
   12109              :     {
   12110      2743147 :       explicit_targs = TREE_OPERAND (fns, 1);
   12111      2743147 :       fns = TREE_OPERAND (fns, 0);
   12112      2743147 :       template_only = 1;
   12113              :     }
   12114    100404548 :   gcc_assert (OVL_P (fns));
   12115    100404548 :   fn = OVL_FIRST (fns);
   12116    100404548 :   name = DECL_NAME (fn);
   12117              : 
   12118    100404548 :   basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
   12119    100404548 :   gcc_assert (CLASS_TYPE_P (basetype));
   12120              : 
   12121    100404548 :   user_args = args == NULL ? NULL : *args;
   12122              :   /* Under DR 147 A::A() is an invalid constructor call,
   12123              :      not a functional cast.  */
   12124    100404548 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
   12125              :     {
   12126           54 :       if (! (complain & tf_error))
   12127            0 :         return error_mark_node;
   12128              : 
   12129           54 :       basetype = DECL_CONTEXT (fn);
   12130           54 :       name = constructor_name (basetype);
   12131           54 :       auto_diagnostic_group d;
   12132           54 :       if (permerror (input_location,
   12133              :                      "cannot call constructor %<%T::%D%> directly",
   12134              :                      basetype, name))
   12135           54 :         inform (input_location, "for a function-style cast, remove the "
   12136              :                 "redundant %<::%D%>", name);
   12137           54 :       call = build_functional_cast (input_location, basetype,
   12138              :                                     build_tree_list_vec (user_args),
   12139              :                                     complain);
   12140           54 :       return call;
   12141           54 :     }
   12142              : 
   12143    100404494 :   if (processing_template_decl)
   12144      7206046 :     orig_args = args == NULL ? NULL : make_tree_vector_copy (*args);
   12145              : 
   12146              :   /* Process the argument list.  */
   12147    100318910 :   if (args != NULL && *args != NULL)
   12148              :     {
   12149     85515742 :       *args = resolve_args (*args, complain);
   12150     85515742 :       if (*args == NULL)
   12151          189 :         return error_mark_node;
   12152              :       user_args = *args;
   12153              :     }
   12154              : 
   12155              :   /* Consider the object argument to be used even if we end up selecting a
   12156              :      static member function.  */
   12157    100404305 :   instance = mark_type_use (instance);
   12158              : 
   12159              :   /* Figure out whether to skip the first argument for the error
   12160              :      message we will display to users if an error occurs.  We don't
   12161              :      want to display any compiler-generated arguments.  The "this"
   12162              :      pointer hasn't been added yet.  However, we must remove the VTT
   12163              :      pointer if this is a call to a base-class constructor or
   12164              :      destructor.  */
   12165    100404305 :   skip_first_for_error = false;
   12166    100404305 :   if (IDENTIFIER_CDTOR_P (name))
   12167              :     {
   12168              :       /* Callers should explicitly indicate whether they want to ctor
   12169              :          the complete object or just the part without virtual bases.  */
   12170     53563534 :       gcc_assert (name != ctor_identifier);
   12171              : 
   12172              :       /* Remove the VTT pointer, if present.  */
   12173     51145968 :       if ((name == base_ctor_identifier || name == base_dtor_identifier)
   12174     55210691 :           && CLASSTYPE_VBASECLASSES (basetype))
   12175              :         skip_first_for_error = true;
   12176              : 
   12177              :       /* It's OK to call destructors and constructors on cv-qualified
   12178              :          objects.  Therefore, convert the INSTANCE to the unqualified
   12179              :          type, if necessary.  */
   12180     53563534 :       if (!same_type_p (basetype, TREE_TYPE (instance)))
   12181              :         {
   12182       706971 :           instance = build_this (instance);
   12183       706971 :           instance = build_nop (build_pointer_type (basetype), instance);
   12184       706971 :           instance = build_fold_indirect_ref (instance);
   12185              :         }
   12186              :     }
   12187              :   else
   12188     93681542 :     gcc_assert (!DECL_DESTRUCTOR_P (fn) && !DECL_CONSTRUCTOR_P (fn));
   12189              : 
   12190              :   /* For the overload resolution we need to find the actual `this`
   12191              :      that would be captured if the call turns out to be to a
   12192              :      non-static member function.  Do not actually capture it at this
   12193              :      point.  */
   12194    200808610 :   if (DECL_CONSTRUCTOR_P (fn))
   12195              :     /* Constructors don't use the enclosing 'this'.  */
   12196              :     first_mem_arg = instance;
   12197              :   else
   12198     73530214 :     first_mem_arg = maybe_resolve_dummy (instance, false);
   12199              : 
   12200    100404305 :   conversion_obstack_sentinel cos;
   12201              : 
   12202              :   /* The number of arguments artificial parms in ARGS; we subtract one because
   12203              :      there's no 'this' in ARGS.  */
   12204    100404305 :   unsigned skip = num_artificial_parms_for (fn) - 1;
   12205              : 
   12206              :   /* If CONSTRUCTOR_IS_DIRECT_INIT is set, this was a T{ } form
   12207              :      initializer, not T({ }).  */
   12208    100404305 :   if (DECL_CONSTRUCTOR_P (fn)
   12209     22958980 :       && vec_safe_length (user_args) > skip
   12210    121079903 :       && DIRECT_LIST_INIT_P ((*user_args)[skip]))
   12211              :     {
   12212      1731123 :       tree init_list = (*user_args)[skip];
   12213      1731123 :       tree init = NULL_TREE;
   12214              : 
   12215      1731123 :       gcc_assert (user_args->length () == skip + 1
   12216              :                   && !(flags & LOOKUP_ONLYCONVERTING));
   12217              : 
   12218              :       /* If the initializer list has no elements and T is a class type with
   12219              :          a default constructor, the object is value-initialized.  Handle
   12220              :          this here so we don't need to handle it wherever we use
   12221              :          build_special_member_call.  */
   12222      1731123 :       if (CONSTRUCTOR_NELTS (init_list) == 0
   12223       197381 :           && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
   12224              :           /* For a user-provided default constructor, use the normal
   12225              :              mechanisms so that protected access works.  */
   12226       197381 :           && type_has_non_user_provided_default_constructor (basetype)
   12227      1656968 :           && !processing_template_decl)
   12228       123223 :         init = build_value_init (basetype, complain);
   12229              : 
   12230              :       /* If BASETYPE is an aggregate, we need to do aggregate
   12231              :          initialization.  */
   12232      1607900 :       else if (CP_AGGREGATE_TYPE_P (basetype))
   12233              :         {
   12234           41 :           init = reshape_init (basetype, init_list, complain);
   12235           41 :           init = digest_init (basetype, init, complain);
   12236              :         }
   12237              : 
   12238       123264 :       if (init)
   12239              :         {
   12240       123264 :           if (is_dummy_object (instance))
   12241        36223 :             return get_target_expr (init, complain);
   12242        87041 :           return cp_build_init_expr (instance, init);
   12243              :         }
   12244              : 
   12245              :       /* Otherwise go ahead with overload resolution.  */
   12246      1607859 :       add_list_candidates (fns, first_mem_arg, user_args,
   12247              :                            basetype, explicit_targs, template_only,
   12248              :                            conversion_path, access_binfo, flags,
   12249              :                            &candidates, complain);
   12250              :     }
   12251              :   else
   12252     98673182 :     add_candidates (fns, first_mem_arg, user_args, optype,
   12253              :                     explicit_targs, template_only, conversion_path,
   12254              :                     access_binfo, flags, &candidates, complain);
   12255              : 
   12256    100281041 :   any_viable_p = false;
   12257    100281041 :   candidates = splice_viable (candidates, false, &any_viable_p);
   12258              : 
   12259    100281041 :   if (!any_viable_p)
   12260              :     {
   12261              :       /* [dcl.init], 17.6.2.2:
   12262              : 
   12263              :          Otherwise, if no constructor is viable, the destination type is
   12264              :          a (possibly cv-qualified) aggregate class A, and the initializer
   12265              :          is a parenthesized expression-list, the object is initialized as
   12266              :          follows...
   12267              : 
   12268              :          We achieve this by building up a CONSTRUCTOR, as for list-init,
   12269              :          and setting CONSTRUCTOR_IS_PAREN_INIT to distinguish between
   12270              :          the two.  */
   12271        27381 :       if (DECL_CONSTRUCTOR_P (fn)
   12272        20608 :           && !(flags & LOOKUP_ONLYCONVERTING)
   12273        20584 :           && cxx_dialect >= cxx20
   12274        19963 :           && CP_AGGREGATE_TYPE_P (basetype)
   12275        27381 :           && !vec_safe_is_empty (user_args))
   12276              :         {
   12277              :           /* Create a CONSTRUCTOR from ARGS, e.g. {1, 2} from <1, 2>.  */
   12278         1171 :           tree ctor = build_constructor_from_vec (init_list_type_node,
   12279              :                                                   user_args);
   12280         1171 :           CONSTRUCTOR_IS_DIRECT_INIT (ctor) = true;
   12281         1171 :           CONSTRUCTOR_IS_PAREN_INIT (ctor) = true;
   12282         1171 :           if (is_dummy_object (instance))
   12283              :             return ctor;
   12284              :           else
   12285              :             {
   12286          677 :               ctor = digest_init (basetype, ctor, complain);
   12287          677 :               if (ctor == error_mark_node)
   12288              :                 return error_mark_node;
   12289          457 :               return cp_build_init_expr (instance, ctor);
   12290              :             }
   12291              :         }
   12292        26210 :       if (complain & tf_error)
   12293          689 :         complain_about_no_candidates_for_method_call (instance, candidates,
   12294              :                                                       explicit_targs, basetype,
   12295              :                                                       optype, name,
   12296              :                                                       skip_first_for_error,
   12297              :                                                       user_args);
   12298        26210 :       call = error_mark_node;
   12299              :     }
   12300              :   else
   12301              :     {
   12302    100253660 :       cand = tourney (candidates, complain);
   12303    100253660 :       if (cand == 0)
   12304              :         {
   12305          193 :           char *pretty_name;
   12306          193 :           bool free_p;
   12307          193 :           tree arglist;
   12308              : 
   12309          193 :           if (complain & tf_error)
   12310              :             {
   12311           93 :               pretty_name = name_as_c_string (name, basetype, &free_p);
   12312           93 :               arglist = build_tree_list_vec (user_args);
   12313           93 :               if (skip_first_for_error)
   12314            0 :                 arglist = TREE_CHAIN (arglist);
   12315           93 :               auto_diagnostic_group d;
   12316          186 :               if (!any_strictly_viable (candidates))
   12317           13 :                 error ("no matching function for call to %<%s(%A)%>",
   12318              :                        pretty_name, arglist);
   12319              :               else
   12320           80 :                 error ("call of overloaded %<%s(%A)%> is ambiguous",
   12321              :                        pretty_name, arglist);
   12322           93 :               print_z_candidates (location_of (name), candidates);
   12323           93 :               if (free_p)
   12324            0 :                 free (pretty_name);
   12325           93 :             }
   12326          193 :           call = error_mark_node;
   12327          193 :           if (fn_p)
   12328           84 :             *fn_p = error_mark_node;
   12329              :         }
   12330              :       else
   12331              :         {
   12332    100253467 :           fn = cand->fn;
   12333    100253467 :           call = NULL_TREE;
   12334              : 
   12335    100253467 :           if (!(flags & LOOKUP_NONVIRTUAL)
   12336     76923083 :               && DECL_PURE_VIRTUAL_P (fn)
   12337       210735 :               && instance == current_class_ref
   12338    100418953 :               && (complain & tf_warning))
   12339              :             {
   12340              :               /* This is not an error, it is runtime undefined
   12341              :                  behavior.  */
   12342       165486 :               if (!current_function_decl)
   12343            3 :                 warning (0, "pure virtual %q#D called from "
   12344              :                          "non-static data member initializer", fn);
   12345       165483 :               else if (DECL_CONSTRUCTOR_P (current_function_decl)
   12346       165483 :                        || DECL_DESTRUCTOR_P (current_function_decl))
   12347            9 :                 warning (0, (DECL_CONSTRUCTOR_P (current_function_decl)
   12348              :                              ? G_("pure virtual %q#D called from constructor")
   12349              :                              : G_("pure virtual %q#D called from destructor")),
   12350              :                          fn);
   12351              :             }
   12352              : 
   12353    115075445 :           if (DECL_OBJECT_MEMBER_FUNCTION_P (fn)
   12354    170866206 :               && !DECL_CONSTRUCTOR_P (fn)
   12355    158956491 :               && is_dummy_object (instance))
   12356              :             {
   12357        52725 :               instance = maybe_resolve_dummy (instance, true);
   12358        52725 :               if (instance == error_mark_node)
   12359              :                 call = error_mark_node;
   12360        52725 :               else if (!is_dummy_object (instance))
   12361              :                 {
   12362              :                   /* We captured 'this' in the current lambda now that
   12363              :                      we know we really need it.  */
   12364        52223 :                   cand->first_arg = instance;
   12365              :                 }
   12366          502 :               else if (current_class_ptr && any_dependent_bases_p ())
   12367              :                 /* We can't tell until instantiation time whether we can use
   12368              :                    *this as the implicit object argument.  */;
   12369              :               else
   12370              :                 {
   12371          463 :                   if (complain & tf_error)
   12372           69 :                     error ("cannot call member function %qD without object",
   12373              :                            fn);
   12374          463 :                   call = error_mark_node;
   12375              :                 }
   12376              :             }
   12377              : 
   12378    100253467 :           if (call != error_mark_node)
   12379              :             {
   12380              :               /* Now we know what function is being called.  */
   12381    100253004 :               if (fn_p)
   12382     27104977 :                 *fn_p = fn;
   12383              :               /* Build the actual CALL_EXPR.  */
   12384    100253004 :               call = build_over_call (cand, flags, complain);
   12385              : 
   12386              :               /* Suppress warnings for if (my_struct.operator= (x)) where
   12387              :                  my_struct is implicitly converted to bool. */
   12388    100253004 :               if (TREE_CODE (call) == MODIFY_EXPR)
   12389      3197745 :                 suppress_warning (call, OPT_Wparentheses);
   12390              : 
   12391              :               /* In an expression of the form `a->f()' where `f' turns
   12392              :                  out to be a static member function, `a' is
   12393              :                  none-the-less evaluated.  */
   12394    100253004 :               if (!is_dummy_object (instance))
   12395     77651813 :                 call = keep_unused_object_arg (call, instance, fn);
   12396    100253004 :               if (call != error_mark_node
   12397    198491908 :                   && DECL_DESTRUCTOR_P (cand->fn)
   12398    126941498 :                   && !VOID_TYPE_P (TREE_TYPE (call)))
   12399              :                 /* An explicit call of the form "x->~X()" has type
   12400              :                    "void".  However, on platforms where destructors
   12401              :                    return "this" (i.e., those where
   12402              :                    targetm.cxx.cdtor_returns_this is true), such calls
   12403              :                    will appear to have a return value of pointer type
   12404              :                    to the low-level call machinery.  We do not want to
   12405              :                    change the low-level machinery, since we want to be
   12406              :                    able to optimize "delete f()" on such platforms as
   12407              :                    "operator delete(~X(f()))" (rather than generating
   12408              :                    "t = f(), ~X(t), operator delete (t)").  */
   12409     15480120 :                 call = build_nop (void_type_node, call);
   12410              :             }
   12411              :         }
   12412              :     }
   12413              : 
   12414    100279870 :   if (processing_template_decl && call != error_mark_node)
   12415              :     {
   12416      7205992 :       bool cast_to_void = false;
   12417              : 
   12418      7205992 :       if (TREE_CODE (call) == COMPOUND_EXPR)
   12419           10 :         call = TREE_OPERAND (call, 1);
   12420      7205982 :       else if (TREE_CODE (call) == NOP_EXPR)
   12421              :         {
   12422            0 :           cast_to_void = true;
   12423            0 :           call = TREE_OPERAND (call, 0);
   12424              :         }
   12425      7205992 :       if (INDIRECT_REF_P (call))
   12426       611487 :         call = TREE_OPERAND (call, 0);
   12427              : 
   12428              :       /* Prune all but the selected function from the original overload
   12429              :          set so that we can avoid some duplicate work at instantiation time.  */
   12430      7205992 :       if (really_overloaded_fn (fns))
   12431              :         {
   12432      1657559 :           if (DECL_TEMPLATE_INFO (fn)
   12433      1657559 :               && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   12434              :             {
   12435              :               /* Use the selected template, not the specialization, so that
   12436              :                  this looks like an actual lookup result for sake of
   12437              :                  filter_memfn_lookup.  */
   12438              : 
   12439       280991 :               if (OVL_SINGLE_P (fns))
   12440              :                 /* If the original overload set consists of a single function
   12441              :                    template, this isn't beneficial.  */
   12442       240866 :                 goto skip_prune;
   12443              : 
   12444        40125 :               fn = ovl_make (DECL_TI_TEMPLATE (fn));
   12445        40125 :               if (template_only)
   12446        30405 :                 fn = lookup_template_function (fn, explicit_targs);
   12447              :             }
   12448      1416693 :           orig_fns = copy_node (orig_fns);
   12449      1416693 :           BASELINK_FUNCTIONS (orig_fns) = fn;
   12450      1416693 :           BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (orig_fns) = true;
   12451              :         }
   12452              : 
   12453      5548433 : skip_prune:
   12454      7205992 :       call = (build_min_non_dep_call_vec
   12455      7205992 :               (call,
   12456      7205992 :                build_min (COMPONENT_REF, TREE_TYPE (CALL_EXPR_FN (call)),
   12457              :                           orig_instance, orig_fns, NULL_TREE),
   12458              :                orig_args));
   12459      7205992 :       SET_EXPR_LOCATION (call, input_location);
   12460      7205992 :       call = convert_from_reference (call);
   12461      7205992 :       if (cast_to_void)
   12462            0 :         call = build_nop (void_type_node, call);
   12463              :     }
   12464              : 
   12465    100279870 :   if (orig_args != NULL)
   12466      7120456 :     release_tree_vector (orig_args);
   12467              : 
   12468              :   return call;
   12469    101875700 : }
   12470              : 
   12471              : /* Returns true iff standard conversion sequence ICS1 is a proper
   12472              :    subsequence of ICS2.  */
   12473              : 
   12474              : static bool
   12475     80411814 : is_subseq (conversion *ics1, conversion *ics2)
   12476              : {
   12477              :   /* We can assume that a conversion of the same code
   12478              :      between the same types indicates a subsequence since we only get
   12479              :      here if the types we are converting from are the same.  */
   12480              : 
   12481     80411814 :   while (ics1->kind == ck_rvalue
   12482     95669064 :          || ics1->kind == ck_lvalue)
   12483     15257250 :     ics1 = next_conversion (ics1);
   12484              : 
   12485              :   while (1)
   12486              :     {
   12487    107862842 :       while (ics2->kind == ck_rvalue
   12488    107862842 :              || ics2->kind == ck_lvalue)
   12489     15257250 :         ics2 = next_conversion (ics2);
   12490              : 
   12491     92605592 :       if (ics2->kind == ck_user
   12492     92605592 :           || !has_next (ics2->kind))
   12493              :         /* At this point, ICS1 cannot be a proper subsequence of
   12494              :            ICS2.  We can get a USER_CONV when we are comparing the
   12495              :            second standard conversion sequence of two user conversion
   12496              :            sequences.  */
   12497              :         return false;
   12498              : 
   12499     12200274 :       ics2 = next_conversion (ics2);
   12500              : 
   12501     12200274 :       while (ics2->kind == ck_rvalue
   12502     19309110 :              || ics2->kind == ck_lvalue)
   12503      7108836 :         ics2 = next_conversion (ics2);
   12504              : 
   12505     12200274 :       if (ics2->kind == ics1->kind
   12506         6541 :           && same_type_p (ics2->type, ics1->type)
   12507     12206770 :           && (ics1->kind == ck_identity
   12508         6496 :               || same_type_p (next_conversion (ics2)->type,
   12509              :                               next_conversion (ics1)->type)))
   12510              :         return true;
   12511              :     }
   12512              : }
   12513              : 
   12514              : /* Returns nonzero iff DERIVED is derived from BASE.  The inputs may
   12515              :    be any _TYPE nodes.  */
   12516              : 
   12517              : bool
   12518    649827264 : is_properly_derived_from (tree derived, tree base)
   12519              : {
   12520    649827264 :   if (!CLASS_TYPE_P (derived) || !CLASS_TYPE_P (base))
   12521              :     return false;
   12522              : 
   12523              :   /* We only allow proper derivation here.  The DERIVED_FROM_P macro
   12524              :      considers every class derived from itself.  */
   12525    486944739 :   return (!same_type_ignoring_top_level_qualifiers_p (derived, base)
   12526    486944739 :           && DERIVED_FROM_P (base, derived));
   12527              : }
   12528              : 
   12529              : /* We build the ICS for an implicit object parameter as a pointer
   12530              :    conversion sequence.  However, such a sequence should be compared
   12531              :    as if it were a reference conversion sequence.  If ICS is the
   12532              :    implicit conversion sequence for an implicit object parameter,
   12533              :    modify it accordingly.  */
   12534              : 
   12535              : static void
   12536    167932322 : maybe_handle_implicit_object (conversion **ics)
   12537              : {
   12538    167932322 :   if ((*ics)->this_p)
   12539              :     {
   12540              :       /* [over.match.funcs]
   12541              : 
   12542              :          For non-static member functions, the type of the
   12543              :          implicit object parameter is "reference to cv X"
   12544              :          where X is the class of which the function is a
   12545              :          member and cv is the cv-qualification on the member
   12546              :          function declaration.  */
   12547     13432773 :       conversion *t = *ics;
   12548     13432773 :       tree reference_type;
   12549              : 
   12550              :       /* The `this' parameter is a pointer to a class type.  Make the
   12551              :          implicit conversion talk about a reference to that same class
   12552              :          type.  */
   12553     13432773 :       reference_type = TREE_TYPE (t->type);
   12554     13432773 :       reference_type = build_reference_type (reference_type);
   12555              : 
   12556     13432773 :       if (t->kind == ck_qual)
   12557      3203437 :         t = next_conversion (t);
   12558     13432773 :       if (t->kind == ck_ptr)
   12559       627182 :         t = next_conversion (t);
   12560     13432773 :       t = build_identity_conv (TREE_TYPE (t->type), NULL_TREE);
   12561     13432773 :       t = direct_reference_binding (reference_type, t);
   12562     13432773 :       t->this_p = 1;
   12563     13432773 :       t->rvaluedness_matches_p = 0;
   12564     13432773 :       *ics = t;
   12565              :     }
   12566    167932322 : }
   12567              : 
   12568              : /* If *ICS is a REF_BIND set *ICS to the remainder of the conversion,
   12569              :    and return the initial reference binding conversion. Otherwise,
   12570              :    leave *ICS unchanged and return NULL.  */
   12571              : 
   12572              : static conversion *
   12573    167932322 : maybe_handle_ref_bind (conversion **ics)
   12574              : {
   12575    167932322 :   if ((*ics)->kind == ck_ref_bind)
   12576              :     {
   12577     61940769 :       conversion *old_ics = *ics;
   12578     61940769 :       *ics = next_conversion (old_ics);
   12579     61940769 :       (*ics)->user_conv_p = old_ics->user_conv_p;
   12580     61940769 :       return old_ics;
   12581              :     }
   12582              : 
   12583              :   return NULL;
   12584              : }
   12585              : 
   12586              : /* Get the expression at the beginning of the conversion chain C.  */
   12587              : 
   12588              : static tree
   12589           51 : conv_get_original_expr (conversion *c)
   12590              : {
   12591           60 :   for (; c; c = next_conversion (c))
   12592           60 :     if (c->kind == ck_identity || c->kind == ck_ambig || c->kind == ck_aggr)
   12593           51 :       return c->u.expr;
   12594              :   return NULL_TREE;
   12595              : }
   12596              : 
   12597              : /* Return a tree representing the number of elements initialized by the
   12598              :    list-initialization C.  The caller must check that C converts to an
   12599              :    array type.  */
   12600              : 
   12601              : static tree
   12602          126 : nelts_initialized_by_list_init (conversion *c)
   12603              : {
   12604              :   /* If the array we're converting to has a dimension, we'll use that.  */
   12605          126 :   if (TYPE_DOMAIN (c->type))
   12606           84 :     return array_type_nelts_top (c->type);
   12607              :   else
   12608              :     {
   12609              :       /* Otherwise, we look at how many elements the constructor we're
   12610              :          initializing from has.  */
   12611           42 :       tree ctor = conv_get_original_expr (c);
   12612           72 :       return size_int (CONSTRUCTOR_NELTS (ctor));
   12613              :     }
   12614              : }
   12615              : 
   12616              : /* True iff C is a conversion that binds a reference or a pointer to
   12617              :    an array of unknown bound.  */
   12618              : 
   12619              : static inline bool
   12620     30933672 : conv_binds_to_array_of_unknown_bound (conversion *c)
   12621              : {
   12622              :   /* ck_ref_bind won't have the reference stripped.  */
   12623     30933672 :   tree type = non_reference (c->type);
   12624              :   /* ck_qual won't have the pointer stripped.  */
   12625     30933672 :   type = strip_pointer_operator (type);
   12626     30933672 :   return (TREE_CODE (type) == ARRAY_TYPE
   12627     30933672 :           && TYPE_DOMAIN (type) == NULL_TREE);
   12628              : }
   12629              : 
   12630              : /* Compare two implicit conversion sequences according to the rules set out in
   12631              :    [over.ics.rank].  Return values:
   12632              : 
   12633              :       1: ics1 is better than ics2
   12634              :      -1: ics2 is better than ics1
   12635              :       0: ics1 and ics2 are indistinguishable */
   12636              : 
   12637              : static int
   12638     83966202 : compare_ics (conversion *ics1, conversion *ics2)
   12639              : {
   12640     83966202 :   tree from_type1;
   12641     83966202 :   tree from_type2;
   12642     83966202 :   tree to_type1;
   12643     83966202 :   tree to_type2;
   12644     83966202 :   tree deref_from_type1 = NULL_TREE;
   12645     83966202 :   tree deref_from_type2 = NULL_TREE;
   12646     83966202 :   tree deref_to_type1 = NULL_TREE;
   12647     83966202 :   tree deref_to_type2 = NULL_TREE;
   12648     83966202 :   conversion_rank rank1, rank2;
   12649              : 
   12650              :   /* REF_BINDING is nonzero if the result of the conversion sequence
   12651              :      is a reference type.   In that case REF_CONV is the reference
   12652              :      binding conversion. */
   12653     83966202 :   conversion *ref_conv1;
   12654     83966202 :   conversion *ref_conv2;
   12655              : 
   12656              :   /* Compare badness before stripping the reference conversion.  */
   12657     83966202 :   if (ics1->bad_p > ics2->bad_p)
   12658              :     return -1;
   12659     83966188 :   else if (ics1->bad_p < ics2->bad_p)
   12660              :     return 1;
   12661              : 
   12662              :   /* Handle implicit object parameters.  */
   12663     83966161 :   maybe_handle_implicit_object (&ics1);
   12664     83966161 :   maybe_handle_implicit_object (&ics2);
   12665              : 
   12666              :   /* Handle reference parameters.  */
   12667     83966161 :   ref_conv1 = maybe_handle_ref_bind (&ics1);
   12668     83966161 :   ref_conv2 = maybe_handle_ref_bind (&ics2);
   12669              : 
   12670              :   /* List-initialization sequence L1 is a better conversion sequence than
   12671              :      list-initialization sequence L2 if L1 converts to
   12672              :      std::initializer_list<X> for some X and L2 does not.  */
   12673     83966161 :   if (ics1->kind == ck_list && ics2->kind != ck_list)
   12674              :     return 1;
   12675     83965350 :   if (ics2->kind == ck_list && ics1->kind != ck_list)
   12676              :     return -1;
   12677              : 
   12678              :   /* [over.ics.rank]
   12679              : 
   12680              :      When  comparing  the  basic forms of implicit conversion sequences (as
   12681              :      defined in _over.best.ics_)
   12682              : 
   12683              :      --a standard conversion sequence (_over.ics.scs_) is a better
   12684              :        conversion sequence than a user-defined conversion sequence
   12685              :        or an ellipsis conversion sequence, and
   12686              : 
   12687              :      --a user-defined conversion sequence (_over.ics.user_) is a
   12688              :        better conversion sequence than an ellipsis conversion sequence
   12689              :        (_over.ics.ellipsis_).  */
   12690              :   /* Use BAD_CONVERSION_RANK because we already checked for a badness
   12691              :      mismatch.  If both ICS are bad, we try to make a decision based on
   12692              :      what would have happened if they'd been good.  This is not an
   12693              :      extension, we'll still give an error when we build up the call; this
   12694              :      just helps us give a more helpful error message.  */
   12695     83965085 :   rank1 = BAD_CONVERSION_RANK (ics1);
   12696     83965085 :   rank2 = BAD_CONVERSION_RANK (ics2);
   12697              : 
   12698     83965085 :   if (rank1 > rank2)
   12699              :     return -1;
   12700     72927000 :   else if (rank1 < rank2)
   12701              :     return 1;
   12702              : 
   12703     40651310 :   if (ics1->ellipsis_p)
   12704              :     /* Both conversions are ellipsis conversions.  */
   12705              :     return 0;
   12706              : 
   12707              :   /* User-defined  conversion sequence U1 is a better conversion sequence
   12708              :      than another user-defined conversion sequence U2 if they contain the
   12709              :      same user-defined conversion operator or constructor and if the sec-
   12710              :      ond standard conversion sequence of U1 is  better  than  the  second
   12711              :      standard conversion sequence of U2.  */
   12712              : 
   12713              :   /* Handle list-conversion with the same code even though it isn't always
   12714              :      ranked as a user-defined conversion and it doesn't have a second
   12715              :      standard conversion sequence; it will still have the desired effect.
   12716              :      Specifically, we need to do the reference binding comparison at the
   12717              :      end of this function.  */
   12718              : 
   12719     40651264 :   if (ics1->user_conv_p || ics1->kind == ck_list
   12720     39917536 :       || ics1->kind == ck_aggr || ics2->kind == ck_aggr)
   12721              :     {
   12722       733797 :       conversion *t1 = strip_standard_conversion (ics1);
   12723       733797 :       conversion *t2 = strip_standard_conversion (ics2);
   12724              : 
   12725       733797 :       if (!t1 || !t2 || t1->kind != t2->kind)
   12726              :         return 0;
   12727       733778 :       else if (t1->kind == ck_user)
   12728              :         {
   12729       717946 :           tree f1 = t1->cand ? t1->cand->fn : t1->type;
   12730       717946 :           tree f2 = t2->cand ? t2->cand->fn : t2->type;
   12731       717946 :           if (f1 != f2)
   12732              :             return 0;
   12733              :         }
   12734              :       /* List-initialization sequence L1 is a better conversion sequence than
   12735              :          list-initialization sequence L2 if
   12736              : 
   12737              :          -- L1 and L2 convert to arrays of the same element type, and either
   12738              :          the number of elements n1 initialized by L1 is less than the number
   12739              :          of elements n2 initialized by L2, or n1=n2 and L2 converts to an array
   12740              :          of unknown bound and L1 does not.  (Added in CWG 1307 and extended by
   12741              :          P0388R4.)  */
   12742        15832 :       else if (t1->kind == ck_aggr
   12743        14820 :                && TREE_CODE (t1->type) == ARRAY_TYPE
   12744           66 :                && TREE_CODE (t2->type) == ARRAY_TYPE
   12745        15898 :                && same_type_p (TREE_TYPE (t1->type), TREE_TYPE (t2->type)))
   12746              :         {
   12747           63 :           tree n1 = nelts_initialized_by_list_init (t1);
   12748           63 :           tree n2 = nelts_initialized_by_list_init (t2);
   12749           63 :           if (tree_int_cst_lt (n1, n2))
   12750              :             return 1;
   12751           24 :           else if (tree_int_cst_lt (n2, n1))
   12752              :             return -1;
   12753              :           /* The n1 == n2 case.  */
   12754           24 :           bool c1 = conv_binds_to_array_of_unknown_bound (t1);
   12755           24 :           bool c2 = conv_binds_to_array_of_unknown_bound (t2);
   12756           24 :           if (c1 && !c2)
   12757              :             return -1;
   12758            6 :           else if (!c1 && c2)
   12759              :             return 1;
   12760              :           else
   12761            6 :             return 0;
   12762              :         }
   12763              :       else
   12764              :         {
   12765              :           /* For ambiguous or aggregate conversions, use the target type as
   12766              :              a proxy for the conversion function.  */
   12767        15769 :           if (!same_type_ignoring_top_level_qualifiers_p (t1->type, t2->type))
   12768              :             return 0;
   12769              :         }
   12770              : 
   12771              :       /* We can just fall through here, after setting up
   12772              :          FROM_TYPE1 and FROM_TYPE2.  */
   12773       730701 :       from_type1 = t1->type;
   12774       730701 :       from_type2 = t2->type;
   12775       730701 :     }
   12776              :   else
   12777              :     {
   12778              :       conversion *t1;
   12779              :       conversion *t2;
   12780              : 
   12781              :       /* We're dealing with two standard conversion sequences.
   12782              : 
   12783              :          [over.ics.rank]
   12784              : 
   12785              :          Standard conversion sequence S1 is a better conversion
   12786              :          sequence than standard conversion sequence S2 if
   12787              : 
   12788              :          --S1 is a proper subsequence of S2 (comparing the conversion
   12789              :            sequences in the canonical form defined by _over.ics.scs_,
   12790              :            excluding any Lvalue Transformation; the identity
   12791              :            conversion sequence is considered to be a subsequence of
   12792              :            any non-identity conversion sequence */
   12793              : 
   12794              :       t1 = ics1;
   12795     57295708 :       while (t1->kind != ck_identity)
   12796     17378241 :         t1 = next_conversion (t1);
   12797     39917467 :       from_type1 = t1->type;
   12798              : 
   12799     39917467 :       t2 = ics2;
   12800     57187596 :       while (t2->kind != ck_identity)
   12801     17270129 :         t2 = next_conversion (t2);
   12802     39917467 :       from_type2 = t2->type;
   12803              :     }
   12804              : 
   12805              :   /* One sequence can only be a subsequence of the other if they start with
   12806              :      the same type.  They can start with different types when comparing the
   12807              :      second standard conversion sequence in two user-defined conversion
   12808              :      sequences.  */
   12809     40648168 :   if (same_type_p (from_type1, from_type2))
   12810              :     {
   12811     40209120 :       if (is_subseq (ics1, ics2))
   12812              :         return 1;
   12813     40202694 :       if (is_subseq (ics2, ics1))
   12814              :         return -1;
   12815              :     }
   12816              : 
   12817              :   /* [over.ics.rank]
   12818              : 
   12819              :      Or, if not that,
   12820              : 
   12821              :      --the rank of S1 is better than the rank of S2 (by the rules
   12822              :        defined below):
   12823              : 
   12824              :     Standard conversion sequences are ordered by their ranks: an Exact
   12825              :     Match is a better conversion than a Promotion, which is a better
   12826              :     conversion than a Conversion.
   12827              : 
   12828              :     Two conversion sequences with the same rank are indistinguishable
   12829              :     unless one of the following rules applies:
   12830              : 
   12831              :     --A conversion that does not a convert a pointer, pointer to member,
   12832              :       or std::nullptr_t to bool is better than one that does.
   12833              : 
   12834              :     The ICS_STD_RANK automatically handles the pointer-to-bool rule,
   12835              :     so that we do not have to check it explicitly.  */
   12836     40641672 :   if (ics1->rank < ics2->rank)
   12837              :     return 1;
   12838     40641592 :   else if (ics2->rank < ics1->rank)
   12839              :     return -1;
   12840              : 
   12841     40641592 :   to_type1 = ics1->type;
   12842     40641592 :   to_type2 = ics2->type;
   12843              : 
   12844              :   /* A conversion from scalar arithmetic type to complex is worse than a
   12845              :      conversion between scalar arithmetic types.  */
   12846     40641592 :   if (same_type_p (from_type1, from_type2)
   12847     40202544 :       && ARITHMETIC_TYPE_P (from_type1)
   12848      8143960 :       && ARITHMETIC_TYPE_P (to_type1)
   12849      8143787 :       && ARITHMETIC_TYPE_P (to_type2)
   12850     40641592 :       && ((TREE_CODE (to_type1) == COMPLEX_TYPE)
   12851      8143733 :           != (TREE_CODE (to_type2) == COMPLEX_TYPE)))
   12852              :     {
   12853          982 :       if (TREE_CODE (to_type1) == COMPLEX_TYPE)
   12854              :         return -1;
   12855              :       else
   12856          979 :         return 1;
   12857              :     }
   12858              : 
   12859     40640610 :   {
   12860              :     /* A conversion in either direction between floating-point type FP1 and
   12861              :        floating-point type FP2 is better than a conversion in the same
   12862              :        direction between FP1 and arithmetic type T3 if
   12863              :        - the floating-point conversion rank of FP1 is equal to the rank of
   12864              :          FP2, and
   12865              :        - T3 is not a floating-point type, or T3 is a floating-point type
   12866              :          whose rank is not equal to the rank of FP1, or the floating-point
   12867              :          conversion subrank of FP2 is greater than the subrank of T3.  */
   12868     40640610 :     tree fp1 = from_type1;
   12869     40640610 :     tree fp2 = to_type1;
   12870     40640610 :     tree fp3 = from_type2;
   12871     40640610 :     tree t3 = to_type2;
   12872     40640610 :     int ret = 1;
   12873     40640610 :     if (TYPE_MAIN_VARIANT (fp2) == TYPE_MAIN_VARIANT (t3))
   12874              :       {
   12875     35670421 :         std::swap (fp1, fp2);
   12876     35670421 :         std::swap (fp3, t3);
   12877              :       }
   12878     40640610 :     if (TYPE_MAIN_VARIANT (fp1) == TYPE_MAIN_VARIANT (fp3)
   12879     40640523 :         && SCALAR_FLOAT_TYPE_P (fp1)
   12880              :         /* Only apply this rule if at least one of the 3 types is
   12881              :            extended floating-point type, otherwise keep them as
   12882              :            before for compatibility reasons with types like __float128.
   12883              :            float, double and long double alone have different conversion
   12884              :            ranks and so when just those 3 types are involved, this
   12885              :            rule doesn't trigger.  */
   12886     45028758 :         && (extended_float_type_p (fp1)
   12887      4308235 :             || (SCALAR_FLOAT_TYPE_P (fp2) && extended_float_type_p (fp2))
   12888      4216992 :             || (SCALAR_FLOAT_TYPE_P (t3) && extended_float_type_p (t3))))
   12889              :       {
   12890       171156 :         if (TREE_CODE (fp2) != REAL_TYPE)
   12891              :           {
   12892        33873 :             ret = -ret;
   12893        33873 :             std::swap (fp2, t3);
   12894              :           }
   12895       171156 :         if (SCALAR_FLOAT_TYPE_P (fp2))
   12896              :           {
   12897              :             /* cp_compare_floating_point_conversion_ranks returns -1, 0 or 1
   12898              :                if the conversion rank is equal (-1 or 1 if the subrank is
   12899              :                different).  */
   12900       152565 :             if (IN_RANGE (cp_compare_floating_point_conversion_ranks (fp1,
   12901              :                                                                       fp2),
   12902              :                           -1, 1))
   12903              :               {
   12904              :                 /* Conversion ranks of FP1 and FP2 are equal.  */
   12905        94958 :                 if (TREE_CODE (t3) != REAL_TYPE
   12906        94958 :                     || !IN_RANGE (cp_compare_floating_point_conversion_ranks
   12907              :                                                                 (fp1, t3),
   12908              :                                   -1, 1))
   12909              :                   /* FP1 <-> FP2 conversion is better.  */
   12910     83966202 :                   return ret;
   12911          746 :                 int c = cp_compare_floating_point_conversion_ranks (fp2, t3);
   12912          746 :                 gcc_assert (IN_RANGE (c, -1, 1));
   12913          746 :                 if (c == 1)
   12914              :                   /* Conversion subrank of FP2 is greater than subrank of T3.
   12915              :                      FP1 <-> FP2 conversion is better.  */
   12916              :                   return ret;
   12917          746 :                 else if (c == -1)
   12918              :                   /* Conversion subrank of FP2 is less than subrank of T3.
   12919              :                      FP1 <-> T3 conversion is better.  */
   12920            0 :                   return -ret;
   12921              :               }
   12922        57607 :             else if (SCALAR_FLOAT_TYPE_P (t3)
   12923        57607 :                      && IN_RANGE (cp_compare_floating_point_conversion_ranks
   12924              :                                                                 (fp1, t3),
   12925              :                                   -1, 1))
   12926              :               /* Conversion ranks of FP1 and FP2 are not equal, conversion
   12927              :                  ranks of FP1 and T3 are equal.
   12928              :                  FP1 <-> T3 conversion is better.  */
   12929        10105 :               return -ret;
   12930              :           }
   12931              :       }
   12932              :   }
   12933              : 
   12934     40536293 :   if (TYPE_PTR_P (from_type1)
   12935      5283849 :       && TYPE_PTR_P (from_type2)
   12936      5283833 :       && TYPE_PTR_P (to_type1)
   12937      5283809 :       && TYPE_PTR_P (to_type2))
   12938              :     {
   12939      5283809 :       deref_from_type1 = TREE_TYPE (from_type1);
   12940      5283809 :       deref_from_type2 = TREE_TYPE (from_type2);
   12941      5283809 :       deref_to_type1 = TREE_TYPE (to_type1);
   12942      5283809 :       deref_to_type2 = TREE_TYPE (to_type2);
   12943              :     }
   12944              :   /* The rules for pointers to members A::* are just like the rules
   12945              :      for pointers A*, except opposite: if B is derived from A then
   12946              :      A::* converts to B::*, not vice versa.  For that reason, we
   12947              :      switch the from_ and to_ variables here.  */
   12948           59 :   else if ((TYPE_PTRDATAMEM_P (from_type1) && TYPE_PTRDATAMEM_P (from_type2)
   12949           59 :             && TYPE_PTRDATAMEM_P (to_type1) && TYPE_PTRDATAMEM_P (to_type2))
   12950     35252484 :            || (TYPE_PTRMEMFUNC_P (from_type1)
   12951          437 :                && TYPE_PTRMEMFUNC_P (from_type2)
   12952          437 :                && TYPE_PTRMEMFUNC_P (to_type1)
   12953          437 :                && TYPE_PTRMEMFUNC_P (to_type2)))
   12954              :     {
   12955          496 :       deref_to_type1 = TYPE_PTRMEM_CLASS_TYPE (from_type1);
   12956          496 :       deref_to_type2 = TYPE_PTRMEM_CLASS_TYPE (from_type2);
   12957          496 :       deref_from_type1 = TYPE_PTRMEM_CLASS_TYPE (to_type1);
   12958          496 :       deref_from_type2 = TYPE_PTRMEM_CLASS_TYPE (to_type2);
   12959              :     }
   12960              : 
   12961      5284305 :   if (deref_from_type1 != NULL_TREE
   12962      5284305 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type1))
   12963       307657 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type2)))
   12964              :     {
   12965              :       /* This was one of the pointer or pointer-like conversions.
   12966              : 
   12967              :          [over.ics.rank]
   12968              : 
   12969              :          --If class B is derived directly or indirectly from class A,
   12970              :            conversion of B* to A* is better than conversion of B* to
   12971              :            void*, and conversion of A* to void* is better than
   12972              :            conversion of B* to void*.  */
   12973       307657 :       if (VOID_TYPE_P (deref_to_type1)
   12974           57 :           && VOID_TYPE_P (deref_to_type2))
   12975              :         {
   12976           14 :           if (is_properly_derived_from (deref_from_type1,
   12977              :                                         deref_from_type2))
   12978              :             return -1;
   12979           14 :           else if (is_properly_derived_from (deref_from_type2,
   12980              :                                              deref_from_type1))
   12981              :             return 1;
   12982              :         }
   12983       307643 :       else if (VOID_TYPE_P (deref_to_type1)
   12984       307600 :                || VOID_TYPE_P (deref_to_type2))
   12985              :         {
   12986           47 :           if (same_type_p (deref_from_type1, deref_from_type2))
   12987              :             {
   12988           47 :               if (VOID_TYPE_P (deref_to_type2))
   12989              :                 {
   12990            4 :                   if (is_properly_derived_from (deref_from_type1,
   12991              :                                                 deref_to_type1))
   12992              :                     return 1;
   12993              :                 }
   12994              :               /* We know that DEREF_TO_TYPE1 is `void' here.  */
   12995           43 :               else if (is_properly_derived_from (deref_from_type1,
   12996              :                                                  deref_to_type2))
   12997              :                 return -1;
   12998              :             }
   12999              :         }
   13000       307596 :       else if (RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type1))
   13001       307596 :                && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type2)))
   13002              :         {
   13003              :           /* [over.ics.rank]
   13004              : 
   13005              :              --If class B is derived directly or indirectly from class A
   13006              :                and class C is derived directly or indirectly from B,
   13007              : 
   13008              :              --conversion of C* to B* is better than conversion of C* to
   13009              :                A*,
   13010              : 
   13011              :              --conversion of B* to A* is better than conversion of C* to
   13012              :                A*  */
   13013       307596 :           if (same_type_p (deref_from_type1, deref_from_type2))
   13014              :             {
   13015       307590 :               if (is_properly_derived_from (deref_to_type1,
   13016              :                                             deref_to_type2))
   13017              :                 return 1;
   13018       307590 :               else if (is_properly_derived_from (deref_to_type2,
   13019              :                                                  deref_to_type1))
   13020              :                 return -1;
   13021              :             }
   13022            6 :           else if (same_type_p (deref_to_type1, deref_to_type2))
   13023              :             {
   13024            6 :               if (is_properly_derived_from (deref_from_type2,
   13025              :                                             deref_from_type1))
   13026              :                 return 1;
   13027            0 :               else if (is_properly_derived_from (deref_from_type1,
   13028              :                                                  deref_from_type2))
   13029              :                 return -1;
   13030              :             }
   13031              :         }
   13032              :     }
   13033     80457272 :   else if (CLASS_TYPE_P (non_reference (from_type1))
   13034     64986156 :            && same_type_p (from_type1, from_type2))
   13035              :     {
   13036     24381467 :       tree from = non_reference (from_type1);
   13037              : 
   13038              :       /* [over.ics.rank]
   13039              : 
   13040              :          --binding of an expression of type C to a reference of type
   13041              :            B& is better than binding an expression of type C to a
   13042              :            reference of type A&
   13043              : 
   13044              :          --conversion of C to B is better than conversion of C to A,  */
   13045     24381467 :       if (is_properly_derived_from (from, to_type1)
   13046     24381467 :           && is_properly_derived_from (from, to_type2))
   13047              :         {
   13048       972711 :           if (is_properly_derived_from (to_type1, to_type2))
   13049              :             return 1;
   13050       968625 :           else if (is_properly_derived_from (to_type2, to_type1))
   13051              :             return -1;
   13052              :         }
   13053              :     }
   13054     31694338 :   else if (CLASS_TYPE_P (non_reference (to_type1))
   13055     16223222 :            && same_type_p (to_type1, to_type2))
   13056              :     {
   13057            7 :       tree to = non_reference (to_type1);
   13058              : 
   13059              :       /* [over.ics.rank]
   13060              : 
   13061              :          --binding of an expression of type B to a reference of type
   13062              :            A& is better than binding an expression of type C to a
   13063              :            reference of type A&,
   13064              : 
   13065              :          --conversion of B to A is better than conversion of C to A  */
   13066            7 :       if (is_properly_derived_from (from_type1, to)
   13067            7 :           && is_properly_derived_from (from_type2, to))
   13068              :         {
   13069            3 :           if (is_properly_derived_from (from_type2, from_type1))
   13070              :             return 1;
   13071            3 :           else if (is_properly_derived_from (from_type1, from_type2))
   13072              :             return -1;
   13073              :         }
   13074              :     }
   13075              : 
   13076              :   /* [over.ics.rank]
   13077              : 
   13078              :      --S1 and S2 differ only in their qualification conversion and  yield
   13079              :        similar  types  T1 and T2 (_conv.qual_), respectively, and the cv-
   13080              :        qualification signature of type T1 is a proper subset of  the  cv-
   13081              :        qualification signature of type T2  */
   13082     40446221 :   if (ics1->kind == ck_qual
   13083          385 :       && ics2->kind == ck_qual
   13084     40446606 :       && same_type_p (from_type1, from_type2))
   13085              :     {
   13086          385 :       int result = comp_cv_qual_signature (to_type1, to_type2);
   13087          385 :       if (result != 0)
   13088              :         return result;
   13089              :     }
   13090              : 
   13091              :   /* [over.ics.rank]
   13092              : 
   13093              :      --S1 and S2 are reference bindings (_dcl.init.ref_) and neither refers
   13094              :      to an implicit object parameter of a non-static member function
   13095              :      declared without a ref-qualifier, and either S1 binds an lvalue
   13096              :      reference to an lvalue and S2 binds an rvalue reference or S1 binds an
   13097              :      rvalue reference to an rvalue and S2 binds an lvalue reference (C++0x
   13098              :      draft standard, 13.3.3.2)
   13099              : 
   13100              :      --S1 and S2 are reference bindings (_dcl.init.ref_), and the
   13101              :      types to which the references refer are the same type except for
   13102              :      top-level cv-qualifiers, and the type to which the reference
   13103              :      initialized by S2 refers is more cv-qualified than the type to
   13104              :      which the reference initialized by S1 refers.
   13105              : 
   13106              :      DR 1328 [over.match.best]: the context is an initialization by
   13107              :      conversion function for direct reference binding (13.3.1.6) of a
   13108              :      reference to function type, the return type of F1 is the same kind of
   13109              :      reference (i.e. lvalue or rvalue) as the reference being initialized,
   13110              :      and the return type of F2 is not.  */
   13111              : 
   13112     40446135 :   if (ref_conv1 && ref_conv2)
   13113              :     {
   13114     18602216 :       if (!ref_conv1->this_p && !ref_conv2->this_p
   13115     18329996 :           && (ref_conv1->rvaluedness_matches_p
   13116     18329996 :               != ref_conv2->rvaluedness_matches_p)
   13117     35011344 :           && (same_type_p (ref_conv1->type, ref_conv2->type)
   13118      9772228 :               || (TYPE_REF_IS_RVALUE (ref_conv1->type)
   13119      9772228 :                   != TYPE_REF_IS_RVALUE (ref_conv2->type))))
   13120              :         {
   13121      9771956 :           if (ref_conv1->bad_p
   13122      9771956 :               && !same_type_p (TREE_TYPE (ref_conv1->type),
   13123              :                                TREE_TYPE (ref_conv2->type)))
   13124              :             /* Don't prefer a bad conversion that drops cv-quals to a bad
   13125              :                conversion with the wrong rvalueness.  */
   13126              :             return 0;
   13127      9770493 :           return (ref_conv1->rvaluedness_matches_p
   13128      9770493 :                   - ref_conv2->rvaluedness_matches_p);
   13129              :         }
   13130              : 
   13131     15467157 :       if (same_type_ignoring_top_level_qualifiers_p (to_type1, to_type2))
   13132              :         {
   13133              :           /* Per P0388R4:
   13134              : 
   13135              :             void f (int(&)[]),     // (1)
   13136              :                  f (int(&)[1]),    // (2)
   13137              :                  f (int*);         // (3)
   13138              : 
   13139              :             (2) is better than (1), but (3) should be equal to (1) and to
   13140              :             (2).  For that reason we don't use ck_qual for (1) which would
   13141              :             give it the cr_exact rank while (3) remains ck_identity.
   13142              :             Therefore we compare (1) and (2) here.  For (1) we'll have
   13143              : 
   13144              :               ck_ref_bind <- ck_identity
   13145              :                 int[] &            int[1]
   13146              : 
   13147              :             so to handle this we must look at ref_conv.  */
   13148     15466574 :           bool c1 = conv_binds_to_array_of_unknown_bound (ref_conv1);
   13149     15466574 :           bool c2 = conv_binds_to_array_of_unknown_bound (ref_conv2);
   13150     15466574 :           if (c1 && !c2)
   13151              :             return -1;
   13152     15466568 :           else if (!c1 && c2)
   13153              :             return 1;
   13154              : 
   13155     15466568 :           int q1 = cp_type_quals (TREE_TYPE (ref_conv1->type));
   13156     15466568 :           int q2 = cp_type_quals (TREE_TYPE (ref_conv2->type));
   13157     15466568 :           if (ref_conv1->bad_p)
   13158              :             {
   13159              :               /* Prefer the one that drops fewer cv-quals.  */
   13160         1606 :               tree ftype = next_conversion (ref_conv1)->type;
   13161         1606 :               int fquals = cp_type_quals (ftype);
   13162         1606 :               q1 ^= fquals;
   13163         1606 :               q2 ^= fquals;
   13164              :             }
   13165     15466568 :           return comp_cv_qualification (q2, q1);
   13166              :         }
   13167              :     }
   13168              : 
   13169              :   /* [over.ics.rank]
   13170              : 
   13171              :      Per CWG 1601:
   13172              :      -- A conversion that promotes an enumeration whose underlying type
   13173              :      is fixed to its underlying type is better than one that promotes to
   13174              :      the promoted underlying type, if the two are different.  */
   13175     15207605 :   if (ics1->rank == cr_promotion
   13176          147 :       && ics2->rank == cr_promotion
   13177          147 :       && UNSCOPED_ENUM_P (from_type1)
   13178           27 :       && ENUM_FIXED_UNDERLYING_TYPE_P (from_type1)
   13179     15207629 :       && same_type_p (from_type1, from_type2))
   13180              :     {
   13181           24 :       tree utype = ENUM_UNDERLYING_TYPE (from_type1);
   13182           24 :       tree prom = type_promotes_to (from_type1);
   13183           24 :       if (!same_type_p (utype, prom))
   13184              :         {
   13185           12 :           if (same_type_p (to_type1, utype)
   13186           12 :               && same_type_p (to_type2, prom))
   13187              :             return 1;
   13188            6 :           else if (same_type_p (to_type2, utype)
   13189            6 :                    && same_type_p (to_type1, prom))
   13190            6 :             return -1;
   13191              :         }
   13192              :     }
   13193              : 
   13194              :   /* Neither conversion sequence is better than the other.  */
   13195              :   return 0;
   13196              : }
   13197              : 
   13198              : /* The source type for this standard conversion sequence.  */
   13199              : 
   13200              : static tree
   13201            9 : source_type (conversion *t)
   13202              : {
   13203            9 :   return strip_standard_conversion (t)->type;
   13204              : }
   13205              : 
   13206              : /* Note a warning about preferring WINNER to LOSER.  We do this by storing
   13207              :    a pointer to LOSER and re-running joust to produce the warning if WINNER
   13208              :    is actually used.  */
   13209              : 
   13210              : static void
   13211          528 : add_warning (struct z_candidate *winner, struct z_candidate *loser)
   13212              : {
   13213          528 :   candidate_warning *cw = (candidate_warning *)
   13214            0 :     conversion_obstack_alloc (sizeof (candidate_warning));
   13215          528 :   cw->loser = loser;
   13216          528 :   cw->next = winner->warnings;
   13217          528 :   winner->warnings = cw;
   13218            0 : }
   13219              : 
   13220              : /* CAND is a constructor candidate in joust in C++17 and up.  If it copies a
   13221              :    prvalue returned from a conversion function, return true.  Otherwise, return
   13222              :    false.  */
   13223              : 
   13224              : static bool
   13225       886990 : joust_maybe_elide_copy (z_candidate *cand)
   13226              : {
   13227       886990 :   tree fn = cand->fn;
   13228      2226897 :   if (!DECL_COPY_CONSTRUCTOR_P (fn) && !DECL_MOVE_CONSTRUCTOR_P (fn))
   13229              :     return false;
   13230       434268 :   conversion *conv = cand->convs[0];
   13231       434268 :   if (conv->kind == ck_ambig)
   13232              :     return false;
   13233       434266 :   gcc_checking_assert (conv->kind == ck_ref_bind);
   13234       434266 :   conv = next_conversion (conv);
   13235       434266 :   if (conv->kind == ck_user && !TYPE_REF_P (conv->type))
   13236              :     {
   13237          372 :       gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p
   13238              :                            (conv->type, DECL_CONTEXT (fn)));
   13239          372 :       z_candidate *uc = conv->cand;
   13240          372 :       if (DECL_CONV_FN_P (uc->fn))
   13241          233 :         return true;
   13242              :     }
   13243              :   return false;
   13244              : }
   13245              : 
   13246              : /* Return the class that CAND's implicit object parameter refers to.  */
   13247              : 
   13248              : static tree
   13249       296022 : class_of_implicit_object (z_candidate *cand)
   13250              : {
   13251       296022 :   if (!DECL_IOBJ_MEMBER_FUNCTION_P (cand->fn))
   13252              :     return NULL_TREE;
   13253              : 
   13254              :   /* "For conversion functions that are implicit object member functions,
   13255              :      the function is considered to be a member of the class of the implied
   13256              :      object argument for the purpose of defining the type of the implicit
   13257              :      object parameter."  */
   13258       296022 :   if (DECL_CONV_FN_P (cand->fn))
   13259            0 :     return TYPE_MAIN_VARIANT (TREE_TYPE (cand->first_arg));
   13260              : 
   13261              :   /* "For non-conversion functions that are implicit object member
   13262              :      functions nominated by a using-declaration in a derived class, the
   13263              :      function is considered to be a member of the derived class for the
   13264              :      purpose of defining the type of the implicit object parameter."
   13265              : 
   13266              :      That derived class is reflected in the conversion_path binfo.  */
   13267       296022 :   return BINFO_TYPE (cand->conversion_path);
   13268              : }
   13269              : 
   13270              : /* Return whether the first parameter of C1 matches the second parameter
   13271              :    of C2.  */
   13272              : 
   13273              : static bool
   13274       566770 : reversed_match (z_candidate *c1, z_candidate *c2)
   13275              : {
   13276       566770 :   tree fn1 = c1->fn;
   13277       566770 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (c2->fn));
   13278       566770 :   tree parm2 = TREE_VALUE (TREE_CHAIN (parms2));
   13279       566770 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn1))
   13280              :     {
   13281       296022 :       tree ctx = class_of_implicit_object (c1);
   13282       296022 :       return iobj_parm_corresponds_to (fn1, parm2, ctx);
   13283              :     }
   13284              :   else
   13285              :     {
   13286       270748 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13287       270748 :       tree parm1 = TREE_VALUE (parms1);
   13288       270748 :       return same_type_p (parm1, parm2);
   13289              :     }
   13290              : }
   13291              : 
   13292              : /* True if the defining declarations of the two candidates have equivalent
   13293              :    parameters.  MATCH_KIND controls whether we're trying to compare the
   13294              :    original declarations (for a warning) or the actual candidates.  */
   13295              : 
   13296              : enum class pmatch { original, current };
   13297              : 
   13298              : static bool
   13299      4990024 : cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
   13300              : {
   13301      4990024 :   tree fn1 = c1->fn;
   13302      4990024 :   tree fn2 = c2->fn;
   13303      4990024 :   bool reversed = (match_kind == pmatch::current
   13304      4990024 :                    && c1->reversed () != c2->reversed ());
   13305      4990024 :   if (fn1 == fn2 && !reversed)
   13306              :     return true;
   13307      4989699 :   if (identifier_p (fn1) || identifier_p (fn2))
   13308              :     return false;
   13309      4989694 :   if (match_kind == pmatch::original)
   13310              :     {
   13311              :       /* We don't look at c1->template_decl because that's only set for
   13312              :          primary templates, not e.g. non-template member functions of
   13313              :          class templates.  */
   13314           22 :       tree t1 = most_general_template (fn1);
   13315           22 :       tree t2 = most_general_template (fn2);
   13316           22 :       if (t1 || t2)
   13317              :         {
   13318           15 :           if (!t1 || !t2)
   13319              :             return false;
   13320           15 :           if (t1 == t2)
   13321              :             return true;
   13322            3 :           fn1 = DECL_TEMPLATE_RESULT (t1);
   13323            3 :           fn2 = DECL_TEMPLATE_RESULT (t2);
   13324              :         }
   13325              :     }
   13326              : 
   13327      4989682 :   tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13328      4989682 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2));
   13329              : 
   13330      9756950 :   if (DECL_FUNCTION_MEMBER_P (fn1)
   13331      4990306 :       && DECL_FUNCTION_MEMBER_P (fn2))
   13332              :     {
   13333       223024 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (fn1));
   13334       223024 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (fn2));
   13335       223024 :       if (base1 != base2)
   13336       148493 :         return false;
   13337              : 
   13338       222847 :       if (reversed)
   13339       148316 :         return (reversed_match (c1, c2)
   13340       148316 :                 && reversed_match (c2, c1));
   13341              : 
   13342              :       /* Use object_parms_correspond to simplify comparing iobj/xobj/static
   13343              :          member functions.  */
   13344        74531 :       if (!object_parms_correspond (fn1, fn2, base1))
   13345              :         return false;
   13346              : 
   13347              :       /* We just compared the object parameters, if they don't correspond
   13348              :          we already returned false.  */
   13349       223593 :       auto skip_parms = [] (tree fn, tree parms)
   13350              :         {
   13351       149062 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   13352         1020 :             return TREE_CHAIN (parms);
   13353              :           else
   13354       148042 :             return skip_artificial_parms_for (fn, parms);
   13355              :         };
   13356        74531 :       parms1 = skip_parms (fn1, parms1);
   13357        74531 :       parms2 = skip_parms (fn2, parms2);
   13358              :     }
   13359      4766658 :   else if (reversed)
   13360       135339 :     return (reversed_match (c1, c2)
   13361       135339 :             && reversed_match (c2, c1));
   13362      4705850 :   return compparms (parms1, parms2);
   13363              : }
   13364              : 
   13365              : /* True iff FN is a copy or move constructor or assignment operator.  */
   13366              : 
   13367              : static bool
   13368     20781010 : sfk_copy_or_move (tree fn)
   13369              : {
   13370     20781010 :   if (TREE_CODE (fn) != FUNCTION_DECL)
   13371              :     return false;
   13372     20780920 :   special_function_kind sfk = special_function_p (fn);
   13373     20780920 :   return sfk >= sfk_copy_constructor && sfk <= sfk_move_assignment;
   13374              : }
   13375              : 
   13376              : /* Compare two candidates for overloading as described in
   13377              :    [over.match.best].  Return values:
   13378              : 
   13379              :       1: cand1 is better than cand2
   13380              :      -1: cand2 is better than cand1
   13381              :       0: cand1 and cand2 are indistinguishable */
   13382              : 
   13383              : static int
   13384     78652485 : joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn,
   13385              :        tsubst_flags_t complain)
   13386              : {
   13387     78652485 :   int winner = 0;
   13388     78652485 :   int off1 = 0, off2 = 0;
   13389     78652485 :   size_t i;
   13390     78652485 :   size_t len;
   13391              : 
   13392              :   /* Candidates that involve bad conversions are always worse than those
   13393              :      that don't.  */
   13394     78652485 :   if (cand1->viable > cand2->viable)
   13395              :     return 1;
   13396     63083938 :   if (cand1->viable < cand2->viable)
   13397              :     return -1;
   13398              : 
   13399              :   /* If we have two pseudo-candidates for conversions to the same type,
   13400              :      or two candidates for the same function, arbitrarily pick one.  */
   13401     63083938 :   if (cand1->fn == cand2->fn
   13402      1911244 :       && cand1->reversed () == cand2->reversed ()
   13403     63922075 :       && (IS_TYPE_OR_DECL_P (cand1->fn)))
   13404              :     return 1;
   13405              : 
   13406              :   /* Prefer a non-deleted function over an implicitly deleted move
   13407              :      constructor or assignment operator.  This differs slightly from the
   13408              :      wording for issue 1402 (which says the move op is ignored by overload
   13409              :      resolution), but this way produces better error messages.  */
   13410     63083938 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13411     58703044 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13412    121777150 :       && DECL_DELETED_FN (cand1->fn) != DECL_DELETED_FN (cand2->fn))
   13413              :     {
   13414      2539336 :       if (DECL_DELETED_FN (cand1->fn) && DECL_DEFAULTED_FN (cand1->fn)
   13415      2118926 :           && move_fn_p (cand1->fn))
   13416              :         return -1;
   13417      3804642 :       if (DECL_DELETED_FN (cand2->fn) && DECL_DEFAULTED_FN (cand2->fn)
   13418      3066913 :           && move_fn_p (cand2->fn))
   13419              :         return 1;
   13420              :     }
   13421              : 
   13422              :   /* a viable function F1
   13423              :      is defined to be a better function than another viable function F2  if
   13424              :      for  all arguments i, ICSi(F1) is not a worse conversion sequence than
   13425              :      ICSi(F2), and then */
   13426              : 
   13427              :   /* for some argument j, ICSj(F1) is a better conversion  sequence  than
   13428              :      ICSj(F2) */
   13429              : 
   13430              :   /* For comparing static and non-static member functions, we ignore
   13431              :      the implicit object parameter of the non-static function.  The
   13432              :      standard says to pretend that the static function has an object
   13433              :      parm, but that won't work with operator overloading.  */
   13434     63069156 :   len = cand1->num_convs;
   13435     63069156 :   if (len != cand2->num_convs)
   13436              :     {
   13437          781 :       int static_1 = (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13438          781 :                       && DECL_STATIC_FUNCTION_P (cand1->fn));
   13439          781 :       int static_2 = (TREE_CODE (cand2->fn) == FUNCTION_DECL
   13440          781 :                       && DECL_STATIC_FUNCTION_P (cand2->fn));
   13441              : 
   13442          781 :       if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13443          193 :           && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13444          193 :           && DECL_CONSTRUCTOR_P (cand1->fn)
   13445          787 :           && is_list_ctor (cand1->fn) != is_list_ctor (cand2->fn))
   13446              :         /* We're comparing a near-match list constructor and a near-match
   13447              :            non-list constructor.  Just treat them as unordered.  */
   13448              :         return 0;
   13449              : 
   13450          775 :       gcc_assert (static_1 != static_2);
   13451              : 
   13452          775 :       if (static_1)
   13453              :         {
   13454              :           /* C++23 [over.best.ics.general] says:
   13455              :              When the parameter is the implicit object parameter of a static
   13456              :              member function, the implicit conversion sequence is a standard
   13457              :              conversion sequence that is neither better nor worse than any
   13458              :              other standard conversion sequence.  */
   13459           72 :           if (CONVERSION_RANK (cand2->convs[0]) >= cr_user)
   13460            0 :             winner = 1;
   13461              :           off2 = 1;
   13462              :         }
   13463              :       else
   13464              :         {
   13465          703 :           if (CONVERSION_RANK (cand1->convs[0]) >= cr_user)
   13466          588 :             winner = -1;
   13467          703 :           off1 = 1;
   13468          703 :           --len;
   13469              :         }
   13470              :     }
   13471              : 
   13472    146981852 :   for (i = 0; i < len; ++i)
   13473              :     {
   13474     83914285 :       conversion *t1 = cand1->convs[i + off1];
   13475     83914285 :       conversion *t2 = cand2->convs[i + off2];
   13476     83914285 :       int comp = compare_ics (t1, t2);
   13477              : 
   13478     83914285 :       if (comp != 0)
   13479              :         {
   13480     56759496 :           if ((complain & tf_warning)
   13481     46852541 :               && warn_sign_promo
   13482           82 :               && (CONVERSION_RANK (t1) + CONVERSION_RANK (t2)
   13483              :                   == cr_std + cr_promotion)
   13484           50 :               && t1->kind == ck_std
   13485           31 :               && t2->kind == ck_std
   13486           31 :               && TREE_CODE (t1->type) == INTEGER_TYPE
   13487           31 :               && TREE_CODE (t2->type) == INTEGER_TYPE
   13488           31 :               && (TYPE_PRECISION (t1->type)
   13489           31 :                   == TYPE_PRECISION (t2->type))
   13490     56759527 :               && (TYPE_UNSIGNED (next_conversion (t1)->type)
   13491            0 :                   || (TREE_CODE (next_conversion (t1)->type)
   13492              :                       == ENUMERAL_TYPE)))
   13493              :             {
   13494           31 :               tree type = next_conversion (t1)->type;
   13495           31 :               tree type1, type2;
   13496           31 :               struct z_candidate *w, *l;
   13497           31 :               if (comp > 0)
   13498              :                 type1 = t1->type, type2 = t2->type,
   13499              :                   w = cand1, l = cand2;
   13500              :               else
   13501            8 :                 type1 = t2->type, type2 = t1->type,
   13502            8 :                   w = cand2, l = cand1;
   13503              : 
   13504           31 :               if (warn)
   13505              :                 {
   13506            9 :                   warning (OPT_Wsign_promo, "passing %qT chooses %qT over %qT",
   13507              :                            type, type1, type2);
   13508            9 :                   warning (OPT_Wsign_promo, "  in call to %qD", w->fn);
   13509              :                 }
   13510              :               else
   13511           22 :                 add_warning (w, l);
   13512              :             }
   13513              : 
   13514     56759496 :           if (winner && comp != winner)
   13515              :             {
   13516              :               /* Ambiguity between normal and reversed comparison operators
   13517              :                  with the same parameter types.  P2468 decided not to go with
   13518              :                  this approach to resolving the ambiguity, so pedwarn.  */
   13519         1583 :               if ((complain & tf_warning_or_error)
   13520         1009 :                   && (cand1->reversed () != cand2->reversed ())
   13521         1935 :                   && cand_parms_match (cand1, cand2, pmatch::original))
   13522              :                 {
   13523          337 :                   struct z_candidate *w, *l;
   13524          337 :                   if (cand2->reversed ())
   13525              :                     winner = 1, w = cand1, l = cand2;
   13526              :                   else
   13527          315 :                     winner = -1, w = cand2, l = cand1;
   13528          337 :                   if (warn)
   13529              :                     {
   13530           22 :                       auto_diagnostic_group d;
   13531           22 :                       if (pedwarn (input_location, 0,
   13532              :                                    "C++20 says that these are ambiguous, "
   13533              :                                    "even though the second is reversed:"))
   13534              :                         {
   13535           22 :                           print_z_candidate (input_location,
   13536              :                                              N_("candidate 1:"), w);
   13537           22 :                           print_z_candidate (input_location,
   13538              :                                              N_("candidate 2:"), l);
   13539           22 :                           if (w->fn == l->fn
   13540           17 :                               && DECL_IOBJ_MEMBER_FUNCTION_P (w->fn)
   13541           37 :                               && (type_memfn_quals (TREE_TYPE (w->fn))
   13542           15 :                                   & TYPE_QUAL_CONST) == 0)
   13543              :                             {
   13544              :                               /* Suggest adding const to
   13545              :                                  struct A { bool operator==(const A&); }; */
   13546           12 :                               tree parmtype
   13547           12 :                                 = FUNCTION_FIRST_USER_PARMTYPE (w->fn);
   13548           12 :                               parmtype = TREE_VALUE (parmtype);
   13549           12 :                               if (TYPE_REF_P (parmtype)
   13550           12 :                                   && TYPE_READONLY (TREE_TYPE (parmtype))
   13551           24 :                                   && (same_type_ignoring_top_level_qualifiers_p
   13552           12 :                                       (TREE_TYPE (parmtype),
   13553           12 :                                        DECL_CONTEXT (w->fn))))
   13554           12 :                                 inform (DECL_SOURCE_LOCATION (w->fn),
   13555              :                                         "try making the operator a %<const%> "
   13556              :                                         "member function");
   13557              :                             }
   13558              :                         }
   13559           22 :                     }
   13560              :                   else
   13561          315 :                     add_warning (w, l);
   13562              :                   return winner;
   13563              :                 }
   13564              : 
   13565         1246 :               winner = 0;
   13566         1246 :               goto tweak;
   13567              :             }
   13568              :           winner = comp;
   13569              :         }
   13570              :     }
   13571              : 
   13572              :   /* warn about confusing overload resolution for user-defined conversions,
   13573              :      either between a constructor and a conversion op, or between two
   13574              :      conversion ops.  */
   13575     63067567 :   if ((complain & tf_warning)
   13576              :       /* In C++17, the constructor might have been elided, which means that
   13577              :          an originally null ->second_conv could become non-null.  */
   13578     51440736 :       && winner && warn_conversion && cand1->second_conv && cand2->second_conv
   13579           54 :       && (!DECL_CONSTRUCTOR_P (cand1->fn) || !DECL_CONSTRUCTOR_P (cand2->fn))
   13580     63067594 :       && winner != compare_ics (cand1->second_conv, cand2->second_conv))
   13581              :     {
   13582           27 :       struct z_candidate *w, *l;
   13583           27 :       bool give_warning = false;
   13584              : 
   13585           27 :       if (winner == 1)
   13586              :         w = cand1, l = cand2;
   13587              :       else
   13588            6 :         w = cand2, l = cand1;
   13589              : 
   13590              :       /* We don't want to complain about `X::operator T1 ()'
   13591              :          beating `X::operator T2 () const', when T2 is a no less
   13592              :          cv-qualified version of T1.  */
   13593           27 :       if (DECL_CONTEXT (w->fn) == DECL_CONTEXT (l->fn)
   13594           39 :           && !DECL_CONSTRUCTOR_P (w->fn) && !DECL_CONSTRUCTOR_P (l->fn))
   13595              :         {
   13596            6 :           tree t = TREE_TYPE (TREE_TYPE (l->fn));
   13597            6 :           tree f = TREE_TYPE (TREE_TYPE (w->fn));
   13598              : 
   13599            6 :           if (TREE_CODE (t) == TREE_CODE (f) && INDIRECT_TYPE_P (t))
   13600              :             {
   13601            6 :               t = TREE_TYPE (t);
   13602            6 :               f = TREE_TYPE (f);
   13603              :             }
   13604            6 :           if (!comp_ptr_ttypes (t, f))
   13605              :             give_warning = true;
   13606              :         }
   13607              :       else
   13608              :         give_warning = true;
   13609              : 
   13610              :       if (!give_warning)
   13611              :         /*NOP*/;
   13612           21 :       else if (warn)
   13613              :         {
   13614            9 :           tree source = source_type (w->convs[0]);
   13615            9 :           if (INDIRECT_TYPE_P (source))
   13616            6 :             source = TREE_TYPE (source);
   13617            9 :           auto_diagnostic_group d;
   13618            9 :           if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn)
   13619           18 :               && warning (OPT_Wconversion, "  for conversion from %qH to %qI",
   13620            9 :                           source, w->second_conv->type))
   13621              :             {
   13622            9 :               inform (input_location, "  because conversion sequence "
   13623              :                       "for the argument is better");
   13624              :             }
   13625            9 :         }
   13626              :       else
   13627           12 :         add_warning (w, l);
   13628              :     }
   13629              : 
   13630     63067567 :   if (winner)
   13631              :     return winner;
   13632              : 
   13633              :   /* DR 495 moved this tiebreaker above the template ones.  */
   13634              :   /* or, if not that,
   13635              :      the  context  is  an  initialization by user-defined conversion (see
   13636              :      _dcl.init_  and  _over.match.user_)  and  the  standard   conversion
   13637              :      sequence  from  the return type of F1 to the destination type (i.e.,
   13638              :      the type of the entity being initialized)  is  a  better  conversion
   13639              :      sequence  than the standard conversion sequence from the return type
   13640              :      of F2 to the destination type.  */
   13641              : 
   13642     10390657 :   if (cand1->second_conv)
   13643              :     {
   13644        51890 :       winner = compare_ics (cand1->second_conv, cand2->second_conv);
   13645        51890 :       if (winner)
   13646              :         return winner;
   13647              :     }
   13648              : 
   13649              :   /* CWG2735 (PR109247): A copy/move ctor/op= for which its operand uses an
   13650              :      explicit conversion (due to list-initialization) is worse.  */
   13651     10390505 :   {
   13652     10390505 :     z_candidate *sp = nullptr;
   13653     10390505 :     if (sfk_copy_or_move (cand1->fn))
   13654          680 :       sp = cand1;
   13655     10390505 :     if (sfk_copy_or_move (cand2->fn))
   13656       895545 :       sp = sp ? nullptr : cand2;
   13657     10390452 :     if (sp)
   13658              :       {
   13659      1792238 :         conversion *conv = sp->convs[!DECL_CONSTRUCTOR_P (sp->fn)];
   13660       896119 :         if (conv->user_conv_p)
   13661         2378 :           for (; conv; conv = next_conversion (conv))
   13662         1998 :             if (conv->kind == ck_user
   13663          809 :                 && DECL_P (conv->cand->fn)
   13664         2807 :                 && DECL_NONCONVERTING_P (conv->cand->fn))
   13665          429 :               return (sp == cand1) ? -1 : 1;
   13666              :       }
   13667              :   }
   13668              : 
   13669              :   /* DR2327: C++17 copy elision in [over.match.ctor] (direct-init) context.
   13670              :      The standard currently says that only constructors are candidates, but if
   13671              :      one copies a prvalue returned by a conversion function we prefer that.
   13672              : 
   13673              :      Clang does something similar, as discussed at
   13674              :      http://lists.isocpp.org/core/2017/10/3166.php
   13675              :      http://lists.isocpp.org/core/2019/03/5721.php  */
   13676      6765517 :   if (len == 1 && cxx_dialect >= cxx17
   13677      6750905 :       && DECL_P (cand1->fn)
   13678      6750905 :       && DECL_COMPLETE_CONSTRUCTOR_P (cand1->fn)
   13679     11208755 :       && !(cand1->flags & LOOKUP_ONLYCONVERTING))
   13680              :     {
   13681       443495 :       bool elided1 = joust_maybe_elide_copy (cand1);
   13682       443495 :       bool elided2 = joust_maybe_elide_copy (cand2);
   13683       443495 :       winner = elided1 - elided2;
   13684       443495 :       if (winner)
   13685              :         return winner;
   13686              :     }
   13687              : 
   13688              :   /* or, if not that,
   13689              :      F1 is a non-template function and F2 is a template function
   13690              :      specialization.  */
   13691              : 
   13692     10389843 :   if (!cand1->template_decl && cand2->template_decl)
   13693              :     return 1;
   13694     10327598 :   else if (cand1->template_decl && !cand2->template_decl)
   13695              :     return -1;
   13696              : 
   13697              :   /* or, if not that,
   13698              :      F1 and F2 are template functions and the function template for F1 is
   13699              :      more specialized than the template for F2 according to the partial
   13700              :      ordering rules.  */
   13701              : 
   13702      9164833 :   if (cand1->template_decl && cand2->template_decl)
   13703              :     {
   13704      4162967 :       winner = more_specialized_fn
   13705      4162967 :         (TI_TEMPLATE (cand1->template_decl),
   13706      4162967 :          TI_TEMPLATE (cand2->template_decl),
   13707              :          /* [temp.func.order]: The presence of unused ellipsis and default
   13708              :             arguments has no effect on the partial ordering of function
   13709              :             templates.   add_function_candidate() will not have
   13710              :             counted the "this" argument for constructors.  */
   13711      8325934 :          cand1->num_convs + DECL_CONSTRUCTOR_P (cand1->fn));
   13712      4162967 :       if (winner)
   13713              :         return winner;
   13714              :     }
   13715              : 
   13716              :   /* F1 and F2 are non-template functions and
   13717              :      - they have the same non-object-parameter-type-lists ([dcl.fct]), and
   13718              :      - if they are member functions, both are direct members of the same
   13719              :        class, and
   13720              :      - if both are non-static member functions, they have the same types for
   13721              :        their object parameters, and
   13722              :      - F1 is more constrained than F2 according to the partial ordering of
   13723              :        constraints described in [temp.constr.order].  */
   13724      6120278 :   if (flag_concepts && DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13725      6120230 :       && !cand1->template_decl && !cand2->template_decl
   13726     11122505 :       && cand_parms_match (cand1, cand2, pmatch::current))
   13727              :     {
   13728       408266 :       winner = more_constrained (cand1->fn, cand2->fn);
   13729       408266 :       if (winner)
   13730              :         return winner;
   13731              :     }
   13732              : 
   13733              :   /* F2 is a rewritten candidate (12.4.1.2) and F1 is not, or F1 and F2 are
   13734              :      rewritten candidates, and F2 is a synthesized candidate with reversed
   13735              :      order of parameters and F1 is not.  */
   13736      6124690 :   if (cand1->rewritten ())
   13737              :     {
   13738      1273826 :       if (!cand2->rewritten ())
   13739              :         return -1;
   13740       816755 :       if (!cand1->reversed () && cand2->reversed ())
   13741              :         return 1;
   13742       816755 :       if (cand1->reversed () && !cand2->reversed ())
   13743              :         return -1;
   13744              :     }
   13745      4850864 :   else if (cand2->rewritten ())
   13746              :     return 1;
   13747              : 
   13748      4782015 :   if (deduction_guide_p (cand1->fn))
   13749              :     {
   13750         4057 :       gcc_assert (deduction_guide_p (cand2->fn));
   13751              : 
   13752              :       /* F1 and F2 are generated from class template argument deduction for a
   13753              :          class D, and F2 is generated from inheriting constructors from a base
   13754              :          class of D while F1 is not, and for each explicit function argument,
   13755              :          the corresponding parameters of F1 and F2 are either both ellipses or
   13756              :          have the same type.  */
   13757         4057 :       bool inherited1 = inherited_guide_p (cand1->fn);
   13758         4057 :       bool inherited2 = inherited_guide_p (cand2->fn);
   13759         4057 :       if (int diff = inherited2 - inherited1)
   13760              :         {
   13761           68 :           for (i = 0; i < len; ++i)
   13762              :             {
   13763           19 :               conversion *t1 = cand1->convs[i + off1];
   13764           19 :               conversion *t2 = cand2->convs[i + off2];
   13765              :               /* ??? It seems the ellipses part of this tiebreaker isn't
   13766              :                  needed since a mismatch should have broken the tie earlier
   13767              :                  during ICS comparison.  */
   13768           19 :               gcc_checking_assert (t1->ellipsis_p == t2->ellipsis_p);
   13769           19 :               if (!same_type_p (t1->type, t2->type))
   13770              :                 break;
   13771              :             }
   13772           51 :           if (i == len)
   13773              :             return diff;
   13774              :         }
   13775              : 
   13776              :       /* F1 is generated from a deduction-guide (13.3.1.8) and F2 is not */
   13777              :       /* We distinguish between candidates from an explicit deduction guide and
   13778              :          candidates built from a constructor based on DECL_ARTIFICIAL.  */
   13779         4008 :       int art1 = DECL_ARTIFICIAL (cand1->fn);
   13780         4008 :       int art2 = DECL_ARTIFICIAL (cand2->fn);
   13781         4008 :       if (art1 != art2)
   13782         1415 :         return art2 - art1;
   13783              : 
   13784         2593 :       if (art1)
   13785              :         {
   13786              :           /* Prefer the special copy guide over a declared copy/move
   13787              :              constructor.  */
   13788         2590 :           if (copy_guide_p (cand1->fn))
   13789              :             return 1;
   13790           86 :           if (copy_guide_p (cand2->fn))
   13791              :             return -1;
   13792              : 
   13793              :           /* Prefer a candidate generated from a non-template constructor.  */
   13794           28 :           int tg1 = template_guide_p (cand1->fn);
   13795           28 :           int tg2 = template_guide_p (cand2->fn);
   13796           28 :           if (tg1 != tg2)
   13797            6 :             return tg2 - tg1;
   13798              :         }
   13799              :     }
   13800              : 
   13801              :   /* F1 is a constructor for a class D, F2 is a constructor for a base class B
   13802              :      of D, and for all arguments the corresponding parameters of F1 and F2 have
   13803              :      the same type (CWG 2273/2277).  */
   13804     14333794 :   if (DECL_INHERITED_CTOR (cand1->fn) || DECL_INHERITED_CTOR (cand2->fn))
   13805              :     {
   13806           87 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (cand1->fn));
   13807           87 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (cand2->fn));
   13808              : 
   13809           87 :       bool used1 = false;
   13810           87 :       bool used2 = false;
   13811           87 :       if (base1 == base2)
   13812              :         /* No difference.  */;
   13813           87 :       else if (DERIVED_FROM_P (base1, base2))
   13814              :         used1 = true;
   13815           18 :       else if (DERIVED_FROM_P (base2, base1))
   13816              :         used2 = true;
   13817              : 
   13818           78 :       if (int diff = used2 - used1)
   13819              :         {
   13820          105 :           for (i = 0; i < len; ++i)
   13821              :             {
   13822           36 :               conversion *t1 = cand1->convs[i + off1];
   13823           36 :               conversion *t2 = cand2->convs[i + off2];
   13824           36 :               if (!same_type_p (t1->type, t2->type))
   13825              :                 break;
   13826              :             }
   13827           78 :           if (i == len)
   13828              :             return diff;
   13829              :         }
   13830              :     }
   13831              : 
   13832              :   /* Check whether we can discard a builtin candidate, either because we
   13833              :      have two identical ones or matching builtin and non-builtin candidates.
   13834              : 
   13835              :      (Pedantically in the latter case the builtin which matched the user
   13836              :      function should not be added to the overload set, but we spot it here.
   13837              : 
   13838              :      [over.match.oper]
   13839              :      ... the builtin candidates include ...
   13840              :      - do not have the same parameter type list as any non-template
   13841              :        non-member candidate.  */
   13842              : 
   13843      4777914 :   if (identifier_p (cand1->fn) || identifier_p (cand2->fn))
   13844              :     {
   13845           93 :       for (i = 0; i < len; ++i)
   13846           69 :         if (!same_type_p (cand1->convs[i]->type,
   13847              :                           cand2->convs[i]->type))
   13848              :           break;
   13849           43 :       if (i == cand1->num_convs)
   13850              :         {
   13851           24 :           if (cand1->fn == cand2->fn)
   13852              :             /* Two built-in candidates; arbitrarily pick one.  */
   13853              :             return 1;
   13854           21 :           else if (identifier_p (cand1->fn))
   13855              :             /* cand1 is built-in; prefer cand2.  */
   13856           21 :             return -1;
   13857              :           else
   13858              :             /* cand2 is built-in; prefer cand1.  */
   13859              :             return 1;
   13860              :         }
   13861              :     }
   13862              : 
   13863              :   /* For candidates of a multi-versioned function,  make the version with
   13864              :      the highest priority win.  This version will be checked for dispatching
   13865              :      first.  If this version can be inlined into the caller, the front-end
   13866              :      will simply make a direct call to this function.  */
   13867              : 
   13868      4777890 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13869      4777868 :       && DECL_FUNCTION_VERSIONED (cand1->fn)
   13870          941 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13871      4778831 :       && DECL_FUNCTION_VERSIONED (cand2->fn))
   13872              :     {
   13873          941 :       tree f1 = TREE_TYPE (cand1->fn);
   13874          941 :       tree f2 = TREE_TYPE (cand2->fn);
   13875          941 :       tree p1 = TYPE_ARG_TYPES (f1);
   13876          941 :       tree p2 = TYPE_ARG_TYPES (f2);
   13877              : 
   13878              :       /* Check if cand1->fn and cand2->fn are versions of the same function.  It
   13879              :          is possible that cand1->fn and cand2->fn are function versions but of
   13880              :          different functions.  Check types to see if they are versions of the same
   13881              :          function.  */
   13882          941 :       if (compparms (p1, p2)
   13883          941 :           && same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
   13884              :         {
   13885              :           /* Always make the version with the higher priority, more
   13886              :              specialized, win.  */
   13887          941 :           gcc_assert (targetm.compare_version_priority);
   13888          941 :           if (targetm.compare_version_priority (cand1->fn, cand2->fn) >= 0)
   13889              :             return 1;
   13890              :           else
   13891          254 :             return -1;
   13892              :         }
   13893              :     }
   13894              : 
   13895              :   /* If the two function declarations represent the same function (this can
   13896              :      happen with declarations in multiple scopes and arg-dependent lookup),
   13897              :      arbitrarily choose one.  But first make sure the default args we're
   13898              :      using match.  */
   13899      4776927 :   if (DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13900      9553876 :       && equal_functions (cand1->fn, cand2->fn))
   13901              :     {
   13902           35 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (cand1->fn));
   13903           35 :       tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (cand2->fn));
   13904              : 
   13905           70 :       gcc_assert (!DECL_CONSTRUCTOR_P (cand1->fn));
   13906              : 
   13907           50 :       for (i = 0; i < len; ++i)
   13908              :         {
   13909              :           /* Don't crash if the fn is variadic.  */
   13910           15 :           if (!parms1)
   13911              :             break;
   13912           15 :           parms1 = TREE_CHAIN (parms1);
   13913           15 :           parms2 = TREE_CHAIN (parms2);
   13914              :         }
   13915              : 
   13916           35 :       if (off1)
   13917            0 :         parms1 = TREE_CHAIN (parms1);
   13918           35 :       else if (off2)
   13919            0 :         parms2 = TREE_CHAIN (parms2);
   13920              : 
   13921           69 :       for (; parms1; ++i)
   13922              :         {
   13923           80 :           if (!cp_tree_equal (TREE_PURPOSE (parms1),
   13924           40 :                               TREE_PURPOSE (parms2)))
   13925              :             {
   13926            6 :               if (warn)
   13927              :                 {
   13928            3 :                   if (complain & tf_error)
   13929              :                     {
   13930            3 :                       auto_diagnostic_group d;
   13931            3 :                       if (permerror (input_location,
   13932              :                                      "default argument mismatch in "
   13933              :                                      "overload resolution"))
   13934              :                         {
   13935            3 :                           inform (DECL_SOURCE_LOCATION (cand1->fn),
   13936              :                                   " candidate 1: %q#F", cand1->fn);
   13937            3 :                           inform (DECL_SOURCE_LOCATION (cand2->fn),
   13938              :                                   " candidate 2: %q#F", cand2->fn);
   13939              :                         }
   13940            3 :                     }
   13941              :                   else
   13942              :                     return 0;
   13943              :                 }
   13944              :               else
   13945            3 :                 add_warning (cand1, cand2);
   13946              :               break;
   13947              :             }
   13948           34 :           parms1 = TREE_CHAIN (parms1);
   13949           34 :           parms2 = TREE_CHAIN (parms2);
   13950              :         }
   13951              : 
   13952              :       return 1;
   13953              :     }
   13954              : 
   13955      4778160 : tweak:
   13956              : 
   13957              :   /* Extension: If the worst conversion for one candidate is better than the
   13958              :      worst conversion for the other, take the first.  */
   13959      4778160 :   if (!pedantic && (complain & tf_warning_or_error))
   13960              :     {
   13961              :       conversion_rank rank1 = cr_identity, rank2 = cr_identity;
   13962     10302408 :       struct z_candidate *w = 0, *l = 0;
   13963              : 
   13964     10302408 :       for (i = 0; i < len; ++i)
   13965              :         {
   13966      5775371 :           if (CONVERSION_RANK (cand1->convs[i+off1]) > rank1)
   13967      4433185 :             rank1 = CONVERSION_RANK (cand1->convs[i+off1]);
   13968      5775371 :           if (CONVERSION_RANK (cand2->convs[i + off2]) > rank2)
   13969      4433202 :             rank2 = CONVERSION_RANK (cand2->convs[i + off2]);
   13970              :         }
   13971      4527037 :       if (rank1 < rank2)
   13972           74 :         winner = 1, w = cand1, l = cand2;
   13973      4527037 :       if (rank1 > rank2)
   13974              :         winner = -1, w = cand2, l = cand1;
   13975      4526929 :       if (winner)
   13976              :         {
   13977              :           /* Don't choose a deleted function over ambiguity.  */
   13978          182 :           if (DECL_P (w->fn) && DECL_DELETED_FN (w->fn))
   13979              :             return 0;
   13980          182 :           if (warn)
   13981              :             {
   13982            6 :               auto_diagnostic_group d;
   13983            6 :               if (pedwarn (input_location, 0,
   13984              :                            "ISO C++ says that these are ambiguous, even "
   13985              :                            "though the worst conversion for the first is "
   13986              :                            "better than the worst conversion for the second:"))
   13987              :                 {
   13988            3 :                   print_z_candidate (input_location, N_("candidate 1:"), w);
   13989            3 :                   print_z_candidate (input_location, N_("candidate 2:"), l);
   13990              :                 }
   13991            6 :             }
   13992              :           else
   13993          176 :             add_warning (w, l);
   13994              :           return winner;
   13995              :         }
   13996              :     }
   13997              : 
   13998              :   gcc_assert (!winner);
   13999              :   return 0;
   14000              : }
   14001              : 
   14002              : /* Given a list of candidates for overloading, find the best one, if any.
   14003              :    This algorithm has a worst case of O(2n) (winner is last), and a best
   14004              :    case of O(n/2) (totally ambiguous); much better than a sorting
   14005              :    algorithm.  The candidates list is assumed to be sorted according
   14006              :    to viability (via splice_viable).  */
   14007              : 
   14008              : static struct z_candidate *
   14009    245533802 : tourney (struct z_candidate *candidates, tsubst_flags_t complain)
   14010              : {
   14011    245533802 :   struct z_candidate **champ = &candidates, **challenger;
   14012    245533802 :   int fate;
   14013    245533802 :   struct z_candidate *previous_worse_champ = nullptr;
   14014              : 
   14015              :   /* Walk through the list once, comparing each current champ to the next
   14016              :      candidate, knocking out a candidate or two with each comparison.  */
   14017              : 
   14018    313138079 :   for (challenger = &candidates->next; *challenger && (*challenger)->viable; )
   14019              :     {
   14020     67617190 :       fate = joust (*champ, *challenger, 0, complain);
   14021     67617190 :       if (fate == 1)
   14022     43821100 :         challenger = &(*challenger)->next;
   14023     23796090 :       else if (fate == -1)
   14024              :         {
   14025     19019818 :           previous_worse_champ = *champ;
   14026     19019818 :           champ = challenger;
   14027     19019818 :           challenger = &(*challenger)->next;
   14028              :         }
   14029              :       else
   14030              :         {
   14031      4776272 :           previous_worse_champ = nullptr;
   14032      4776272 :           champ = &(*challenger)->next;
   14033      4776272 :           if (!*champ || !(*champ)->viable
   14034      4763453 :               || (*champ)->viable < (*challenger)->viable)
   14035              :             {
   14036              :               champ = nullptr;
   14037              :               break;
   14038              :             }
   14039      4763359 :           challenger = &(*champ)->next;
   14040              :         }
   14041              :     }
   14042              : 
   14043              :   /* Make sure the champ is better than all the candidates it hasn't yet
   14044              :      been compared to.  */
   14045              : 
   14046    245533802 :   if (champ)
   14047     28829216 :     for (challenger = &candidates;
   14048    274350105 :          challenger != champ;
   14049     28829216 :          challenger = &(*challenger)->next)
   14050              :       {
   14051     28831122 :         if (*challenger == previous_worse_champ)
   14052              :           /* We already know this candidate is worse than the champ.  */
   14053     17795876 :           continue;
   14054     11035246 :         fate = joust (*champ, *challenger, 0, complain);
   14055     11035246 :         if (fate != 1)
   14056              :           {
   14057              :             champ = nullptr;
   14058              :             break;
   14059              :           }
   14060              :       }
   14061              : 
   14062    245520889 :   if (!champ)
   14063              :     return nullptr;
   14064              : 
   14065              :   /* Move the champ to the front of the candidate list.  */
   14066              : 
   14067    245518983 :   if (champ != &candidates)
   14068              :     {
   14069     19491661 :       z_candidate *saved_champ = *champ;
   14070     19491661 :       *champ = saved_champ->next;
   14071     19491661 :       saved_champ->next = candidates;
   14072     19491661 :       candidates = saved_champ;
   14073              :     }
   14074              : 
   14075    245518983 :   return candidates;
   14076              : }
   14077              : 
   14078              : /* Returns nonzero if things of type FROM can be converted to TO.  */
   14079              : 
   14080              : bool
   14081      4528718 : can_convert (tree to, tree from, tsubst_flags_t complain)
   14082              : {
   14083      4528718 :   tree arg = NULL_TREE;
   14084              :   /* implicit_conversion only considers user-defined conversions
   14085              :      if it has an expression for the call argument list.  */
   14086      4528718 :   if (CLASS_TYPE_P (from) || CLASS_TYPE_P (to))
   14087          111 :     arg = build_stub_object (from);
   14088      4528718 :   return can_convert_arg (to, from, arg, LOOKUP_IMPLICIT, complain);
   14089              : }
   14090              : 
   14091              : /* Returns nonzero if things of type FROM can be converted to TO with a
   14092              :    standard conversion.  */
   14093              : 
   14094              : bool
   14095          263 : can_convert_standard (tree to, tree from, tsubst_flags_t complain)
   14096              : {
   14097          263 :   return can_convert_arg (to, from, NULL_TREE, LOOKUP_IMPLICIT, complain);
   14098              : }
   14099              : 
   14100              : /* Returns nonzero if ARG (of type FROM) can be converted to TO.  */
   14101              : 
   14102              : bool
   14103      5532210 : can_convert_arg (tree to, tree from, tree arg, int flags,
   14104              :                  tsubst_flags_t complain)
   14105              : {
   14106      5532210 :   conversion *t;
   14107      5532210 :   bool ok_p;
   14108              : 
   14109      5532210 :   conversion_obstack_sentinel cos;
   14110              :   /* We want to discard any access checks done for this test,
   14111              :      as we might not be in the appropriate access context and
   14112              :      we'll do the check again when we actually perform the
   14113              :      conversion.  */
   14114      5532210 :   push_deferring_access_checks (dk_deferred);
   14115              : 
   14116              :   /* Handle callers like check_local_shadow forgetting to
   14117              :      convert_from_reference.  */
   14118      5532210 :   if (TYPE_REF_P (from) && arg)
   14119              :     {
   14120           61 :       arg = convert_from_reference (arg);
   14121           61 :       from = TREE_TYPE (arg);
   14122              :     }
   14123              : 
   14124      5532210 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   14125              :                             flags, complain);
   14126      5532210 :   ok_p = (t && !t->bad_p);
   14127              : 
   14128              :   /* Discard the access checks now.  */
   14129      5532210 :   pop_deferring_access_checks ();
   14130              : 
   14131     11064420 :   return ok_p;
   14132      5532210 : }
   14133              : 
   14134              : /* Like can_convert_arg, but allows dubious conversions as well.  */
   14135              : 
   14136              : bool
   14137    185650608 : can_convert_arg_bad (tree to, tree from, tree arg, int flags,
   14138              :                      tsubst_flags_t complain)
   14139              : {
   14140    185650608 :   conversion *t;
   14141              : 
   14142    185650608 :   conversion_obstack_sentinel cos;
   14143              :   /* Try to perform the conversion.  */
   14144    185650608 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   14145              :                             flags, complain);
   14146              : 
   14147    371301216 :   return t != NULL;
   14148    185650608 : }
   14149              : 
   14150              : /* Return an IMPLICIT_CONV_EXPR from EXPR to TYPE with bits set from overload
   14151              :    resolution FLAGS.  */
   14152              : 
   14153              : tree
   14154     14895065 : build_implicit_conv_flags (tree type, tree expr, int flags)
   14155              : {
   14156              :   /* In a template, we are only concerned about determining the
   14157              :      type of non-dependent expressions, so we do not have to
   14158              :      perform the actual conversion.  But for initializers, we
   14159              :      need to be able to perform it at instantiation
   14160              :      (or instantiate_non_dependent_expr) time.  */
   14161     14895065 :   expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14162     14895065 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   14163      6769709 :     IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14164     14895065 :   if (flags & LOOKUP_NO_NARROWING)
   14165        23549 :     IMPLICIT_CONV_EXPR_BRACED_INIT (expr) = true;
   14166     14895065 :   return expr;
   14167              : }
   14168              : 
   14169              : /* Convert EXPR to TYPE.  Return the converted expression.
   14170              : 
   14171              :    Note that we allow bad conversions here because by the time we get to
   14172              :    this point we are committed to doing the conversion.  If we end up
   14173              :    doing a bad conversion, convert_like will complain.  */
   14174              : 
   14175              : tree
   14176    301489463 : perform_implicit_conversion_flags (tree type, tree expr,
   14177              :                                    tsubst_flags_t complain, int flags)
   14178              : {
   14179    301489463 :   conversion *conv;
   14180    301489463 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14181              : 
   14182    301489463 :   if (error_operand_p (expr))
   14183          456 :     return error_mark_node;
   14184              : 
   14185    301489007 :   conversion_obstack_sentinel cos;
   14186              : 
   14187    301489007 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14188              :                               /*c_cast_p=*/false,
   14189              :                               flags, complain);
   14190              : 
   14191    301489007 :   if (!conv)
   14192              :     {
   14193       263467 :       if (complain & tf_error)
   14194          488 :         implicit_conversion_error (loc, type, expr, flags);
   14195       263467 :       expr = error_mark_node;
   14196              :     }
   14197    301225540 :   else if (processing_template_decl && conv->kind != ck_identity)
   14198     14895065 :     expr = build_implicit_conv_flags (type, expr, flags);
   14199              :   else
   14200              :     {
   14201              :       /* Give a conversion call the same location as expr.  */
   14202    286330475 :       iloc_sentinel il (loc);
   14203    286330475 :       expr = convert_like (conv, expr, complain);
   14204    286330475 :     }
   14205              : 
   14206    301489007 :   return expr;
   14207    301489007 : }
   14208              : 
   14209              : tree
   14210     13199942 : perform_implicit_conversion (tree type, tree expr, tsubst_flags_t complain)
   14211              : {
   14212     13199942 :   return perform_implicit_conversion_flags (type, expr, complain,
   14213     13199942 :                                             LOOKUP_IMPLICIT);
   14214              : }
   14215              : 
   14216              : /* Convert EXPR to TYPE (as a direct-initialization) if that is
   14217              :    permitted.  If the conversion is valid, the converted expression is
   14218              :    returned.  Otherwise, NULL_TREE is returned, except in the case
   14219              :    that TYPE is a class type; in that case, an error is issued.  If
   14220              :    C_CAST_P is true, then this direct-initialization is taking
   14221              :    place as part of a static_cast being attempted as part of a C-style
   14222              :    cast.  */
   14223              : 
   14224              : tree
   14225     49310145 : perform_direct_initialization_if_possible (tree type,
   14226              :                                            tree expr,
   14227              :                                            bool c_cast_p,
   14228              :                                            tsubst_flags_t complain)
   14229              : {
   14230     49310145 :   conversion *conv;
   14231              : 
   14232     49310145 :   if (type == error_mark_node || error_operand_p (expr))
   14233              :     return error_mark_node;
   14234              :   /* [dcl.init]
   14235              : 
   14236              :      If the destination type is a (possibly cv-qualified) class type:
   14237              : 
   14238              :      -- If the initialization is direct-initialization ...,
   14239              :      constructors are considered.
   14240              : 
   14241              :        -- If overload resolution is successful, the selected constructor
   14242              :        is called to initialize the object, with the initializer expression
   14243              :        or expression-list as its argument(s).
   14244              : 
   14245              :        -- Otherwise, if no constructor is viable, the destination type is
   14246              :        a (possibly cv-qualified) aggregate class A, and the initializer is
   14247              :        a parenthesized expression-list, the object is initialized as
   14248              :        follows...  */
   14249     49310145 :   if (CLASS_TYPE_P (type))
   14250              :     {
   14251      3259122 :       releasing_vec args (make_tree_vector_single (expr));
   14252      3259122 :       expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
   14253              :                                         &args, type, LOOKUP_NORMAL, complain);
   14254      3259122 :       return build_cplus_new (type, expr, complain);
   14255      3259122 :     }
   14256              : 
   14257     46051023 :   conversion_obstack_sentinel cos;
   14258              : 
   14259     46051023 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14260              :                               c_cast_p,
   14261              :                               LOOKUP_NORMAL, complain);
   14262     46051023 :   if (!conv || conv->bad_p)
   14263              :     expr = NULL_TREE;
   14264     41240831 :   else if (processing_template_decl && conv->kind != ck_identity)
   14265              :     {
   14266              :       /* In a template, we are only concerned about determining the
   14267              :          type of non-dependent expressions, so we do not have to
   14268              :          perform the actual conversion.  But for initializers, we
   14269              :          need to be able to perform it at instantiation
   14270              :          (or instantiate_non_dependent_expr) time.  */
   14271       708912 :       expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14272       708912 :       IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14273              :     }
   14274              :   else
   14275     40531919 :     expr = convert_like (conv, expr, NULL_TREE, 0,
   14276              :                          /*issue_conversion_warnings=*/false,
   14277              :                          c_cast_p, /*nested_p=*/false, complain);
   14278              : 
   14279     46051023 :   return expr;
   14280     46051023 : }
   14281              : 
   14282              : /* When initializing a reference that lasts longer than a full-expression,
   14283              :    this special rule applies:
   14284              : 
   14285              :      [class.temporary]
   14286              : 
   14287              :      The temporary to which the reference is bound or the temporary
   14288              :      that is the complete object to which the reference is bound
   14289              :      persists for the lifetime of the reference.
   14290              : 
   14291              :      The temporaries created during the evaluation of the expression
   14292              :      initializing the reference, except the temporary to which the
   14293              :      reference is bound, are destroyed at the end of the
   14294              :      full-expression in which they are created.
   14295              : 
   14296              :    In that case, we store the converted expression into a new
   14297              :    VAR_DECL in a new scope.
   14298              : 
   14299              :    However, we want to be careful not to create temporaries when
   14300              :    they are not required.  For example, given:
   14301              : 
   14302              :      struct B {};
   14303              :      struct D : public B {};
   14304              :      D f();
   14305              :      const B& b = f();
   14306              : 
   14307              :    there is no need to copy the return value from "f"; we can just
   14308              :    extend its lifetime.  Similarly, given:
   14309              : 
   14310              :      struct S {};
   14311              :      struct T { operator S(); };
   14312              :      T t;
   14313              :      const S& s = t;
   14314              : 
   14315              :   we can extend the lifetime of the return value of the conversion
   14316              :   operator.
   14317              : 
   14318              :   The next several functions are involved in this lifetime extension.  */
   14319              : 
   14320              : /* DECL is a VAR_DECL or FIELD_DECL whose type is a REFERENCE_TYPE.  The
   14321              :    reference is being bound to a temporary.  Create and return a new
   14322              :    VAR_DECL with the indicated TYPE; this variable will store the value to
   14323              :    which the reference is bound.  */
   14324              : 
   14325              : tree
   14326         9388 : make_temporary_var_for_ref_to_temp (tree decl, tree type)
   14327              : {
   14328         9388 :   tree var = create_temporary_var (type);
   14329              : 
   14330              :   /* Register the variable.  */
   14331         9388 :   if (VAR_P (decl)
   14332         9388 :       && (TREE_STATIC (decl) || CP_DECL_THREAD_LOCAL_P (decl)))
   14333              :     {
   14334              :       /* Namespace-scope or local static; give it a mangled name.  */
   14335              : 
   14336              :       /* If an initializer is visible to multiple translation units, those
   14337              :          translation units must agree on the addresses of the
   14338              :          temporaries. Therefore the temporaries must be given a consistent name
   14339              :          and vague linkage. The mangled name of a temporary is the name of the
   14340              :          non-temporary object in whose initializer they appear, prefixed with
   14341              :          GR and suffixed with a sequence number mangled using the usual rules
   14342              :          for a seq-id. Temporaries are numbered with a pre-order, depth-first,
   14343              :          left-to-right walk of the complete initializer.  */
   14344          829 :       copy_linkage (var, decl);
   14345              : 
   14346          829 :       tree name = mangle_ref_init_variable (decl);
   14347          829 :       DECL_NAME (var) = name;
   14348          829 :       SET_DECL_ASSEMBLER_NAME (var, name);
   14349              : 
   14350              :       /* Set the context to make the variable mergeable in modules.  */
   14351          829 :       DECL_CONTEXT (var) = current_scope ();
   14352              :     }
   14353              :   else
   14354              :     /* Create a new cleanup level if necessary.  */
   14355         8559 :     maybe_push_cleanup_level (type);
   14356              : 
   14357         9388 :   return pushdecl (var);
   14358              : }
   14359              : 
   14360              : static tree extend_temps_r (tree *, int *, void *);
   14361              : 
   14362              : /* EXPR is the initializer for a variable DECL of reference or
   14363              :    std::initializer_list type.  Create, push and return a new VAR_DECL
   14364              :    for the initializer so that it will live as long as DECL.  Any
   14365              :    cleanup for the new variable is returned through CLEANUP, and the
   14366              :    code to initialize the new variable is returned through INITP.  */
   14367              : 
   14368              : static tree
   14369         9388 : set_up_extended_ref_temp (tree decl, tree expr, vec<tree, va_gc> **cleanups,
   14370              :                           tree *initp, tree *cond_guard,
   14371              :                           void *walk_data)
   14372              : {
   14373         9388 :   tree init;
   14374         9388 :   tree type;
   14375         9388 :   tree var;
   14376              : 
   14377              :   /* Create the temporary variable.  */
   14378         9388 :   type = TREE_TYPE (expr);
   14379         9388 :   var = make_temporary_var_for_ref_to_temp (decl, type);
   14380         9388 :   layout_decl (var, 0);
   14381              :   /* If the rvalue is the result of a function call it will be
   14382              :      a TARGET_EXPR.  If it is some other construct (such as a
   14383              :      member access expression where the underlying object is
   14384              :      itself the result of a function call), turn it into a
   14385              :      TARGET_EXPR here.  It is important that EXPR be a
   14386              :      TARGET_EXPR below since otherwise the INIT_EXPR will
   14387              :      attempt to make a bitwise copy of EXPR to initialize
   14388              :      VAR.  */
   14389         9388 :   if (TREE_CODE (expr) != TARGET_EXPR)
   14390            0 :     expr = get_target_expr (expr);
   14391              :   else
   14392              :     {
   14393         9388 :       if (TREE_ADDRESSABLE (expr))
   14394         9305 :         TREE_ADDRESSABLE (var) = 1;
   14395         9388 :       if (DECL_MERGEABLE (TARGET_EXPR_SLOT (expr)))
   14396          633 :         DECL_MERGEABLE (var) = true;
   14397              :     }
   14398              : 
   14399         9388 :   if (TREE_CODE (decl) == FIELD_DECL
   14400         9388 :       && extra_warnings && !warning_suppressed_p (decl))
   14401              :     {
   14402            3 :       warning (OPT_Wextra, "a temporary bound to %qD only persists "
   14403              :                "until the constructor exits", decl);
   14404            3 :       suppress_warning (decl);
   14405              :     }
   14406              : 
   14407              :   /* Recursively extend temps in this initializer.  The recursion needs to come
   14408              :      after creating the variable to conform to the mangling ABI, and before
   14409              :      maybe_constant_init because the extension might change its result.  */
   14410         9388 :   if (walk_data)
   14411         2192 :     cp_walk_tree (&TARGET_EXPR_INITIAL (expr), extend_temps_r,
   14412              :                   walk_data, nullptr);
   14413              :   else
   14414         7196 :     TARGET_EXPR_INITIAL (expr)
   14415        14392 :       = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups,
   14416              :                                cond_guard);
   14417              : 
   14418              :   /* Any reference temp has a non-trivial initializer.  */
   14419         9388 :   DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
   14420              : 
   14421              :   /* If the initializer is constant, put it in DECL_INITIAL so we get
   14422              :      static initialization and use in constant expressions.  */
   14423         9388 :   init = maybe_constant_init (expr, var, /*manifestly_const_eval=*/true);
   14424              :   /* As in store_init_value.  */
   14425         9388 :   init = cp_fully_fold (init);
   14426         9388 :   if (TREE_CONSTANT (init))
   14427              :     {
   14428         1309 :       if (literal_type_p (type)
   14429         1283 :           && CP_TYPE_CONST_NON_VOLATILE_P (type)
   14430         2084 :           && !TYPE_HAS_MUTABLE_P (type))
   14431              :         {
   14432              :           /* 5.19 says that a constant expression can include an
   14433              :              lvalue-rvalue conversion applied to "a glvalue of literal type
   14434              :              that refers to a non-volatile temporary object initialized
   14435              :              with a constant expression".  Rather than try to communicate
   14436              :              that this VAR_DECL is a temporary, just mark it constexpr.  */
   14437          772 :           DECL_DECLARED_CONSTEXPR_P (var) = true;
   14438          772 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = true;
   14439          772 :           TREE_CONSTANT (var) = true;
   14440          772 :           TREE_READONLY (var) = true;
   14441              :         }
   14442         1309 :       DECL_INITIAL (var) = init;
   14443         1309 :       init = NULL_TREE;
   14444              :     }
   14445              :   else
   14446              :     /* Create the INIT_EXPR that will initialize the temporary
   14447              :        variable.  */
   14448         8079 :     init = split_nonconstant_init (var, expr);
   14449         9388 :   if (at_function_scope_p ())
   14450              :     {
   14451         8651 :       add_decl_expr (var);
   14452              : 
   14453         8651 :       if (TREE_STATIC (var))
   14454           92 :         init = add_stmt_to_compound (init, register_dtor_fn (var));
   14455              :       else
   14456              :         {
   14457              :           /* ??? Instead of rebuilding the cleanup, we could replace the slot
   14458              :              with var in TARGET_EXPR_CLEANUP (expr).  */
   14459         8559 :           tree cleanup = cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14460         8559 :           if (cleanup)
   14461              :             {
   14462         3534 :               if (cond_guard && cleanup != error_mark_node)
   14463              :                 {
   14464           23 :                   if (*cond_guard == NULL_TREE)
   14465              :                     {
   14466           23 :                       *cond_guard = build_local_temp (boolean_type_node);
   14467           23 :                       add_decl_expr (*cond_guard);
   14468           23 :                       tree set = cp_build_modify_expr (UNKNOWN_LOCATION,
   14469              :                                                        *cond_guard, NOP_EXPR,
   14470              :                                                        boolean_false_node,
   14471              :                                                        tf_warning_or_error);
   14472           23 :                       finish_expr_stmt (set);
   14473              :                     }
   14474           23 :                   cleanup = build3 (COND_EXPR, void_type_node,
   14475              :                                     *cond_guard, cleanup, NULL_TREE);
   14476              :                 }
   14477         3534 :               if (flag_exceptions && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE)
   14478              :                 {
   14479              :                   /* The normal cleanup for this extended variable isn't pushed
   14480              :                      until cp_finish_decl, so we need to retain a TARGET_EXPR
   14481              :                      to clean it up in case a later initializer throws
   14482              :                      (g++.dg/eh/ref-temp3.C).
   14483              : 
   14484              :                      We don't do this for array temporaries because they have
   14485              :                      the array cleanup region from build_vec_init.
   14486              : 
   14487              :                      Unlike maybe_push_temp_cleanup, we don't actually need a
   14488              :                      flag, but a TARGET_EXPR needs a TARGET_EXPR_SLOT.
   14489              :                      Perhaps this could use WITH_CLEANUP_EXPR instead, but
   14490              :                      gimplify.cc doesn't handle that, and front-end handling
   14491              :                      was removed in r8-1725 and r8-1818.
   14492              : 
   14493              :                      Alternately it might be preferable to flatten an
   14494              :                      initialization with extended temps into a sequence of
   14495              :                      (non-full-expression) statements, so we could immediately
   14496              :                      push_cleanup here for only a single cleanup region, but we
   14497              :                      don't have a mechanism for that in the front-end, only the
   14498              :                      gimplifier.  */
   14499         3426 :                   tree targ = get_internal_target_expr (boolean_true_node);
   14500         3426 :                   TARGET_EXPR_CLEANUP (targ) = cleanup;
   14501         3426 :                   CLEANUP_EH_ONLY (targ) = true;
   14502              :                   /* Don't actually initialize the bool.  */
   14503         3426 :                   init = (!init ? void_node
   14504         3400 :                           : convert_to_void (init, ICV_STATEMENT, tf_none));
   14505         3426 :                   TARGET_EXPR_INITIAL (targ) = init;
   14506         3426 :                   init = targ;
   14507              :                 }
   14508         3534 :               vec_safe_push (*cleanups, cleanup);
   14509              :             }
   14510              :         }
   14511              : 
   14512              :       /* We must be careful to destroy the temporary only
   14513              :          after its initialization has taken place.  If the
   14514              :          initialization throws an exception, then the
   14515              :          destructor should not be run.  We cannot simply
   14516              :          transform INIT into something like:
   14517              : 
   14518              :          (INIT, ({ CLEANUP_STMT; }))
   14519              : 
   14520              :          because emit_local_var always treats the
   14521              :          initializer as a full-expression.  Thus, the
   14522              :          destructor would run too early; it would run at the
   14523              :          end of initializing the reference variable, rather
   14524              :          than at the end of the block enclosing the
   14525              :          reference variable.
   14526              : 
   14527              :          The solution is to pass back a cleanup expression
   14528              :          which the caller is responsible for attaching to
   14529              :          the statement tree.  */
   14530              :     }
   14531              :   else
   14532              :     {
   14533              :       /* Don't output reflection variables.  */
   14534          737 :       if (consteval_only_p (var))
   14535            6 :         DECL_EXTERNAL (var) = true;
   14536              : 
   14537          737 :       rest_of_decl_compilation (var, /*toplev=*/1, at_eof);
   14538          737 :       if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
   14539              :         {
   14540           43 :           if (CP_DECL_THREAD_LOCAL_P (var))
   14541           12 :             tls_aggregates = tree_cons (NULL_TREE, var,
   14542              :                                         tls_aggregates);
   14543              :           else
   14544           31 :             static_aggregates = tree_cons (NULL_TREE, var,
   14545              :                                            static_aggregates);
   14546              :         }
   14547              :       else
   14548              :         /* Check whether the dtor is callable.  */
   14549          694 :         cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14550              :     }
   14551              :   /* Avoid -Wunused-variable warning (c++/38958).  */
   14552         9388 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   14553         9388 :       && VAR_P (decl))
   14554         3508 :     TREE_USED (decl) = DECL_READ_P (decl) = true;
   14555              : 
   14556         9388 :   *initp = init;
   14557         9388 :   return var;
   14558              : }
   14559              : 
   14560              : /* Convert EXPR to the indicated reference TYPE, in a way suitable for
   14561              :    initializing a variable of that TYPE.  */
   14562              : 
   14563              : tree
   14564      6537391 : initialize_reference (tree type, tree expr,
   14565              :                       int flags, tsubst_flags_t complain)
   14566              : {
   14567      6537391 :   conversion *conv;
   14568      6537391 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14569              : 
   14570      6537391 :   if (type == error_mark_node || error_operand_p (expr))
   14571              :     return error_mark_node;
   14572              : 
   14573      6537314 :   conversion_obstack_sentinel cos;
   14574              : 
   14575      6537314 :   conv = reference_binding (type, TREE_TYPE (expr), expr, /*c_cast_p=*/false,
   14576              :                             flags, complain);
   14577              :   /* If this conversion failed, we're in C++20, and we have something like
   14578              :      A& a(b) where A is an aggregate, try again, this time as A& a{b}.  */
   14579      6537314 :   if ((!conv || conv->bad_p)
   14580          740 :       && (flags & LOOKUP_AGGREGATE_PAREN_INIT))
   14581              :     {
   14582            4 :       tree e = build_constructor_single (init_list_type_node, NULL_TREE, expr);
   14583            4 :       CONSTRUCTOR_IS_DIRECT_INIT (e) = true;
   14584            4 :       CONSTRUCTOR_IS_PAREN_INIT (e) = true;
   14585            4 :       conversion *c = reference_binding (type, TREE_TYPE (e), e,
   14586              :                                          /*c_cast_p=*/false, flags, complain);
   14587              :       /* If this worked, use it.  */
   14588            4 :       if (c && !c->bad_p)
   14589              :         expr = e, conv = c;
   14590              :     }
   14591      6537314 :   if (!conv || conv->bad_p)
   14592              :     {
   14593          737 :       if (complain & tf_error)
   14594              :         {
   14595          381 :           if (conv)
   14596          328 :             convert_like (conv, expr, complain);
   14597           53 :           else if (!CP_TYPE_CONST_P (TREE_TYPE (type))
   14598           21 :                    && !TYPE_REF_IS_RVALUE (type)
   14599           74 :                    && !lvalue_p (expr))
   14600            6 :             error_at (loc, "invalid initialization of non-const reference of "
   14601              :                       "type %qH from an rvalue of type %qI",
   14602            6 :                       type, TREE_TYPE (expr));
   14603              :           else
   14604           47 :             error_at (loc, "invalid initialization of reference of type "
   14605              :                       "%qH from expression of type %qI", type,
   14606           47 :                       TREE_TYPE (expr));
   14607              :         }
   14608          737 :       return error_mark_node;
   14609              :     }
   14610              : 
   14611      6536577 :   if (conv->kind == ck_ref_bind)
   14612              :     /* Perform the conversion.  */
   14613      6536574 :     expr = convert_like (conv, expr, complain);
   14614            3 :   else if (conv->kind == ck_ambig)
   14615              :     /* We gave an error in build_user_type_conversion_1.  */
   14616            3 :     expr = error_mark_node;
   14617              :   else
   14618            0 :     gcc_unreachable ();
   14619              : 
   14620              :   return expr;
   14621      6537314 : }
   14622              : 
   14623              : /* Return true if T is std::pair<const T&, const T&>.  */
   14624              : 
   14625              : static bool
   14626       620051 : std_pair_ref_ref_p (tree t)
   14627              : {
   14628              :   /* First, check if we have std::pair.  */
   14629        58738 :   if (!NON_UNION_CLASS_TYPE_P (t)
   14630       678329 :       || !CLASSTYPE_TEMPLATE_INSTANTIATION (t))
   14631              :     return false;
   14632        21223 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (t));
   14633        21223 :   if (!decl_in_std_namespace_p (tdecl))
   14634              :     return false;
   14635        15882 :   tree name = DECL_NAME (tdecl);
   14636        15882 :   if (!name || !id_equal (name, "pair"))
   14637              :     return false;
   14638              : 
   14639              :   /* Now see if the template arguments are both const T&.  */
   14640          361 :   tree args = CLASSTYPE_TI_ARGS (t);
   14641          361 :   if (TREE_VEC_LENGTH (args) != 2)
   14642              :     return false;
   14643          421 :   for (int i = 0; i < 2; i++)
   14644          451 :     if (!TYPE_REF_OBJ_P (TREE_VEC_ELT (args, i))
   14645          451 :         || !CP_TYPE_CONST_P (TREE_TYPE (TREE_VEC_ELT (args, i))))
   14646              :       return false;
   14647              : 
   14648              :   return true;
   14649              : }
   14650              : 
   14651              : /* Return true if a class T has a reference member.  */
   14652              : 
   14653              : static bool
   14654          216 : class_has_reference_member_p (tree t)
   14655              : {
   14656          216 :   for (tree fields = TYPE_FIELDS (t);
   14657         3380 :        fields;
   14658         3164 :        fields = DECL_CHAIN (fields))
   14659         3227 :     if (TREE_CODE (fields) == FIELD_DECL
   14660          196 :         && !DECL_ARTIFICIAL (fields)
   14661         3394 :         && TYPE_REF_P (TREE_TYPE (fields)))
   14662              :       return true;
   14663              :   return false;
   14664              : }
   14665              : 
   14666              : /* A wrapper for the above suitable as a callback for dfs_walk_once.  */
   14667              : 
   14668              : static tree
   14669          216 : class_has_reference_member_p_r (tree binfo, void *)
   14670              : {
   14671          216 :   return (class_has_reference_member_p (BINFO_TYPE (binfo))
   14672          216 :           ? integer_one_node : NULL_TREE);
   14673              : }
   14674              : 
   14675              : 
   14676              : /* Return true if T (either a class or a function) has been marked as
   14677              :    not-dangling.  */
   14678              : 
   14679              : static bool
   14680         1557 : no_dangling_p (tree t)
   14681              : {
   14682         1557 :   t = lookup_attribute ("no_dangling", TYPE_ATTRIBUTES (t));
   14683         1557 :   if (!t)
   14684              :     return false;
   14685              : 
   14686           75 :   t = TREE_VALUE (t);
   14687           75 :   if (!t)
   14688              :     return true;
   14689              : 
   14690           51 :   t = build_converted_constant_bool_expr (TREE_VALUE (t), tf_warning_or_error);
   14691           51 :   t = cxx_constant_value (t);
   14692           51 :   return t == boolean_true_node;
   14693              : }
   14694              : 
   14695              : /* Return true if a class CTYPE is either std::reference_wrapper or
   14696              :    std::ref_view, or a reference wrapper class.  We consider a class
   14697              :    a reference wrapper class if it has a reference member.  We no
   14698              :    longer check that it has a constructor taking the same reference type
   14699              :    since that approach still generated too many false positives.  */
   14700              : 
   14701              : static bool
   14702          447 : reference_like_class_p (tree ctype)
   14703              : {
   14704          447 :   if (!CLASS_TYPE_P (ctype))
   14705              :     return false;
   14706              : 
   14707          314 :   if (no_dangling_p (ctype))
   14708              :     return true;
   14709              : 
   14710              :   /* Also accept a std::pair<const T&, const T&>.  */
   14711          290 :   if (std_pair_ref_ref_p (ctype))
   14712              :     return true;
   14713              : 
   14714          275 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (ctype));
   14715          275 :   if (decl_in_std_namespace_p (tdecl))
   14716              :     {
   14717           38 :       tree name = DECL_NAME (tdecl);
   14718           38 :       if (name
   14719           38 :           && (id_equal (name, "reference_wrapper")
   14720           26 :               || id_equal (name, "span")
   14721           11 :               || id_equal (name, "ref_view")))
   14722              :         return true;
   14723              :     }
   14724              : 
   14725              :   /* Avoid warning if CTYPE looks like std::span: it has a T* member and
   14726              :      a trivial destructor.  For example,
   14727              : 
   14728              :       template<typename T>
   14729              :       struct Span {
   14730              :         T* data_;
   14731              :         std::size len_;
   14732              :       };
   14733              : 
   14734              :      is considered std::span-like.  */
   14735          248 :   if (NON_UNION_CLASS_TYPE_P (ctype) && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
   14736          228 :     for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
   14737          367 :          field; field = next_aggregate_field (DECL_CHAIN (field)))
   14738          199 :       if (TYPE_PTR_P (TREE_TYPE (field)))
   14739              :         return true;
   14740              : 
   14741              :   /* Some classes, such as std::tuple, have the reference member in its
   14742              :      (non-direct) base class.  */
   14743          188 :   if (dfs_walk_once (TYPE_BINFO (ctype), class_has_reference_member_p_r,
   14744              :                      nullptr, nullptr))
   14745           63 :     return true;
   14746              : 
   14747              :   return false;
   14748              : }
   14749              : 
   14750              : /* Helper for maybe_warn_dangling_reference to find a problematic temporary
   14751              :    in EXPR (as outlined in maybe_warn_dangling_reference), or NULL_TREE
   14752              :    if none found.  For instance:
   14753              : 
   14754              :      const S& s = S().self(); // S()
   14755              :      const int& r = (42, f(1)); // temporary for passing 1 to f
   14756              :      const int& t = b ? f(1) : f(2); // temporary for 1
   14757              :      const int& u = b ? f(1) : f(g); // temporary for 1
   14758              :      const int& v = b ? f(g) : f(2); // temporary for 2
   14759              :      const int& w = b ? f(g) : f(g); // NULL_TREE
   14760              :      const int& y = (f(1), 42); // NULL_TREE
   14761              :      const int& z = f(f(1)); // temporary for 1
   14762              : 
   14763              :    EXPR is the initializer.  If ARG_P is true, we're processing an argument
   14764              :    to a function; the point is to distinguish between, for example,
   14765              : 
   14766              :      Ref::inner (&TARGET_EXPR <D.2839, F::foo (fm)>)
   14767              : 
   14768              :    where we shouldn't warn, and
   14769              : 
   14770              :      Ref::inner (&TARGET_EXPR <D.2908, F::foo (&TARGET_EXPR <...>)>)
   14771              : 
   14772              :    where we should warn (Ref is a reference_like_class_p so we see through
   14773              :    it.  */
   14774              : 
   14775              : static tree
   14776         3715 : do_warn_dangling_reference (tree expr, bool arg_p)
   14777              : {
   14778         3881 :   STRIP_NOPS (expr);
   14779              : 
   14780         3881 :   if (arg_p && expr_represents_temporary_p (expr))
   14781              :     {
   14782              :       /* An attempt to reduce the number of -Wdangling-reference
   14783              :          false positives concerning reference wrappers (c++/107532).
   14784              :          When we encounter a reference_like_class_p, we don't warn
   14785              :          just yet; instead, we keep recursing to see if there were
   14786              :          any temporaries behind the reference-wrapper class.  */
   14787              :       tree e = expr;
   14788          355 :       while (handled_component_p (e))
   14789           15 :         e = TREE_OPERAND (e, 0);
   14790          340 :       tree type = TREE_TYPE (e);
   14791              :       /* If the temporary represents a lambda, we don't really know
   14792              :          what's going on here.  */
   14793          462 :       if (!reference_like_class_p (type) && !LAMBDA_TYPE_P (type))
   14794              :         return expr;
   14795              :     }
   14796              : 
   14797         3648 :   switch (TREE_CODE (expr))
   14798              :     {
   14799         1822 :     case CALL_EXPR:
   14800         1822 :       {
   14801         1822 :         tree fndecl = cp_get_callee_fndecl_nofold (expr);
   14802         1822 :         if (!fndecl
   14803         1822 :             || warning_suppressed_p (fndecl, OPT_Wdangling_reference)
   14804         2055 :             || !warning_enabled_at (DECL_SOURCE_LOCATION (fndecl),
   14805         1811 :                                     OPT_Wdangling_reference)
   14806              :             /* Don't emit a false positive for:
   14807              :                 std::vector<int> v = ...;
   14808              :                 std::vector<int>::const_iterator it = v.begin();
   14809              :                 const int &r = *it++;
   14810              :                because R refers to one of the int elements of V, not to
   14811              :                a temporary object.  Member operator* may return a reference
   14812              :                but probably not to one of its arguments.  */
   14813         1452 :             || (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   14814          852 :                 && DECL_OVERLOADED_OPERATOR_P (fndecl)
   14815          319 :                 && DECL_OVERLOADED_OPERATOR_IS (fndecl, INDIRECT_REF))
   14816         3065 :             || no_dangling_p (TREE_TYPE (fndecl)))
   14817              :           return NULL_TREE;
   14818              : 
   14819         1219 :         tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
   14820              :         /* If the function doesn't return a reference, don't warn.  This
   14821              :            can be e.g.
   14822              :              const int& z = std::min({1, 2, 3, 4, 5, 6, 7});
   14823              :            which doesn't dangle: std::min here returns an int.
   14824              : 
   14825              :            If the function returns a std::pair<const T&, const T&>, we
   14826              :            warn, to detect e.g.
   14827              :              std::pair<const int&, const int&> v = std::minmax(1, 2);
   14828              :            which also creates a dangling reference, because std::minmax
   14829              :            returns std::pair<const T&, const T&>(b, a).  */
   14830         1219 :         if (!(TYPE_REF_OBJ_P (rettype) || reference_like_class_p (rettype)))
   14831              :           return NULL_TREE;
   14832              : 
   14833              :         /* Here we're looking to see if any of the arguments is a temporary
   14834              :            initializing a reference parameter.  */
   14835         1647 :         for (int i = 0; i < call_expr_nargs (expr); ++i)
   14836              :           {
   14837         1240 :             tree arg = CALL_EXPR_ARG (expr, i);
   14838              :             /* Check that this argument initializes a reference, except for
   14839              :                the argument initializing the object of a member function.  */
   14840         1240 :             if (!DECL_IOBJ_MEMBER_FUNCTION_P (fndecl)
   14841         1240 :                 && !TYPE_REF_P (TREE_TYPE (arg)))
   14842          130 :               continue;
   14843         1110 :             STRIP_NOPS (arg);
   14844         1110 :             if (TREE_CODE (arg) == ADDR_EXPR)
   14845          725 :               arg = TREE_OPERAND (arg, 0);
   14846              :             /* Recurse to see if the argument is a temporary.  It could also
   14847              :                be another call taking a temporary and returning it and
   14848              :                initializing this reference parameter.  */
   14849         1110 :             if ((arg = do_warn_dangling_reference (arg, /*arg_p=*/true)))
   14850              :               {
   14851              :                 /* If we know the temporary could not bind to the return type,
   14852              :                    don't warn.  This is for scalars and empty classes only
   14853              :                    because for other classes we can't be sure we are not
   14854              :                    returning its sub-object.  */
   14855          278 :                 if ((SCALAR_TYPE_P (TREE_TYPE (arg))
   14856          152 :                      || is_empty_class (TREE_TYPE (arg)))
   14857          153 :                     && TYPE_REF_P (rettype)
   14858          138 :                     && !reference_related_p (TREE_TYPE (rettype),
   14859          138 :                                              TREE_TYPE (arg)))
   14860           21 :                   continue;
   14861              :                 return arg;
   14862              :               }
   14863              :           /* Don't warn about member functions like:
   14864              :               std::any a(...);
   14865              :               S& s = a.emplace<S>({0}, 0);
   14866              :              which construct a new object and return a reference to it, but
   14867              :              we still want to detect:
   14868              :                struct S { const S& self () { return *this; } };
   14869              :                const S& s = S().self();
   14870              :              where 's' dangles.  If we've gotten here, the object this function
   14871              :              is invoked on is not a temporary.  */
   14872          832 :             if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl))
   14873              :               break;
   14874              :           }
   14875              :         return NULL_TREE;
   14876              :       }
   14877           28 :     case COMPOUND_EXPR:
   14878           28 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 1), arg_p);
   14879           31 :     case COND_EXPR:
   14880           31 :       if (tree t = do_warn_dangling_reference (TREE_OPERAND (expr, 1), arg_p))
   14881              :         return t;
   14882           16 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 2), arg_p);
   14883            0 :     case PAREN_EXPR:
   14884            0 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 0), arg_p);
   14885          122 :     case TARGET_EXPR:
   14886          122 :       return do_warn_dangling_reference (TARGET_EXPR_INITIAL (expr), arg_p);
   14887              :     default:
   14888              :       return NULL_TREE;
   14889              :     }
   14890              : }
   14891              : 
   14892              : /* Implement -Wdangling-reference, to detect cases like
   14893              : 
   14894              :      int n = 1;
   14895              :      const int& r = std::max(n - 1, n + 1); // r is dangling
   14896              : 
   14897              :    This creates temporaries from the arguments, returns a reference to
   14898              :    one of the temporaries, but both temporaries are destroyed at the end
   14899              :    of the full expression.
   14900              : 
   14901              :    This works by checking if a reference is initialized with a function
   14902              :    that returns a reference, and at least one parameter of the function
   14903              :    is a reference that is bound to a temporary.  It assumes that such a
   14904              :    function actually returns one of its arguments.
   14905              : 
   14906              :    DECL is the reference being initialized, INIT is the initializer.  */
   14907              : 
   14908              : static void
   14909    110155191 : maybe_warn_dangling_reference (const_tree decl, tree init)
   14910              : {
   14911    110155191 :   if (!warn_dangling_reference)
   14912              :     return;
   14913       622320 :   tree type = TREE_TYPE (decl);
   14914              :   /* Only warn if what we're initializing has type T&& or const T&, or
   14915              :      std::pair<const T&, const T&>.  (A non-const lvalue reference can't
   14916              :      bind to a temporary.)  */
   14917      1242081 :   if (!((TYPE_REF_OBJ_P (type)
   14918         5444 :          && (TYPE_REF_IS_RVALUE (type)
   14919         5004 :              || CP_TYPE_CONST_P (TREE_TYPE (type))))
   14920       619761 :         || std_pair_ref_ref_p (type)))
   14921              :     return;
   14922              :   /* Don't suppress the diagnostic just because the call comes from
   14923              :      a system header.  If the DECL is not in a system header, or if
   14924              :      -Wsystem-headers was provided, warn.  */
   14925         2574 :   auto wsh
   14926         2574 :     = make_temp_override (global_dc->m_warn_system_headers,
   14927         2574 :                           (!in_system_header_at (DECL_SOURCE_LOCATION (decl))
   14928         2574 :                            || global_dc->m_warn_system_headers));
   14929         2574 :   if (tree call = do_warn_dangling_reference (init, /*arg_p=*/false))
   14930              :     {
   14931          212 :       auto_diagnostic_group d;
   14932          212 :       if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wdangling_reference,
   14933              :                       "possibly dangling reference to a temporary"))
   14934          212 :         inform (EXPR_LOCATION (call), "%qT temporary created here",
   14935          212 :                 TREE_TYPE (call));
   14936          212 :     }
   14937         2574 : }
   14938              : 
   14939              : /* If *P is an xvalue expression, prevent temporary lifetime extension if it
   14940              :    gets used to initialize a reference.  */
   14941              : 
   14942              : static tree
   14943           95 : prevent_lifetime_extension (tree t)
   14944              : {
   14945           95 :   tree *p = &t;
   14946           95 :   while (TREE_CODE (*p) == COMPOUND_EXPR)
   14947            0 :     p = &TREE_OPERAND (*p, 1);
   14948          104 :   while (handled_component_p (*p))
   14949            9 :     p = &TREE_OPERAND (*p, 0);
   14950              :   /* Change a TARGET_EXPR from prvalue to xvalue.  */
   14951           95 :   if (TREE_CODE (*p) == TARGET_EXPR)
   14952            3 :     *p = build2 (COMPOUND_EXPR, TREE_TYPE (*p), *p,
   14953            3 :                  move (TARGET_EXPR_SLOT (*p)));
   14954           95 :   return t;
   14955              : }
   14956              : 
   14957              : /* Subroutine of extend_ref_init_temps.  Possibly extend one initializer,
   14958              :    which is bound either to a reference or a std::initializer_list.  */
   14959              : 
   14960              : static tree
   14961       768461 : extend_ref_init_temps_1 (tree decl, tree init, vec<tree, va_gc> **cleanups,
   14962              :                          tree *cond_guard)
   14963              : {
   14964              :   /* CWG1299 (C++20): The temporary object to which the reference is bound or
   14965              :      the temporary object that is the complete object of a subobject to which
   14966              :      the reference is bound persists for the lifetime of the reference if the
   14967              :      glvalue to which the reference is bound was obtained through one of the
   14968              :      following:
   14969              :      - a temporary materialization conversion ([conv.rval]),
   14970              :      - ( expression ), where expression is one of these expressions,
   14971              :      - subscripting ([expr.sub]) of an array operand, where that operand is one
   14972              :        of these expressions,
   14973              :      - a class member access ([expr.ref]) using the . operator where the left
   14974              :        operand is one of these expressions and the right operand designates a
   14975              :        non-static data member of non-reference type,
   14976              :      - a pointer-to-member operation ([expr.mptr.oper]) using the .* operator
   14977              :        where the left operand is one of these expressions and the right operand
   14978              :        is a pointer to data member of non-reference type,
   14979              :      - a const_cast ([expr.const.cast]), static_cast ([expr.static.cast]),
   14980              :        dynamic_cast ([expr.dynamic.cast]), or reinterpret_cast
   14981              :        ([expr.reinterpret.cast]) converting, without a user-defined conversion,
   14982              :        a glvalue operand that is one of these expressions to a glvalue that
   14983              :        refers to the object designated by the operand, or to its complete
   14984              :        object or a subobject thereof,
   14985              :      - a conditional expression ([expr.cond]) that is a glvalue where the
   14986              :        second or third operand is one of these expressions, or
   14987              :      - a comma expression ([expr.comma]) that is a glvalue where the right
   14988              :        operand is one of these expressions.  */
   14989              : 
   14990              :   /* FIXME several cases are still handled wrong (101572, 81420).  */
   14991              : 
   14992       768461 :   tree sub = init;
   14993       768461 :   tree *p;
   14994       768461 :   STRIP_NOPS (sub);
   14995       768461 :   if (TREE_CODE (sub) == COMPOUND_EXPR)
   14996              :     {
   14997          242 :       TREE_OPERAND (sub, 1)
   14998          242 :         = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   14999              :                                    cond_guard);
   15000          242 :       return init;
   15001              :     }
   15002       768219 :   if (TREE_CODE (sub) == POINTER_PLUS_EXPR
   15003       768219 :       && TYPE_PTRDATAMEM_P (TREE_TYPE (tree_strip_nop_conversions
   15004              :                                        (TREE_OPERAND (sub, 1)))))
   15005              :     {
   15006              :       /* A pointer-to-member operation.  */
   15007            6 :       TREE_OPERAND (sub, 0)
   15008            6 :         = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 0), cleanups,
   15009              :                                    cond_guard);
   15010            6 :       return init;
   15011              :     }
   15012       768213 :   if (TREE_CODE (sub) == COND_EXPR)
   15013              :     {
   15014        23491 :       tree cur_cond_guard = NULL_TREE;
   15015        23491 :       if (TREE_OPERAND (sub, 1))
   15016        23491 :         TREE_OPERAND (sub, 1)
   15017        46982 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   15018              :                                      &cur_cond_guard);
   15019        23491 :       if (cur_cond_guard)
   15020              :         {
   15021            9 :           tree set = cp_build_modify_expr (UNKNOWN_LOCATION, cur_cond_guard,
   15022              :                                            NOP_EXPR, boolean_true_node,
   15023              :                                            tf_warning_or_error);
   15024            9 :           TREE_OPERAND (sub, 1)
   15025           18 :             = cp_build_compound_expr (set, TREE_OPERAND (sub, 1),
   15026              :                                       tf_warning_or_error);
   15027              :         }
   15028        23491 :       cur_cond_guard = NULL_TREE;
   15029        23491 :       if (TREE_OPERAND (sub, 2))
   15030        23491 :         TREE_OPERAND (sub, 2)
   15031        46982 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 2), cleanups,
   15032              :                                      &cur_cond_guard);
   15033        23491 :       if (cur_cond_guard)
   15034              :         {
   15035           12 :           tree set = cp_build_modify_expr (UNKNOWN_LOCATION, cur_cond_guard,
   15036              :                                            NOP_EXPR, boolean_true_node,
   15037              :                                            tf_warning_or_error);
   15038           12 :           TREE_OPERAND (sub, 2)
   15039           24 :             = cp_build_compound_expr (set, TREE_OPERAND (sub, 2),
   15040              :                                       tf_warning_or_error);
   15041              :         }
   15042        23491 :       return init;
   15043              :     }
   15044       744722 :   if (TREE_CODE (sub) != ADDR_EXPR)
   15045              :     return init;
   15046              :   /* Deal with binding to a subobject.  */
   15047       265853 :   for (p = &TREE_OPERAND (sub, 0);
   15048       279427 :        TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   15049        13574 :     p = &TREE_OPERAND (*p, 0);
   15050       265853 :   if (TREE_CODE (*p) == TARGET_EXPR)
   15051              :     {
   15052         7196 :       tree subinit = NULL_TREE;
   15053         7196 :       *p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit,
   15054              :                                      cond_guard, nullptr);
   15055         7196 :       recompute_tree_invariant_for_addr_expr (sub);
   15056         7196 :       if (init != sub)
   15057         7178 :         init = fold_convert (TREE_TYPE (init), sub);
   15058         7196 :       if (subinit)
   15059         6061 :         init = build2 (COMPOUND_EXPR, TREE_TYPE (init), subinit, init);
   15060              :     }
   15061              :   return init;
   15062              : }
   15063              : 
   15064              : /* Data for extend_temps_r, mostly matching the parameters of
   15065              :    extend_ref_init_temps.  */
   15066              : 
   15067              : struct extend_temps_data
   15068              : {
   15069              :   tree decl;
   15070              :   tree init;
   15071              :   vec<tree, va_gc> **cleanups;
   15072              :   tree* cond_guard;
   15073              :   hash_set<tree> *pset;            // For avoiding redundant walk_tree.
   15074              :   hash_map<tree, tree> *var_map; // For remapping extended temps.
   15075              : };
   15076              : 
   15077              : /* Tree walk function for extend_all_temps.  Generally parallel to
   15078              :    extend_ref_init_temps_1, but adapted for walk_tree.  */
   15079              : 
   15080              : tree
   15081        99492 : extend_temps_r (tree *tp, int *walk_subtrees, void *data)
   15082              : {
   15083        99492 :   extend_temps_data *d = (extend_temps_data *)data;
   15084              : 
   15085        99492 :   if (TREE_CODE (*tp) == VAR_DECL)
   15086              :     {
   15087        11592 :       if (tree *r = d->var_map->get (*tp))
   15088            0 :         *tp = *r;
   15089              :       return NULL_TREE;
   15090              :     }
   15091              : 
   15092        87881 :   if (TYPE_P (*tp) || TREE_CODE (*tp) == CLEANUP_POINT_EXPR
   15093       175780 :       || d->pset->add (*tp))
   15094              :     {
   15095         4972 :       *walk_subtrees = 0;
   15096         4972 :       return NULL_TREE;
   15097              :     }
   15098              : 
   15099        82928 :   if (TREE_CODE (*tp) == COND_EXPR)
   15100              :     {
   15101            8 :       cp_walk_tree (&TREE_OPERAND (*tp, 0), extend_temps_r, d, nullptr);
   15102              : 
   15103           24 :       auto walk_arm = [d](tree &op)
   15104              :       {
   15105           16 :         tree cur_cond_guard = NULL_TREE;
   15106           16 :         auto ov = make_temp_override (d->cond_guard, &cur_cond_guard);
   15107           16 :         cp_walk_tree (&op, extend_temps_r, d, nullptr);
   15108           16 :         if (cur_cond_guard)
   15109              :           {
   15110            2 :             tree set = build2 (MODIFY_EXPR, boolean_type_node,
   15111              :                                cur_cond_guard, boolean_true_node);
   15112            2 :             op = cp_build_compound_expr (set, op, tf_none);
   15113              :           }
   15114           24 :       };
   15115            8 :       walk_arm (TREE_OPERAND (*tp, 1));
   15116            8 :       walk_arm (TREE_OPERAND (*tp, 2));
   15117              : 
   15118            8 :       *walk_subtrees = 0;
   15119            8 :       return NULL_TREE;
   15120              :     }
   15121              : 
   15122        82920 :   tree *p = tp;
   15123              : 
   15124        82920 :   if (TREE_CODE (*tp) == ADDR_EXPR)
   15125        18704 :     for (p = &TREE_OPERAND (*tp, 0);
   15126        20179 :          TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   15127         1475 :       p = &TREE_OPERAND (*p, 0);
   15128              : 
   15129        82920 :   if (TREE_CODE (*p) == TARGET_EXPR
   15130              :       /* An eliding TARGET_EXPR isn't a temporary at all.  */
   15131         3602 :       && !TARGET_EXPR_ELIDING_P (*p)
   15132              :       /* A TARGET_EXPR with TARGET_EXPR_INTERNAL_P is an artificial variable
   15133              :          used during initialization that need not be extended.  */
   15134        85448 :       && !TARGET_EXPR_INTERNAL_P (*p))
   15135              :     {
   15136              :       /* A CLEANUP_EH_ONLY expr should also have TARGET_EXPR_INTERNAL_P.  */
   15137         2192 :       gcc_checking_assert (!CLEANUP_EH_ONLY (*p));
   15138              : 
   15139         2192 :       tree subinit = NULL_TREE;
   15140         2192 :       tree slot = TARGET_EXPR_SLOT (*p);
   15141         2192 :       *p = set_up_extended_ref_temp (d->decl, *p, d->cleanups, &subinit,
   15142              :                                      d->cond_guard, d);
   15143         2192 :       if (TREE_CODE (*tp) == ADDR_EXPR)
   15144         2178 :         recompute_tree_invariant_for_addr_expr (*tp);
   15145         2192 :       if (subinit)
   15146         2044 :         *tp = cp_build_compound_expr (subinit, *tp, tf_none);
   15147         2192 :       d->var_map->put (slot, *p);
   15148              :     }
   15149              : 
   15150              :   return NULL_TREE;
   15151              : }
   15152              : 
   15153              : /* Extend all the temporaries in a for-range-initializer.  */
   15154              : 
   15155              : static tree
   15156        20123 : extend_all_temps (tree decl, tree init, vec<tree, va_gc> **cleanups)
   15157              : {
   15158        20123 :   hash_set<tree> pset;
   15159        20123 :   hash_map<tree, tree> map;
   15160        20123 :   gcc_assert (!TREE_STATIC (decl));
   15161        20123 :   extend_temps_data d = { decl, init, cleanups, nullptr, &pset, &map };
   15162        20123 :   cp_walk_tree (&init, extend_temps_r, &d, nullptr);
   15163        20123 :   return init;
   15164        20123 : }
   15165              : 
   15166              : /* INIT is part of the initializer for DECL.  If there are any
   15167              :    reference or initializer lists being initialized, extend their
   15168              :    lifetime to match that of DECL.  */
   15169              : 
   15170              : tree
   15171    112676696 : extend_ref_init_temps (tree decl, tree init, vec<tree, va_gc> **cleanups,
   15172              :                        tree *cond_guard)
   15173              : {
   15174    112676696 :   tree type = TREE_TYPE (init);
   15175    112676696 :   if (processing_template_decl)
   15176              :     return init;
   15177              : 
   15178              :   /* P2718R0 - in C++23 for-range-initializer, extend all temps.  */
   15179    110175314 :   if (DECL_NAME (decl) == for_range__identifier
   15180        95136 :       && flag_range_for_ext_temps
   15181              :       /* Iterating expansion statement decl is static right now, but that
   15182              :          could change depending on CWG3044 and CWG3043.  */
   15183    110195495 :       && !TREE_STATIC (decl))
   15184              :     {
   15185        20123 :       gcc_checking_assert (!cond_guard);
   15186        20123 :       return extend_all_temps (decl, init, cleanups);
   15187              :     }
   15188              : 
   15189    110155191 :   maybe_warn_dangling_reference (decl, init);
   15190              : 
   15191    110155191 :   if (TYPE_REF_P (type))
   15192       720572 :     init = extend_ref_init_temps_1 (decl, init, cleanups, cond_guard);
   15193              :   else
   15194              :     {
   15195    109434619 :       tree ctor = init;
   15196    109434619 :       if (TREE_CODE (ctor) == TARGET_EXPR)
   15197      1574123 :         ctor = TARGET_EXPR_INITIAL (ctor);
   15198    109434619 :       if (TREE_CODE (ctor) == CONSTRUCTOR)
   15199              :         {
   15200              :           /* [dcl.init] When initializing an aggregate from a parenthesized list
   15201              :              of values... a temporary object bound to a reference does not have
   15202              :              its lifetime extended.  */
   15203      5741512 :           if (CONSTRUCTOR_IS_PAREN_INIT (ctor))
   15204              :             return init;
   15205              : 
   15206      5741018 :           if (is_std_init_list (type))
   15207              :             {
   15208              :               /* The temporary array underlying a std::initializer_list
   15209              :                  is handled like a reference temporary.  */
   15210          659 :               tree array = CONSTRUCTOR_ELT (ctor, 0)->value;
   15211          659 :               array = extend_ref_init_temps_1 (decl, array, cleanups,
   15212              :                                                cond_guard);
   15213          659 :               CONSTRUCTOR_ELT (ctor, 0)->value = array;
   15214              :             }
   15215              :           else
   15216              :             {
   15217      5740359 :               unsigned i;
   15218      5740359 :               constructor_elt *p;
   15219      5740359 :               vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (ctor);
   15220     63706314 :               FOR_EACH_VEC_SAFE_ELT (elts, i, p)
   15221     57965955 :                 p->value = extend_ref_init_temps (decl, p->value, cleanups,
   15222              :                                                   cond_guard);
   15223              :             }
   15224      5741018 :           recompute_constructor_flags (ctor);
   15225      5741018 :           if (decl_maybe_constant_var_p (decl) && TREE_CONSTANT (ctor))
   15226      3193558 :             DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
   15227              :         }
   15228              :     }
   15229              : 
   15230              :   return init;
   15231              : }
   15232              : 
   15233              : /* Returns true iff an initializer for TYPE could contain temporaries that
   15234              :    need to be extended because they are bound to references or
   15235              :    std::initializer_list.  */
   15236              : 
   15237              : bool
   15238            0 : type_has_extended_temps (tree type)
   15239              : {
   15240            0 :   type = strip_array_types (type);
   15241            0 :   if (TYPE_REF_P (type))
   15242              :     return true;
   15243            0 :   if (CLASS_TYPE_P (type))
   15244              :     {
   15245            0 :       if (is_std_init_list (type))
   15246              :         return true;
   15247            0 :       for (tree f = next_aggregate_field (TYPE_FIELDS (type));
   15248            0 :            f; f = next_aggregate_field (DECL_CHAIN (f)))
   15249            0 :         if (type_has_extended_temps (TREE_TYPE (f)))
   15250              :           return true;
   15251              :     }
   15252              :   return false;
   15253              : }
   15254              : 
   15255              : /* Returns true iff TYPE is some variant of std::initializer_list.  */
   15256              : 
   15257              : bool
   15258    184340635 : is_std_init_list (tree type)
   15259              : {
   15260    184340635 :   if (!TYPE_P (type))
   15261              :     return false;
   15262    184340612 :   if (cxx_dialect == cxx98)
   15263              :     return false;
   15264              :   /* Look through typedefs.  */
   15265    183923591 :   type = TYPE_MAIN_VARIANT (type);
   15266    147388688 :   return (CLASS_TYPE_P (type)
   15267    147241367 :           && CP_TYPE_CONTEXT (type) == std_node
   15268    266009334 :           && init_list_identifier == DECL_NAME (TYPE_NAME (type)));
   15269              : }
   15270              : 
   15271              : /* Returns true iff DECL is a list constructor: i.e. a constructor which
   15272              :    will accept an argument list of a single std::initializer_list<T>.  */
   15273              : 
   15274              : bool
   15275    160001673 : is_list_ctor (tree decl)
   15276              : {
   15277    160001673 :   tree args = FUNCTION_FIRST_USER_PARMTYPE (decl);
   15278    160001673 :   tree arg;
   15279              : 
   15280    160001673 :   if (!args || args == void_list_node)
   15281              :     return false;
   15282              : 
   15283    128796980 :   arg = non_reference (TREE_VALUE (args));
   15284    128796980 :   if (!is_std_init_list (arg))
   15285              :     return false;
   15286              : 
   15287      2315540 :   args = TREE_CHAIN (args);
   15288              : 
   15289      3940901 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   15290              :     /* There are more non-defaulted parms.  */
   15291       637101 :     return false;
   15292              : 
   15293              :   return true;
   15294              : }
   15295              : 
   15296              : /* We know that can_convert_arg_bad already said "no" when trying to convert
   15297              :    FROM to TO with ARG and FLAGS.  Try to figure out if it was because
   15298              :    an explicit conversion function was skipped when looking for a way to
   15299              :    perform the conversion.  At this point we've already printed an error.  */
   15300              : 
   15301              : void
   15302         2194 : maybe_show_nonconverting_candidate (tree to, tree from, tree arg, int flags)
   15303              : {
   15304         2194 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   15305          311 :     return;
   15306              : 
   15307         1883 :   conversion_obstack_sentinel cos;
   15308         1883 :   conversion *c = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   15309              :                                        flags & ~LOOKUP_ONLYCONVERTING, tf_none);
   15310         1883 :   if (c && !c->bad_p && c->user_conv_p)
   15311              :     /* Ay, the conversion would have worked in direct-init context.  */
   15312          859 :     for (; c; c = next_conversion (c))
   15313          575 :       if (c->kind == ck_user
   15314          281 :           && DECL_P (c->cand->fn)
   15315          856 :           && DECL_NONCONVERTING_P (c->cand->fn))
   15316          277 :         inform (DECL_SOURCE_LOCATION (c->cand->fn), "explicit conversion "
   15317              :                 "function was not considered");
   15318         1883 : }
   15319              : 
   15320              : /* We're converting EXPR to TYPE.  If that conversion involves a conversion
   15321              :    function and we're binding EXPR to a reference parameter of that function,
   15322              :    return true.  */
   15323              : 
   15324              : bool
   15325          171 : conv_binds_to_reference_parm_p (tree type, tree expr)
   15326              : {
   15327          171 :   conversion_obstack_sentinel cos;
   15328          171 :   conversion *c = implicit_conversion (type, TREE_TYPE (expr), expr,
   15329              :                                        /*c_cast_p=*/false, LOOKUP_NORMAL,
   15330              :                                        tf_none);
   15331          171 :   if (c && !c->bad_p && c->user_conv_p)
   15332          117 :     for (; c; c = next_conversion (c))
   15333           81 :       if (c->kind == ck_user)
   15334          244 :         for (z_candidate *cand = c->cand; cand; cand = cand->next)
   15335          208 :           if (cand->viable == 1)
   15336           81 :             for (size_t i = 0; i < cand->num_convs; ++i)
   15337           45 :               if (cand->convs[i]->kind == ck_ref_bind
   15338           45 :                   && conv_get_original_expr (cand->convs[i]) == expr)
   15339              :                 return true;
   15340              : 
   15341              :   return false;
   15342          171 : }
   15343              : 
   15344              : #include "gt-cp-call.h"
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.