LCOV - code coverage report
Current view: top level - gcc/cp - call.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.3 % 6389 6150
Test Date: 2026-03-28 14:25:54 Functions: 100.0 % 226 226
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 "stringpool.h"
      43              : #include "attribs.h"
      44              : #include "decl.h"
      45              : #include "c-family/c-type-mismatch.h"
      46              : #include "tristate.h"
      47              : #include "tree-pretty-print-markup.h"
      48              : #include "contracts.h" // maybe_contract_wrap_call
      49              : 
      50              : /* The various kinds of conversion.  */
      51              : 
      52              : enum conversion_kind {
      53              :   ck_identity,
      54              :   ck_lvalue,
      55              :   ck_fnptr,
      56              :   ck_qual,
      57              :   ck_std,
      58              :   ck_ptr,
      59              :   ck_pmem,
      60              :   ck_base,
      61              :   ck_ref_bind,
      62              :   ck_user,
      63              :   ck_ambig,
      64              :   ck_list,
      65              :   ck_aggr,
      66              :   ck_rvalue,
      67              :   /* When LOOKUP_SHORTCUT_BAD_CONVS is set, we may return a conversion of
      68              :      this kind whenever we know the true conversion is either bad or outright
      69              :      invalid, but we don't want to attempt to compute the bad conversion (for
      70              :      sake of avoiding unnecessary instantiation).  bad_p should always be set
      71              :      for these.  */
      72              :   ck_deferred_bad,
      73              : };
      74              : 
      75              : /* The rank of the conversion.  Order of the enumerals matters; better
      76              :    conversions should come earlier in the list.  */
      77              : 
      78              : enum conversion_rank {
      79              :   cr_identity,
      80              :   cr_exact,
      81              :   cr_promotion,
      82              :   cr_std,
      83              :   cr_pbool,
      84              :   cr_user,
      85              :   cr_ellipsis,
      86              :   cr_bad
      87              : };
      88              : 
      89              : /* An implicit conversion sequence, in the sense of [over.best.ics].
      90              :    The first conversion to be performed is at the end of the chain.
      91              :    That conversion is always a cr_identity conversion.  */
      92              : 
      93              : struct conversion {
      94              :   /* The kind of conversion represented by this step.  */
      95              :   conversion_kind kind;
      96              :   /* The rank of this conversion.  */
      97              :   conversion_rank rank;
      98              :   BOOL_BITFIELD user_conv_p : 1;
      99              :   BOOL_BITFIELD ellipsis_p : 1;
     100              :   BOOL_BITFIELD this_p : 1;
     101              :   /* True if this conversion would be permitted with a bending of
     102              :      language standards, e.g. disregarding pointer qualifiers or
     103              :      converting integers to pointers.  */
     104              :   BOOL_BITFIELD bad_p : 1;
     105              :   /* If KIND is ck_ref_bind or ck_base, true to indicate that a
     106              :      temporary should be created to hold the result of the
     107              :      conversion.  If KIND is ck_ambig or ck_user, true means force
     108              :      copy-initialization.  */
     109              :   BOOL_BITFIELD need_temporary_p : 1;
     110              :   /* If KIND is ck_ptr or ck_pmem, true to indicate that a conversion
     111              :      from a pointer-to-derived to pointer-to-base is being performed.  */
     112              :   BOOL_BITFIELD base_p : 1;
     113              :   /* If KIND is ck_ref_bind, true when either an lvalue reference is
     114              :      being bound to an lvalue expression or an rvalue reference is
     115              :      being bound to an rvalue expression.  If KIND is ck_rvalue or ck_base,
     116              :      true when we are treating an lvalue as an rvalue (12.8p33).  If
     117              :      ck_identity, we will be binding a reference directly or decaying to
     118              :      a pointer.  */
     119              :   BOOL_BITFIELD rvaluedness_matches_p: 1;
     120              :   BOOL_BITFIELD check_narrowing: 1;
     121              :   /* Whether check_narrowing should only check TREE_CONSTANTs; used
     122              :      in build_converted_constant_expr.  */
     123              :   BOOL_BITFIELD check_narrowing_const_only: 1;
     124              :   /* True if this conversion is taking place in a copy-initialization context
     125              :      and we should only consider converting constructors.  Only set in
     126              :      ck_base and ck_rvalue.  */
     127              :   BOOL_BITFIELD copy_init_p : 1;
     128              :   /* The type of the expression resulting from the conversion.  */
     129              :   tree type;
     130              :   union {
     131              :     /* The next conversion in the chain.  Since the conversions are
     132              :        arranged from outermost to innermost, the NEXT conversion will
     133              :        actually be performed before this conversion.  This variant is
     134              :        used only when KIND is neither ck_identity, ck_aggr, ck_ambig nor
     135              :        ck_list.  Please use the next_conversion function instead
     136              :        of using this field directly.  */
     137              :     conversion *next;
     138              :     /* The expression at the beginning of the conversion chain.  This
     139              :        variant is used only if KIND is ck_identity, ck_aggr, or ck_ambig.
     140              :        You can use conv_get_original_expr to get this expression.  */
     141              :     tree expr;
     142              :     /* The array of conversions for an initializer_list, so this
     143              :        variant is used only when KIN D is ck_list.  */
     144              :     conversion **list;
     145              :   } u;
     146              :   /* The function candidate corresponding to this conversion
     147              :      sequence.  This field is only used if KIND is ck_user.  */
     148              :   struct z_candidate *cand;
     149              : };
     150              : 
     151              : #define CONVERSION_RANK(NODE)                   \
     152              :   ((NODE)->bad_p ? cr_bad                    \
     153              :    : (NODE)->ellipsis_p ? cr_ellipsis                \
     154              :    : (NODE)->user_conv_p ? cr_user           \
     155              :    : (NODE)->rank)
     156              : 
     157              : #define BAD_CONVERSION_RANK(NODE)               \
     158              :   ((NODE)->ellipsis_p ? cr_ellipsis          \
     159              :    : (NODE)->user_conv_p ? cr_user           \
     160              :    : (NODE)->rank)
     161              : 
     162              : static struct obstack conversion_obstack;
     163              : static bool conversion_obstack_initialized;
     164              : struct rejection_reason;
     165              : 
     166              : static struct z_candidate * tourney (struct z_candidate *, tsubst_flags_t);
     167              : static int equal_functions (tree, tree);
     168              : static int joust (struct z_candidate *, struct z_candidate *, bool,
     169              :                   tsubst_flags_t);
     170              : static int compare_ics (conversion *, conversion *);
     171              : static void maybe_warn_class_memaccess (location_t, tree,
     172              :                                         const vec<tree, va_gc> *);
     173              : static tree build_over_call (struct z_candidate *, int, tsubst_flags_t);
     174              : static tree convert_like (conversion *, tree, tsubst_flags_t);
     175              : static tree convert_like_with_context (conversion *, tree, tree, int,
     176              :                                        tsubst_flags_t);
     177              : static void op_error (const op_location_t &, enum tree_code, enum tree_code,
     178              :                       tree, tree, tree, bool);
     179              : static struct z_candidate *build_user_type_conversion_1 (tree, tree, int,
     180              :                                                          tsubst_flags_t);
     181              : static void print_z_candidate (location_t, const char *, struct z_candidate *);
     182              : static void print_z_candidates (location_t, struct z_candidate *,
     183              :                                 tristate = tristate::unknown ());
     184              : static tree build_this (tree);
     185              : static struct z_candidate *splice_viable (struct z_candidate *, bool, bool *);
     186              : static bool any_strictly_viable (struct z_candidate *);
     187              : static struct z_candidate *add_template_candidate
     188              :         (struct z_candidate **, tree, tree, tree, tree, const vec<tree, va_gc> *,
     189              :          tree, tree, tree, int, unification_kind_t, bool, tsubst_flags_t);
     190              : static struct z_candidate *add_template_candidate_real
     191              :         (struct z_candidate **, tree, tree, tree, tree, const vec<tree, va_gc> *,
     192              :          tree, tree, tree, int, tree, unification_kind_t, bool, tsubst_flags_t);
     193              : static bool is_complete (tree);
     194              : static struct z_candidate *add_conv_candidate
     195              :         (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, tree,
     196              :          tree, tsubst_flags_t);
     197              : static struct z_candidate *add_function_candidate
     198              :         (struct z_candidate **, tree, tree, tree, const vec<tree, va_gc> *, tree,
     199              :          tree, int, conversion**, bool, tsubst_flags_t);
     200              : static conversion *implicit_conversion (tree, tree, tree, bool, int,
     201              :                                         tsubst_flags_t);
     202              : static conversion *reference_binding (tree, tree, tree, bool, int,
     203              :                                       tsubst_flags_t);
     204              : static conversion *build_conv (conversion_kind, tree, conversion *);
     205              : static conversion *build_list_conv (tree, tree, int, tsubst_flags_t);
     206              : static conversion *next_conversion (conversion *);
     207              : static bool is_subseq (conversion *, conversion *);
     208              : static conversion *maybe_handle_ref_bind (conversion **);
     209              : static void maybe_handle_implicit_object (conversion **);
     210              : static struct z_candidate *add_candidate
     211              :         (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, size_t,
     212              :          conversion **, tree, tree, int, struct rejection_reason *, int);
     213              : static tree source_type (conversion *);
     214              : static void add_warning (struct z_candidate *, struct z_candidate *);
     215              : static conversion *direct_reference_binding (tree, conversion *);
     216              : static bool promoted_arithmetic_type_p (tree);
     217              : static conversion *conditional_conversion (tree, tree, tsubst_flags_t);
     218              : static char *name_as_c_string (tree, tree, bool *);
     219              : static tree prep_operand (tree);
     220              : static void add_candidates (tree, tree, const vec<tree, va_gc> *, tree, tree,
     221              :                             bool, tree, tree, int, struct z_candidate **,
     222              :                             tsubst_flags_t);
     223              : static conversion *merge_conversion_sequences (conversion *, conversion *);
     224              : static tree build_temp (tree, tree, int, enum diagnostics::kind *,
     225              :                         tsubst_flags_t);
     226              : static conversion *build_identity_conv (tree, tree);
     227              : static inline bool conv_binds_to_array_of_unknown_bound (conversion *);
     228              : static bool conv_is_prvalue (conversion *);
     229              : static tree prevent_lifetime_extension (tree);
     230              : 
     231              : /* Returns nonzero iff the destructor name specified in NAME matches BASETYPE.
     232              :    NAME can take many forms...  */
     233              : 
     234              : bool
     235      3004799 : check_dtor_name (tree basetype, tree name)
     236              : {
     237              :   /* Just accept something we've already complained about.  */
     238      3004799 :   if (name == error_mark_node)
     239              :     return true;
     240              : 
     241      3004799 :   if (TREE_CODE (name) == TYPE_DECL)
     242           84 :     name = TREE_TYPE (name);
     243      3004715 :   else if (TYPE_P (name))
     244              :     /* OK */;
     245           26 :   else if (identifier_p (name))
     246              :     {
     247           26 :       if ((MAYBE_CLASS_TYPE_P (basetype)
     248            0 :            || TREE_CODE (basetype) == ENUMERAL_TYPE)
     249           26 :           && name == constructor_name (basetype))
     250              :         return true;
     251              : 
     252              :       /* Otherwise lookup the name, it could be an unrelated typedef
     253              :          of the correct type.  */
     254            6 :       name = lookup_name (name, LOOK_want::TYPE);
     255            6 :       if (!name)
     256              :         return false;
     257            3 :       name = TREE_TYPE (name);
     258            3 :       if (name == error_mark_node)
     259              :         return false;
     260              :     }
     261              :   else
     262              :     {
     263              :       /* In the case of:
     264              : 
     265              :          template <class T> struct S { ~S(); };
     266              :          int i;
     267              :          i.~S();
     268              : 
     269              :          NAME will be a class template.  */
     270            0 :       gcc_assert (DECL_CLASS_TEMPLATE_P (name));
     271              :       return false;
     272              :     }
     273              : 
     274      3004773 :   return same_type_p (TYPE_MAIN_VARIANT (basetype), TYPE_MAIN_VARIANT (name));
     275              : }
     276              : 
     277              : /* We want the address of a function or method.  We avoid creating a
     278              :    pointer-to-member function.  */
     279              : 
     280              : tree
     281    463349926 : build_addr_func (tree function, tsubst_flags_t complain)
     282              : {
     283    463349926 :   tree type = TREE_TYPE (function);
     284              : 
     285              :   /* We have to do these by hand to avoid real pointer to member
     286              :      functions.  */
     287    463349926 :   if (TREE_CODE (type) == METHOD_TYPE)
     288              :     {
     289     75143856 :       if (TREE_CODE (function) == OFFSET_REF)
     290              :         {
     291           71 :           tree object = build_address (TREE_OPERAND (function, 0));
     292           71 :           return get_member_function_from_ptrfunc (&object,
     293           71 :                                                    TREE_OPERAND (function, 1),
     294              :                                                    complain);
     295              :         }
     296     75143785 :       function = build_address (function);
     297              :     }
     298    388206070 :   else if (TREE_CODE (function) == FUNCTION_DECL
     299    548921796 :            && DECL_IMMEDIATE_FUNCTION_P (function))
     300      2483382 :     function = build_address (function);
     301              :   else
     302    385722688 :     function = decay_conversion (function, complain, /*reject_builtin=*/false);
     303              : 
     304              :   return function;
     305              : }
     306              : 
     307              : /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
     308              :    POINTER_TYPE to those.  Note, pointer to member function types
     309              :    (TYPE_PTRMEMFUNC_P) must be handled by our callers.  There are
     310              :    two variants.  build_call_a is the primitive taking an array of
     311              :    arguments, while build_call_n is a wrapper that handles varargs.  */
     312              : 
     313              : tree
     314       158370 : build_call_n (tree function, int n, ...)
     315              : {
     316       158370 :   if (n == 0)
     317            0 :     return build_call_a (function, 0, NULL);
     318              :   else
     319              :     {
     320       158370 :       tree *argarray = XALLOCAVEC (tree, n);
     321       158370 :       va_list ap;
     322       158370 :       int i;
     323              : 
     324       158370 :       va_start (ap, n);
     325       317466 :       for (i = 0; i < n; i++)
     326       159096 :         argarray[i] = va_arg (ap, tree);
     327       158370 :       va_end (ap);
     328       158370 :       return build_call_a (function, n, argarray);
     329              :     }
     330              : }
     331              : 
     332              : /* Update various flags in cfun and the call itself based on what is being
     333              :    called.  Split out of build_call_a so that bot_manip can use it too.  */
     334              : 
     335              : void
     336    226261008 : set_flags_from_callee (tree call)
     337              : {
     338              :   /* Handle both CALL_EXPRs and AGGR_INIT_EXPRs.  */
     339    226261008 :   tree decl = cp_get_callee_fndecl_nofold (call);
     340              : 
     341              :   /* We check both the decl and the type; a function may be known not to
     342              :      throw without being declared throw().  */
     343    226261008 :   bool nothrow = decl && TREE_NOTHROW (decl);
     344    226261008 :   tree callee = cp_get_callee (call);
     345    226261008 :   if (callee)
     346    226261000 :     nothrow |= TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (callee)));
     347            8 :   else if (TREE_CODE (call) == CALL_EXPR
     348            8 :            && internal_fn_flags (CALL_EXPR_IFN (call)) & ECF_NOTHROW)
     349              :     nothrow = true;
     350              : 
     351    226261008 :   if (cfun && cp_function_chain && !cp_unevaluated_operand)
     352              :     {
     353    122563330 :       if (!nothrow && at_function_scope_p ())
     354     34148607 :         cp_function_chain->can_throw = 1;
     355              : 
     356    122563330 :       if (decl && TREE_THIS_VOLATILE (decl))
     357      3777090 :         current_function_returns_abnormally = 1;
     358              :     }
     359              : 
     360    226261008 :   TREE_NOTHROW (call) = nothrow;
     361    226261008 : }
     362              : 
     363              : tree
     364    222018215 : build_call_a (tree function, int n, tree *argarray)
     365              : {
     366    222018215 :   tree decl;
     367    222018215 :   tree result_type;
     368    222018215 :   tree fntype;
     369    222018215 :   int i;
     370              : 
     371    222018215 :   function = build_addr_func (function, tf_warning_or_error);
     372              : 
     373    222018215 :   gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
     374    222018215 :   fntype = TREE_TYPE (TREE_TYPE (function));
     375    222018215 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     376    222018215 :   result_type = TREE_TYPE (fntype);
     377              :   /* An rvalue has no cv-qualifiers.  */
     378    222018215 :   if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
     379    122829363 :     result_type = cv_unqualified (result_type);
     380              : 
     381    222018215 :   function = build_call_array_loc (input_location,
     382              :                                    result_type, function, n, argarray);
     383    222018215 :   set_flags_from_callee (function);
     384              : 
     385    222018215 :   decl = get_callee_fndecl (function);
     386              : 
     387    222018215 :   if (decl && !TREE_USED (decl))
     388              :     {
     389              :       /* We invoke build_call directly for several library
     390              :          functions.  These may have been declared normally if
     391              :          we're building libgcc, so we can't just check
     392              :          DECL_ARTIFICIAL.  */
     393       205450 :       gcc_assert (DECL_ARTIFICIAL (decl)
     394              :                   || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
     395              :                                "__", 2));
     396       205450 :       mark_used (decl);
     397              :     }
     398              : 
     399    222018215 :   require_complete_eh_spec_types (fntype, decl);
     400              : 
     401    642748416 :   TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl));
     402              : 
     403              :   /* Don't pass empty class objects by value.  This is useful
     404              :      for tags in STL, which are used to control overload resolution.
     405              :      We don't need to handle other cases of copying empty classes.  */
     406    222018215 :   if (!decl || !fndecl_built_in_p (decl))
     407    448673562 :     for (i = 0; i < n; i++)
     408              :       {
     409    235248895 :         tree arg = CALL_EXPR_ARG (function, i);
     410    235248895 :         if (is_empty_class (TREE_TYPE (arg))
     411    235248895 :             && simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
     412              :           {
     413      5828588 :             while (TREE_CODE (arg) == TARGET_EXPR)
     414              :               /* We're disconnecting the initializer from its target,
     415              :                  don't create a temporary.  */
     416      2913350 :               arg = TARGET_EXPR_INITIAL (arg);
     417      2915238 :             suppress_warning (arg, OPT_Wunused_result);
     418      2915238 :             tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
     419      2915238 :             arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
     420      2915238 :             CALL_EXPR_ARG (function, i) = arg;
     421              :           }
     422              :       }
     423              : 
     424    222018215 :   return function;
     425              : }
     426              : 
     427              : /* New overloading code.  */
     428              : 
     429              : struct z_candidate;
     430              : 
     431              : struct candidate_warning {
     432              :   z_candidate *loser;
     433              :   candidate_warning *next;
     434              : };
     435              : 
     436              : /* Information for providing diagnostics about why overloading failed.  */
     437              : 
     438              : enum rejection_reason_code {
     439              :   rr_none,
     440              :   rr_arity,
     441              :   rr_explicit_conversion,
     442              :   rr_template_conversion,
     443              :   rr_arg_conversion,
     444              :   rr_bad_arg_conversion,
     445              :   rr_template_unification,
     446              :   rr_invalid_copy,
     447              :   rr_inherited_ctor,
     448              :   rr_constraint_failure,
     449              :   rr_ignored,
     450              : };
     451              : 
     452              : struct conversion_info {
     453              :   /* The index of the argument, 0-based.  */
     454              :   int n_arg;
     455              :   /* The actual argument or its type.  */
     456              :   tree from;
     457              :   /* The type of the parameter.  */
     458              :   tree to_type;
     459              :   /* The location of the argument.  */
     460              :   location_t loc;
     461              : };
     462              : 
     463              : struct rejection_reason {
     464              :   enum rejection_reason_code code;
     465              :   union {
     466              :     /* Information about an arity mismatch.  */
     467              :     struct {
     468              :       /* The expected number of arguments.  */
     469              :       int expected;
     470              :       /* The actual number of arguments in the call.  */
     471              :       int actual;
     472              :       /* Whether EXPECTED should be treated as a lower bound.  */
     473              :       bool least_p;
     474              :     } arity;
     475              :     /* Information about an argument conversion mismatch.  */
     476              :     struct conversion_info conversion;
     477              :     /* Same, but for bad argument conversions.  */
     478              :     struct conversion_info bad_conversion;
     479              :     /* Information about template unification failures.  These are the
     480              :        parameters passed to fn_type_unification.  */
     481              :     struct {
     482              :       tree tmpl;
     483              :       tree explicit_targs;
     484              :       int num_targs;
     485              :       const tree *args;
     486              :       unsigned int nargs;
     487              :       tree return_type;
     488              :       unification_kind_t strict;
     489              :       int flags;
     490              :     } template_unification;
     491              :     /* Information about template instantiation failures.  These are the
     492              :        parameters passed to instantiate_template.  */
     493              :     struct {
     494              :       tree tmpl;
     495              :       tree targs;
     496              :     } template_instantiation;
     497              :   } u;
     498              : };
     499              : 
     500              : struct z_candidate {
     501              :   /* The FUNCTION_DECL that will be called if this candidate is
     502              :      selected by overload resolution.  */
     503              :   tree fn;
     504              :   /* If not NULL_TREE, the first argument to use when calling this
     505              :      function.  */
     506              :   tree first_arg;
     507              :   /* The rest of the arguments to use when calling this function.  If
     508              :      there are no further arguments this may be NULL or it may be an
     509              :      empty vector.  */
     510              :   const vec<tree, va_gc> *args;
     511              :   /* The implicit conversion sequences for each of the arguments to
     512              :      FN.  */
     513              :   conversion **convs;
     514              :   /* The number of implicit conversion sequences.  */
     515              :   size_t num_convs;
     516              :   /* If FN is a user-defined conversion, the standard conversion
     517              :      sequence from the type returned by FN to the desired destination
     518              :      type.  */
     519              :   conversion *second_conv;
     520              :   struct rejection_reason *reason;
     521              :   /* If FN is a member function, the binfo indicating the path used to
     522              :      qualify the name of FN at the call site.  This path is used to
     523              :      determine whether or not FN is accessible if it is selected by
     524              :      overload resolution.  The DECL_CONTEXT of FN will always be a
     525              :      (possibly improper) base of this binfo.  */
     526              :   tree access_path;
     527              :   /* If FN is a non-static member function, the binfo indicating the
     528              :      subobject to which the `this' pointer should be converted if FN
     529              :      is selected by overload resolution.  The type pointed to by
     530              :      the `this' pointer must correspond to the most derived class
     531              :      indicated by the CONVERSION_PATH.  */
     532              :   tree conversion_path;
     533              :   tree template_decl;
     534              :   tree explicit_targs;
     535              :   candidate_warning *warnings;
     536              :   z_candidate *next;
     537              :   int viable;
     538              : 
     539              :   /* The flags active in add_candidate.  */
     540              :   int flags;
     541              : 
     542     85938422 :   bool rewritten () const { return (flags & LOOKUP_REWRITTEN); }
     543   1478279637 :   bool reversed () const { return (flags & LOOKUP_REVERSED); }
     544              : };
     545              : 
     546              : /* Returns true iff T is a null pointer constant in the sense of
     547              :    [conv.ptr].  */
     548              : 
     549              : bool
     550    162156093 : null_ptr_cst_p (tree t)
     551              : {
     552    162156093 :   tree type = TREE_TYPE (t);
     553              : 
     554              :   /* [conv.ptr]
     555              : 
     556              :      A null pointer constant is an integer literal ([lex.icon]) with value
     557              :      zero or a prvalue of type std::nullptr_t.  */
     558    162156093 :   if (NULLPTR_TYPE_P (type))
     559              :     return true;
     560              : 
     561    152856662 :   if (cxx_dialect >= cxx11)
     562              :     {
     563    152507931 :       STRIP_ANY_LOCATION_WRAPPER (t);
     564              : 
     565              :       /* Core issue 903 says only literal 0 is a null pointer constant.  */
     566    152507931 :       if (TREE_CODE (t) == INTEGER_CST
     567     16015801 :           && !TREE_OVERFLOW (t)
     568     16015801 :           && TREE_CODE (type) == INTEGER_TYPE
     569     15460351 :           && integer_zerop (t)
     570    161687350 :           && !char_type_p (type))
     571              :         return true;
     572              :     }
     573       348731 :   else if (CP_INTEGRAL_TYPE_P (type))
     574              :     {
     575        65465 :       t = fold_non_dependent_expr (t, tf_none);
     576        65465 :       STRIP_NOPS (t);
     577        65465 :       if (integer_zerop (t) && !TREE_OVERFLOW (t))
     578              :         return true;
     579              :     }
     580              : 
     581              :   return false;
     582              : }
     583              : 
     584              : /* Returns true iff T is a null member pointer value (4.11).  */
     585              : 
     586              : bool
     587    102337911 : null_member_pointer_value_p (tree t)
     588              : {
     589    102337911 :   tree type = TREE_TYPE (t);
     590    102337911 :   if (!type)
     591              :     return false;
     592    102142920 :   else if (TYPE_PTRMEMFUNC_P (type))
     593          751 :     return (TREE_CODE (t) == CONSTRUCTOR
     594          401 :             && CONSTRUCTOR_NELTS (t)
     595         1149 :             && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
     596    102142169 :   else if (TYPE_PTRDATAMEM_P (type))
     597         5700 :     return integer_all_onesp (t);
     598              :   else
     599              :     return false;
     600              : }
     601              : 
     602              : /* Returns nonzero if PARMLIST consists of only default parms,
     603              :    ellipsis, and/or undeduced parameter packs.  */
     604              : 
     605              : bool
     606    899994407 : sufficient_parms_p (const_tree parmlist)
     607              : {
     608    911393142 :   for (; parmlist && parmlist != void_list_node;
     609     11398735 :        parmlist = TREE_CHAIN (parmlist))
     610    249910513 :     if (!TREE_PURPOSE (parmlist)
     611    249910513 :         && !PACK_EXPANSION_P (TREE_VALUE (parmlist)))
     612              :       return false;
     613              :   return true;
     614              : }
     615              : 
     616              : /* Allocate N bytes of memory from the conversion obstack.  The memory
     617              :    is zeroed before being returned.  */
     618              : 
     619              : static void *
     620  10440010784 : conversion_obstack_alloc (size_t n)
     621              : {
     622  10440010784 :   void *p;
     623  10440010784 :   if (!conversion_obstack_initialized)
     624              :     {
     625        83927 :       gcc_obstack_init (&conversion_obstack);
     626        83927 :       conversion_obstack_initialized = true;
     627              :     }
     628  10440010784 :   p = obstack_alloc (&conversion_obstack, n);
     629  10440010784 :   memset (p, 0, n);
     630  10440010784 :   return p;
     631              : }
     632              : 
     633              : /* RAII class to discard anything added to conversion_obstack.  */
     634              : 
     635              : struct conversion_obstack_sentinel
     636              : {
     637              :   void *p;
     638   2841702076 :   conversion_obstack_sentinel (): p (conversion_obstack_alloc (0)) {}
     639   1420837484 :   ~conversion_obstack_sentinel () { obstack_free (&conversion_obstack, p); }
     640              : };
     641              : 
     642              : /* Allocate rejection reasons.  */
     643              : 
     644              : static struct rejection_reason *
     645   1109670476 : alloc_rejection (enum rejection_reason_code code)
     646              : {
     647   1109670476 :   struct rejection_reason *p;
     648            0 :   p = (struct rejection_reason *) conversion_obstack_alloc (sizeof *p);
     649   1109670476 :   p->code = code;
     650   1109670476 :   return p;
     651              : }
     652              : 
     653              : static struct rejection_reason *
     654    261714697 : arity_rejection (tree first_arg, int expected, int actual, bool least_p = false)
     655              : {
     656    212985714 :   struct rejection_reason *r = alloc_rejection (rr_arity);
     657    261714697 :   int adjust = first_arg != NULL_TREE;
     658    261714697 :   r->u.arity.expected = expected - adjust;
     659    261714697 :   r->u.arity.actual = actual - adjust;
     660    261714697 :   r->u.arity.least_p = least_p;
     661    261714697 :   return r;
     662              : }
     663              : 
     664              : static struct rejection_reason *
     665    223848767 : arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     666              :                           location_t loc)
     667              : {
     668      7971645 :   struct rejection_reason *r = alloc_rejection (rr_arg_conversion);
     669    223848767 :   int adjust = first_arg != NULL_TREE;
     670    223848767 :   r->u.conversion.n_arg = n_arg - adjust;
     671    223848767 :   r->u.conversion.from = from;
     672    223848767 :   r->u.conversion.to_type = to;
     673    223848767 :   r->u.conversion.loc = loc;
     674    223848767 :   return r;
     675              : }
     676              : 
     677              : static struct rejection_reason *
     678     25564291 : bad_arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     679              :                               location_t loc)
     680              : {
     681         2009 :   struct rejection_reason *r = alloc_rejection (rr_bad_arg_conversion);
     682     25564291 :   int adjust = first_arg != NULL_TREE;
     683     25564291 :   r->u.bad_conversion.n_arg = n_arg - adjust;
     684     25564291 :   r->u.bad_conversion.from = from;
     685     25564291 :   r->u.bad_conversion.to_type = to;
     686     25564291 :   r->u.bad_conversion.loc = loc;
     687     25564291 :   return r;
     688              : }
     689              : 
     690              : static struct rejection_reason *
     691         2621 : explicit_conversion_rejection (tree from, tree to)
     692              : {
     693         2621 :   struct rejection_reason *r = alloc_rejection (rr_explicit_conversion);
     694         2621 :   r->u.conversion.n_arg = 0;
     695         2621 :   r->u.conversion.from = from;
     696         2621 :   r->u.conversion.to_type = to;
     697         2621 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     698         2621 :   return r;
     699              : }
     700              : 
     701              : static struct rejection_reason *
     702           21 : template_conversion_rejection (tree from, tree to)
     703              : {
     704           21 :   struct rejection_reason *r = alloc_rejection (rr_template_conversion);
     705           21 :   r->u.conversion.n_arg = 0;
     706           21 :   r->u.conversion.from = from;
     707           21 :   r->u.conversion.to_type = to;
     708           21 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     709           21 :   return r;
     710              : }
     711              : 
     712              : static struct rejection_reason *
     713    595660384 : template_unification_rejection (tree tmpl, tree explicit_targs, tree targs,
     714              :                                 const tree *args, unsigned int nargs,
     715              :                                 tree return_type, unification_kind_t strict,
     716              :                                 int flags)
     717              : {
     718    595660384 :   size_t args_n_bytes = sizeof (*args) * nargs;
     719    595660384 :   tree *args1 = (tree *) conversion_obstack_alloc (args_n_bytes);
     720    595660384 :   struct rejection_reason *r = alloc_rejection (rr_template_unification);
     721    595660384 :   r->u.template_unification.tmpl = tmpl;
     722    595660384 :   r->u.template_unification.explicit_targs = explicit_targs;
     723    595660384 :   r->u.template_unification.num_targs = TREE_VEC_LENGTH (targs);
     724              :   /* Copy args to our own storage.  */
     725    595660384 :   memcpy (args1, args, args_n_bytes);
     726    595660384 :   r->u.template_unification.args = args1;
     727    595660384 :   r->u.template_unification.nargs = nargs;
     728    595660384 :   r->u.template_unification.return_type = return_type;
     729    595660384 :   r->u.template_unification.strict = strict;
     730    595660384 :   r->u.template_unification.flags = flags;
     731    595660384 :   return r;
     732              : }
     733              : 
     734              : static struct rejection_reason *
     735          110 : template_unification_error_rejection (void)
     736              : {
     737            0 :   return alloc_rejection (rr_template_unification);
     738              : }
     739              : 
     740              : static struct rejection_reason *
     741      2023013 : invalid_copy_with_fn_template_rejection (void)
     742              : {
     743            0 :   struct rejection_reason *r = alloc_rejection (rr_invalid_copy);
     744      2023013 :   return r;
     745              : }
     746              : 
     747              : static struct rejection_reason *
     748       627134 : inherited_ctor_rejection (void)
     749              : {
     750            0 :   struct rejection_reason *r = alloc_rejection (rr_inherited_ctor);
     751       627134 :   return r;
     752              : }
     753              : 
     754              : /* Build a constraint failure record.  */
     755              : 
     756              : static struct rejection_reason *
     757       229438 : constraint_failure (void)
     758              : {
     759            0 :   struct rejection_reason *r = alloc_rejection (rr_constraint_failure);
     760       229438 :   return r;
     761              : }
     762              : 
     763              : /* Dynamically allocate a conversion.  */
     764              : 
     765              : static conversion *
     766   3347853105 : alloc_conversion (conversion_kind kind)
     767              : {
     768   3347853105 :   conversion *c;
     769            0 :   c = (conversion *) conversion_obstack_alloc (sizeof (conversion));
     770   3347853105 :   c->kind = kind;
     771   3347853105 :   return c;
     772              : }
     773              : 
     774              : /* Make sure that all memory on the conversion obstack has been
     775              :    freed.  */
     776              : 
     777              : void
     778        96186 : validate_conversion_obstack (void)
     779              : {
     780        96186 :   if (conversion_obstack_initialized)
     781        83597 :     gcc_assert ((obstack_next_free (&conversion_obstack)
     782              :                  == obstack_base (&conversion_obstack)));
     783        96186 : }
     784              : 
     785              : /* Dynamically allocate an array of N conversions.  */
     786              : 
     787              : static conversion **
     788   1439635865 : alloc_conversions (size_t n)
     789              : {
     790            0 :   return (conversion **) conversion_obstack_alloc (n * sizeof (conversion *));
     791              : }
     792              : 
     793              : /* True iff the active member of conversion::u for code CODE is NEXT.  */
     794              : 
     795              : static inline bool
     796   2051601495 : has_next (conversion_kind code)
     797              : {
     798   1876273401 :   return !(code == ck_identity
     799   2051601495 :            || code == ck_ambig
     800              :            || code == ck_list
     801   1876433750 :            || code == ck_aggr
     802   2051601495 :            || code == ck_deferred_bad);
     803              : }
     804              : 
     805              : static conversion *
     806   1006342584 : build_conv (conversion_kind code, tree type, conversion *from)
     807              : {
     808   1006342584 :   conversion *t;
     809   1006342584 :   conversion_rank rank = CONVERSION_RANK (from);
     810              : 
     811              :   /* Only call this function for conversions that use u.next.  */
     812   1006342584 :   gcc_assert (from == NULL || has_next (code));
     813              : 
     814              :   /* Note that the caller is responsible for filling in t->cand for
     815              :      user-defined conversions.  */
     816   1006342584 :   t = alloc_conversion (code);
     817   1006342584 :   t->type = type;
     818   1006342584 :   t->u.next = from;
     819              : 
     820   1006342584 :   switch (code)
     821              :     {
     822    251988672 :     case ck_ptr:
     823    251988672 :     case ck_pmem:
     824    251988672 :     case ck_base:
     825    251988672 :     case ck_std:
     826    251988672 :       if (rank < cr_std)
     827   1006342584 :         rank = cr_std;
     828              :       break;
     829              : 
     830     73890668 :     case ck_qual:
     831     73890668 :     case ck_fnptr:
     832     73890668 :       if (rank < cr_exact)
     833   1006342584 :         rank = cr_exact;
     834              :       break;
     835              : 
     836              :     default:
     837              :       break;
     838              :     }
     839   1006342584 :   t->rank = rank;
     840   1006342584 :   t->user_conv_p = (code == ck_user || from->user_conv_p);
     841   1006342584 :   t->bad_p = from->bad_p;
     842   1006342584 :   t->base_p = false;
     843   1006342584 :   return t;
     844              : }
     845              : 
     846              : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
     847              :    specialization of std::initializer_list<T>, if such a conversion is
     848              :    possible.  */
     849              : 
     850              : static conversion *
     851        81256 : build_list_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     852              : {
     853        81256 :   tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (type), 0);
     854        81256 :   unsigned len = CONSTRUCTOR_NELTS (ctor);
     855        81256 :   conversion **subconvs = alloc_conversions (len);
     856        81256 :   conversion *t;
     857        81256 :   unsigned i;
     858        81256 :   tree val;
     859              : 
     860              :   /* Within a list-initialization we can have more user-defined
     861              :      conversions.  */
     862        81256 :   flags &= ~LOOKUP_NO_CONVERSION;
     863              :   /* But no narrowing conversions.  */
     864        81256 :   flags |= LOOKUP_NO_NARROWING;
     865              : 
     866              :   /* Can't make an array of these types.  */
     867        81256 :   if (TYPE_REF_P (elttype)
     868        81247 :       || TREE_CODE (elttype) == FUNCTION_TYPE
     869        81247 :       || VOID_TYPE_P (elttype))
     870              :     return NULL;
     871              : 
     872       281414 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
     873              :     {
     874       211371 :       if (TREE_CODE (val) == RAW_DATA_CST)
     875              :         {
     876           51 :           tree elt
     877           51 :             = build_int_cst (TREE_TYPE (val), RAW_DATA_UCHAR_ELT (val, 0));
     878           51 :           conversion *sub
     879           51 :             = implicit_conversion (elttype, TREE_TYPE (val), elt,
     880              :                                    false, flags, complain);
     881           51 :           conversion *next;
     882           51 :           if (sub == NULL)
     883              :             return NULL;
     884              :           /* For conversion to initializer_list<unsigned char> or
     885              :              initializer_list<char> or initializer_list<signed char>
     886              :              we can optimize and keep RAW_DATA_CST with adjusted
     887              :              type if we report narrowing errors if needed.
     888              :              Use just one subconversion for that case.  */
     889           69 :           if (sub->kind == ck_std
     890           24 :               && sub->type
     891           24 :               && (TREE_CODE (sub->type) == INTEGER_TYPE
     892            6 :                   || is_byte_access_type (sub->type))
     893           18 :               && TYPE_PRECISION (sub->type) == CHAR_BIT
     894           18 :               && (next = next_conversion (sub))
     895           69 :               && next->kind == ck_identity)
     896              :             {
     897           18 :               subconvs[i] = sub;
     898           18 :               continue;
     899              :             }
     900              :           /* Otherwise. build separate subconv for each RAW_DATA_CST
     901              :              byte.  Wrap those into an artificial ck_list which convert_like
     902              :              will then handle.  */
     903           33 :           conversion **subsubconvs = alloc_conversions (RAW_DATA_LENGTH (val));
     904           33 :           unsigned int j;
     905           33 :           subsubconvs[0] = sub;
     906        15849 :           for (j = 1; j < (unsigned) RAW_DATA_LENGTH (val); ++j)
     907              :             {
     908        15816 :               elt = build_int_cst (TREE_TYPE (val),
     909        15816 :                                    RAW_DATA_UCHAR_ELT (val, j));
     910        15816 :               sub = implicit_conversion (elttype, TREE_TYPE (val), elt,
     911              :                                          false, flags, complain);
     912        15816 :               if (sub == NULL)
     913              :                 return NULL;
     914        15816 :               subsubconvs[j] = sub;
     915              :             }
     916              : 
     917           33 :           t = alloc_conversion (ck_list);
     918           33 :           t->type = type;
     919           33 :           t->u.list = subsubconvs;
     920           33 :           t->rank = cr_exact;
     921        15882 :           for (j = 0; j < (unsigned) RAW_DATA_LENGTH (val); ++j)
     922              :             {
     923        15849 :               sub = subsubconvs[j];
     924        15849 :               if (sub->rank > t->rank)
     925            6 :                 t->rank = sub->rank;
     926        15849 :               if (sub->user_conv_p)
     927        12063 :                 t->user_conv_p = true;
     928        15849 :               if (sub->bad_p)
     929            0 :                 t->bad_p = true;
     930              :             }
     931           33 :           subconvs[i] = t;
     932           33 :           continue;
     933           33 :         }
     934              : 
     935       211320 :       conversion *sub
     936       211320 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
     937              :                                false, flags, complain);
     938       211320 :       if (sub == NULL)
     939              :         return NULL;
     940              : 
     941       200116 :       subconvs[i] = sub;
     942              :     }
     943              : 
     944        70043 :   t = alloc_conversion (ck_list);
     945        70043 :   t->type = type;
     946        70043 :   t->u.list = subconvs;
     947        70043 :   t->rank = cr_exact;
     948              : 
     949       252238 :   for (i = 0; i < len; ++i)
     950              :     {
     951       182195 :       conversion *sub = subconvs[i];
     952       182195 :       if (sub->rank > t->rank)
     953        57792 :         t->rank = sub->rank;
     954       182195 :       if (sub->user_conv_p)
     955        10648 :         t->user_conv_p = true;
     956       182195 :       if (sub->bad_p)
     957        58262 :         t->bad_p = true;
     958              :     }
     959              : 
     960              :   return t;
     961              : }
     962              : 
     963              : /* Return the next conversion of the conversion chain (if applicable),
     964              :    or NULL otherwise.  Please use this function instead of directly
     965              :    accessing fields of struct conversion.  */
     966              : 
     967              : static conversion *
     968    865586010 : next_conversion (conversion *conv)
     969              : {
     970    865586010 :   if (conv == NULL
     971    865586010 :       || !has_next (conv->kind))
     972              :     return NULL;
     973    852094447 :   return conv->u.next;
     974              : }
     975              : 
     976              : /* Strip to the first ck_user, ck_ambig, ck_list, ck_aggr or ck_identity
     977              :    encountered.  */
     978              : 
     979              : static conversion *
     980      1421012 : strip_standard_conversion (conversion *conv)
     981              : {
     982      1421012 :   while (conv
     983      1428275 :          && conv->kind != ck_user
     984      1511416 :          && has_next (conv->kind))
     985         7263 :     conv = next_conversion (conv);
     986      1421012 :   return conv;
     987              : }
     988              : 
     989              : /* Subroutine of build_aggr_conv: check whether FROM is a valid aggregate
     990              :    initializer for array type ATYPE.  */
     991              : 
     992              : static bool
     993        74323 : can_convert_array (tree atype, tree from, int flags, tsubst_flags_t complain)
     994              : {
     995        74323 :   tree elttype = TREE_TYPE (atype);
     996        74323 :   unsigned i;
     997              : 
     998        74323 :   if (TREE_CODE (from) == CONSTRUCTOR)
     999              :     {
    1000        77259 :       for (i = 0; i < CONSTRUCTOR_NELTS (from); ++i)
    1001              :         {
    1002         2981 :           tree val = CONSTRUCTOR_ELT (from, i)->value;
    1003         2981 :           bool ok;
    1004         2981 :           if (TREE_CODE (elttype) == ARRAY_TYPE)
    1005           18 :             ok = can_convert_array (elttype, val, flags, complain);
    1006              :           else
    1007         2963 :             ok = can_convert_arg (elttype, TREE_TYPE (val), val, flags,
    1008              :                                   complain);
    1009         2981 :           if (!ok)
    1010              :             return false;
    1011              :         }
    1012              :       return true;
    1013              :     }
    1014              : 
    1015           45 :   if (char_type_p (TYPE_MAIN_VARIANT (elttype))
    1016           45 :       && TREE_CODE (tree_strip_any_location_wrapper (from)) == STRING_CST)
    1017           45 :     return array_string_literal_compatible_p (atype, from);
    1018              : 
    1019              :   /* No other valid way to aggregate initialize an array.  */
    1020              :   return false;
    1021              : }
    1022              : 
    1023              : /* Helper for build_aggr_conv.  Return true if FIELD is in PSET, or if
    1024              :    FIELD has ANON_AGGR_TYPE_P and any initializable field in there recursively
    1025              :    is in PSET.  */
    1026              : 
    1027              : static bool
    1028       764395 : field_in_pset (hash_set<tree, true> &pset, tree field)
    1029              : {
    1030       764395 :   if (pset.contains (field))
    1031              :     return true;
    1032          953 :   if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    1033            0 :     for (field = TYPE_FIELDS (TREE_TYPE (field));
    1034            0 :          field; field = DECL_CHAIN (field))
    1035              :       {
    1036            0 :         field = next_aggregate_field (field);
    1037            0 :         if (field == NULL_TREE)
    1038              :           break;
    1039            0 :         if (field_in_pset (pset, field))
    1040              :           return true;
    1041              :       }
    1042              :   return false;
    1043              : }
    1044              : 
    1045              : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
    1046              :    aggregate class, if such a conversion is possible.  */
    1047              : 
    1048              : static conversion *
    1049      1336079 : build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1050              : {
    1051      1336079 :   unsigned HOST_WIDE_INT i = 0;
    1052      1336079 :   conversion *c;
    1053      1336079 :   tree field = next_aggregate_field (TYPE_FIELDS (type));
    1054      1336079 :   tree empty_ctor = NULL_TREE;
    1055      1336079 :   hash_set<tree, true> pset;
    1056              : 
    1057              :   /* We already called reshape_init in implicit_conversion, but it might not
    1058              :      have done anything in the case of parenthesized aggr init.  */
    1059              : 
    1060              :   /* The conversions within the init-list aren't affected by the enclosing
    1061              :      context; they're always simple copy-initialization.  */
    1062      1336079 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1063              : 
    1064              :   /* For designated initializers, verify that each initializer is convertible
    1065              :      to corresponding TREE_TYPE (ce->index) and mark those FIELD_DECLs as
    1066              :      visited.  In the following loop then ignore already visited
    1067              :      FIELD_DECLs.  */
    1068      1336079 :   tree idx, val;
    1069      2099521 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
    1070              :     {
    1071       763517 :       if (!idx)
    1072              :         break;
    1073              : 
    1074       763474 :       gcc_checking_assert (TREE_CODE (idx) == FIELD_DECL);
    1075              : 
    1076       763474 :       tree ftype = TREE_TYPE (idx);
    1077       763474 :       bool ok;
    1078              : 
    1079       763474 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1080         1055 :         ok = can_convert_array (ftype, val, flags, complain);
    1081              :       else
    1082       762419 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1083              :                               complain);
    1084              : 
    1085       763474 :       if (!ok)
    1086              :         return NULL;
    1087              : 
    1088              :       /* For unions, there should be just one initializer.  */
    1089       763465 :       if (TREE_CODE (type) == UNION_TYPE)
    1090              :         {
    1091              :           field = NULL_TREE;
    1092              :           i = 1;
    1093              :           break;
    1094              :         }
    1095       763442 :       pset.add (idx);
    1096              :     }
    1097              : 
    1098      2213985 :   for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
    1099              :     {
    1100       878172 :       tree ftype = TREE_TYPE (field);
    1101       878172 :       bool ok;
    1102              : 
    1103       878172 :       if (!pset.is_empty () && field_in_pset (pset, field))
    1104       763442 :         continue;
    1105       114730 :       if (i < CONSTRUCTOR_NELTS (ctor))
    1106              :         {
    1107           29 :           constructor_elt *ce = CONSTRUCTOR_ELT (ctor, i);
    1108           29 :           gcc_checking_assert (!ce->index);
    1109           29 :           val = ce->value;
    1110           29 :           ++i;
    1111              :         }
    1112       114701 :       else if (DECL_INITIAL (field))
    1113        14304 :         val = get_nsdmi (field, /*ctor*/false, complain);
    1114       100397 :       else if (TYPE_REF_P (ftype))
    1115              :         /* Value-initialization of reference is ill-formed.  */
    1116              :         return NULL;
    1117              :       else
    1118              :         {
    1119       100391 :           if (empty_ctor == NULL_TREE)
    1120        87362 :             empty_ctor = build_constructor (init_list_type_node, NULL);
    1121              :           val = empty_ctor;
    1122              :         }
    1123              : 
    1124       114724 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1125        73250 :         ok = can_convert_array (ftype, val, flags, complain);
    1126              :       else
    1127        41474 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1128              :                               complain);
    1129              : 
    1130       114724 :       if (!ok)
    1131              :         return NULL;
    1132              : 
    1133       114713 :       if (TREE_CODE (type) == UNION_TYPE)
    1134              :         break;
    1135              :     }
    1136              : 
    1137      1336053 :   if (i < CONSTRUCTOR_NELTS (ctor))
    1138              :     return NULL;
    1139              : 
    1140      1336034 :   c = alloc_conversion (ck_aggr);
    1141      1336034 :   c->type = type;
    1142      1336034 :   c->rank = cr_exact;
    1143      1336034 :   c->user_conv_p = true;
    1144      1336034 :   c->check_narrowing = true;
    1145      1336034 :   c->u.expr = ctor;
    1146      1336034 :   return c;
    1147      1336079 : }
    1148              : 
    1149              : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
    1150              :    array type, if such a conversion is possible.  */
    1151              : 
    1152              : static conversion *
    1153         1652 : build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1154              : {
    1155         1652 :   conversion *c;
    1156         1652 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1157         1652 :   tree elttype = TREE_TYPE (type);
    1158         1652 :   bool bad = false;
    1159         1652 :   bool user = false;
    1160         1652 :   enum conversion_rank rank = cr_exact;
    1161              : 
    1162              :   /* We might need to propagate the size from the element to the array.  */
    1163         1652 :   complete_type (type);
    1164              : 
    1165         1652 :   if (TYPE_DOMAIN (type)
    1166         1652 :       && !variably_modified_type_p (TYPE_DOMAIN (type), NULL_TREE))
    1167              :     {
    1168         1578 :       unsigned HOST_WIDE_INT alen = tree_to_uhwi (array_type_nelts_top (type));
    1169         1578 :       if (alen < len)
    1170              :         return NULL;
    1171              :     }
    1172              : 
    1173         1615 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1174              : 
    1175         6940 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1176              :     {
    1177         2758 :       conversion *sub
    1178         2758 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1179              :                                false, flags, complain);
    1180         2758 :       if (sub == NULL)
    1181              :         return NULL;
    1182              : 
    1183         2181 :       if (sub->rank > rank)
    1184          264 :         rank = sub->rank;
    1185         2181 :       if (sub->user_conv_p)
    1186           23 :         user = true;
    1187         2181 :       if (sub->bad_p)
    1188          195 :         bad = true;
    1189              :     }
    1190              : 
    1191         1038 :   c = alloc_conversion (ck_aggr);
    1192         1038 :   c->type = type;
    1193         1038 :   c->rank = rank;
    1194         1038 :   c->user_conv_p = user;
    1195         1038 :   c->bad_p = bad;
    1196         1038 :   c->u.expr = ctor;
    1197         1038 :   return c;
    1198              : }
    1199              : 
    1200              : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
    1201              :    complex type, if such a conversion is possible.  */
    1202              : 
    1203              : static conversion *
    1204        54406 : build_complex_conv (tree type, tree ctor, int flags,
    1205              :                     tsubst_flags_t complain)
    1206              : {
    1207        54406 :   conversion *c;
    1208        54406 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1209        54406 :   tree elttype = TREE_TYPE (type);
    1210        54406 :   bool bad = false;
    1211        54406 :   bool user = false;
    1212        54406 :   enum conversion_rank rank = cr_exact;
    1213              : 
    1214        54406 :   if (len != 2)
    1215              :     return NULL;
    1216              : 
    1217        54366 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1218              : 
    1219       271830 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1220              :     {
    1221       108732 :       conversion *sub
    1222       108732 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1223              :                                false, flags, complain);
    1224       108732 :       if (sub == NULL)
    1225              :         return NULL;
    1226              : 
    1227       108732 :       if (sub->rank > rank)
    1228           44 :         rank = sub->rank;
    1229       108732 :       if (sub->user_conv_p)
    1230            0 :         user = true;
    1231       108732 :       if (sub->bad_p)
    1232            0 :         bad = true;
    1233              :     }
    1234              : 
    1235        54366 :   c = alloc_conversion (ck_aggr);
    1236        54366 :   c->type = type;
    1237        54366 :   c->rank = rank;
    1238        54366 :   c->user_conv_p = user;
    1239        54366 :   c->bad_p = bad;
    1240        54366 :   c->u.expr = ctor;
    1241        54366 :   return c;
    1242              : }
    1243              : 
    1244              : /* Build a representation of the identity conversion from EXPR to
    1245              :    itself.  The TYPE should match the type of EXPR, if EXPR is non-NULL.  */
    1246              : 
    1247              : static conversion *
    1248   2332382039 : build_identity_conv (tree type, tree expr)
    1249              : {
    1250   2332382039 :   conversion *c;
    1251              : 
    1252            0 :   c = alloc_conversion (ck_identity);
    1253   2332382039 :   c->type = type;
    1254   2332382039 :   c->u.expr = expr;
    1255              : 
    1256   2332382039 :   return c;
    1257              : }
    1258              : 
    1259              : /* Converting from EXPR to TYPE was ambiguous in the sense that there
    1260              :    were multiple user-defined conversions to accomplish the job.
    1261              :    Build a conversion that indicates that ambiguity.  */
    1262              : 
    1263              : static conversion *
    1264         1339 : build_ambiguous_conv (tree type, tree expr)
    1265              : {
    1266         1339 :   conversion *c;
    1267              : 
    1268            0 :   c = alloc_conversion (ck_ambig);
    1269         1339 :   c->type = type;
    1270         1339 :   c->u.expr = expr;
    1271              : 
    1272         1339 :   return c;
    1273              : }
    1274              : 
    1275              : tree
    1276   4040158952 : strip_top_quals (tree t)
    1277              : {
    1278   4040158952 :   if (TREE_CODE (t) == ARRAY_TYPE)
    1279              :     return t;
    1280   4031918407 :   return cp_build_qualified_type (t, 0);
    1281              : }
    1282              : 
    1283              : /* Returns the standard conversion path (see [conv]) from type FROM to type
    1284              :    TO, if any.  For proper handling of null pointer constants, you must
    1285              :    also pass the expression EXPR to convert from.  If C_CAST_P is true,
    1286              :    this conversion is coming from a C-style cast.  */
    1287              : 
    1288              : static conversion *
    1289   1823688575 : standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
    1290              :                      int flags, tsubst_flags_t complain)
    1291              : {
    1292   1823688575 :   enum tree_code fcode, tcode;
    1293   1823688575 :   conversion *conv;
    1294   1823688575 :   bool fromref = false;
    1295   1823688575 :   tree qualified_to;
    1296              : 
    1297   1823688575 :   to = non_reference (to);
    1298   1823688575 :   if (TYPE_REF_P (from))
    1299              :     {
    1300        76085 :       fromref = true;
    1301        76085 :       from = TREE_TYPE (from);
    1302              :     }
    1303   1823688575 :   qualified_to = to;
    1304   1823688575 :   to = strip_top_quals (to);
    1305   1823688575 :   from = strip_top_quals (from);
    1306              : 
    1307   1823688575 :   if (expr && type_unknown_p (expr))
    1308              :     {
    1309       264687 :       if (TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
    1310              :         {
    1311        30520 :           tsubst_flags_t tflags = tf_conv;
    1312        30520 :           expr = instantiate_type (to, expr, tflags);
    1313        30520 :           if (expr == error_mark_node)
    1314              :             return NULL;
    1315        19732 :           from = TREE_TYPE (expr);
    1316              :         }
    1317       234167 :       else if (TREE_CODE (to) == BOOLEAN_TYPE)
    1318              :         {
    1319              :           /* Necessary for eg, TEMPLATE_ID_EXPRs (c++/50961).  */
    1320         5193 :           expr = resolve_nondeduced_context (expr, complain);
    1321         5193 :           from = TREE_TYPE (expr);
    1322              :         }
    1323              :     }
    1324              : 
    1325   1823677787 :   fcode = TREE_CODE (from);
    1326   1823677787 :   tcode = TREE_CODE (to);
    1327              : 
    1328   1823677787 :   conv = build_identity_conv (from, expr);
    1329   1823677787 :   if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
    1330              :     {
    1331      8260550 :       from = type_decays_to (from);
    1332      8260550 :       fcode = TREE_CODE (from);
    1333              :       /* Tell convert_like that we're using the address.  */
    1334      8260550 :       conv->rvaluedness_matches_p = true;
    1335      8260550 :       conv = build_conv (ck_lvalue, from, conv);
    1336              :     }
    1337              :   /* Wrapping a ck_rvalue around a class prvalue (as a result of using
    1338              :      obvalue_p) seems odd, since it's already a prvalue, but that's how we
    1339              :      express the copy constructor call required by copy-initialization.  */
    1340   1815417237 :   else if (fromref || (expr && obvalue_p (expr)))
    1341              :     {
    1342    478379206 :       if (expr)
    1343              :         {
    1344    478303144 :           tree bitfield_type;
    1345    478303144 :           bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1346    478303144 :           if (bitfield_type)
    1347              :             {
    1348     18412406 :               from = strip_top_quals (bitfield_type);
    1349     18412406 :               fcode = TREE_CODE (from);
    1350              :             }
    1351              :         }
    1352    478379206 :       conv = build_conv (ck_rvalue, from, conv);
    1353              :       /* If we're performing copy-initialization, remember to skip
    1354              :          explicit constructors.  */
    1355    478379206 :       if (flags & LOOKUP_ONLYCONVERTING)
    1356    427352252 :         conv->copy_init_p = true;
    1357              :     }
    1358              : 
    1359              :    /* Allow conversion between `__complex__' data types.  */
    1360   1823677787 :   if (tcode == COMPLEX_TYPE && fcode == COMPLEX_TYPE)
    1361              :     {
    1362              :       /* The standard conversion sequence to convert FROM to TO is
    1363              :          the standard conversion sequence to perform componentwise
    1364              :          conversion.  */
    1365      2204193 :       conversion *part_conv = standard_conversion
    1366      2204193 :         (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, c_cast_p, flags,
    1367              :          complain);
    1368              : 
    1369      2204193 :       if (!part_conv)
    1370              :         conv = NULL;
    1371      2204193 :       else if (part_conv->kind == ck_identity)
    1372              :         /* Leave conv alone.  */;
    1373              :       else
    1374              :         {
    1375       224612 :           conv = build_conv (part_conv->kind, to, conv);
    1376       224612 :           conv->rank = part_conv->rank;
    1377              :         }
    1378              : 
    1379      2204193 :       return conv;
    1380              :     }
    1381              : 
    1382   1821473594 :   if (same_type_p (from, to))
    1383              :     {
    1384   1083987637 :       if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
    1385     24364229 :         conv->type = qualified_to;
    1386   1059623408 :       else if (from != to)
    1387              :         /* Use TO in order to not lose TO in diagnostics.  */
    1388     95187325 :         conv->type = to;
    1389   1083987637 :       return conv;
    1390              :     }
    1391              : 
    1392              :   /* [conv.ptr]
    1393              :      A null pointer constant can be converted to a pointer type; ... A
    1394              :      null pointer constant of integral type can be converted to an
    1395              :      rvalue of type std::nullptr_t. */
    1396    457126934 :   if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
    1397    457040848 :        || NULLPTR_TYPE_P (to))
    1398    745746466 :       && ((expr && null_ptr_cst_p (expr))
    1399    282646103 :           || NULLPTR_TYPE_P (from)))
    1400      5973433 :     conv = build_conv (ck_std, to, conv);
    1401    731512524 :   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
    1402    730826372 :            || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
    1403              :     {
    1404              :       /* For backwards brain damage compatibility, allow interconversion of
    1405              :          pointers and integers with a pedwarn.  */
    1406      2535337 :       conv = build_conv (ck_std, to, conv);
    1407      2535337 :       conv->bad_p = true;
    1408              :     }
    1409    728977187 :   else if (UNSCOPED_ENUM_P (to) && fcode == INTEGER_TYPE)
    1410              :     {
    1411              :       /* For backwards brain damage compatibility, allow interconversion of
    1412              :          enums and integers with a pedwarn.  */
    1413       342555 :       conv = build_conv (ck_std, to, conv);
    1414       342555 :       conv->bad_p = true;
    1415              :     }
    1416    728634632 :   else if ((tcode == POINTER_TYPE && fcode == POINTER_TYPE)
    1417    463786646 :            || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from)))
    1418              :     {
    1419         1700 :       tree to_pointee;
    1420         1700 :       tree from_pointee;
    1421              : 
    1422         1700 :       if (tcode == POINTER_TYPE)
    1423              :         {
    1424    264847986 :           to_pointee = TREE_TYPE (to);
    1425    264847986 :           from_pointee = TREE_TYPE (from);
    1426              : 
    1427              :           /* Since this is the target of a pointer, it can't have function
    1428              :              qualifiers, so any TYPE_QUALS must be for attributes const or
    1429              :              noreturn.  Strip them.  */
    1430    264847986 :           if (TREE_CODE (to_pointee) == FUNCTION_TYPE
    1431    264847986 :               && TYPE_QUALS (to_pointee))
    1432            9 :             to_pointee = build_qualified_type (to_pointee, TYPE_UNQUALIFIED);
    1433    264847986 :           if (TREE_CODE (from_pointee) == FUNCTION_TYPE
    1434    264847986 :               && TYPE_QUALS (from_pointee))
    1435           36 :             from_pointee = build_qualified_type (from_pointee, TYPE_UNQUALIFIED);
    1436              :         }
    1437              :       else
    1438              :         {
    1439         1700 :           to_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (to);
    1440         1700 :           from_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (from);
    1441              :         }
    1442              : 
    1443    264849686 :       if (tcode == POINTER_TYPE
    1444    264849686 :           && same_type_ignoring_top_level_qualifiers_p (from_pointee,
    1445              :                                                         to_pointee))
    1446              :         ;
    1447    185108707 :       else if (VOID_TYPE_P (to_pointee)
    1448      4955349 :                && !TYPE_PTRDATAMEM_P (from)
    1449      4955349 :                && TREE_CODE (from_pointee) != FUNCTION_TYPE)
    1450              :         {
    1451      4955024 :           tree nfrom = TREE_TYPE (from);
    1452              :           /* Don't try to apply restrict to void.  */
    1453      4955024 :           int quals = cp_type_quals (nfrom) & ~TYPE_QUAL_RESTRICT;
    1454      4955024 :           from_pointee = cp_build_qualified_type (void_type_node, quals);
    1455      4955024 :           from = build_pointer_type (from_pointee);
    1456      4955024 :           conv = build_conv (ck_ptr, from, conv);
    1457      4955024 :         }
    1458    180153683 :       else if (TYPE_PTRDATAMEM_P (from))
    1459              :         {
    1460         1700 :           tree fbase = TYPE_PTRMEM_CLASS_TYPE (from);
    1461         1700 :           tree tbase = TYPE_PTRMEM_CLASS_TYPE (to);
    1462              : 
    1463         1700 :           if (same_type_p (fbase, tbase))
    1464              :             /* No base conversion needed.  */;
    1465          589 :           else if (DERIVED_FROM_P (fbase, tbase)
    1466          990 :                    && (same_type_ignoring_top_level_qualifiers_p
    1467          401 :                        (from_pointee, to_pointee)))
    1468              :             {
    1469          377 :               from = build_ptrmem_type (tbase, from_pointee);
    1470          377 :               conv = build_conv (ck_pmem, from, conv);
    1471              :             }
    1472              :           else
    1473          212 :             return NULL;
    1474              :         }
    1475     83756865 :       else if (CLASS_TYPE_P (from_pointee)
    1476     83754502 :                && CLASS_TYPE_P (to_pointee)
    1477              :                /* [conv.ptr]
    1478              : 
    1479              :                   An rvalue of type "pointer to cv D," where D is a
    1480              :                   class type, can be converted to an rvalue of type
    1481              :                   "pointer to cv B," where B is a base class (clause
    1482              :                   _class.derived_) of D.  If B is an inaccessible
    1483              :                   (clause _class.access_) or ambiguous
    1484              :                   (_class.member.lookup_) base class of D, a program
    1485              :                   that necessitates this conversion is ill-formed.
    1486              :                   Therefore, we use DERIVED_FROM_P, and do not check
    1487              :                   access or uniqueness.  */
    1488    262712468 :                && DERIVED_FROM_P (to_pointee, from_pointee))
    1489              :         {
    1490      7133716 :           from_pointee
    1491      7133716 :             = cp_build_qualified_type (to_pointee,
    1492              :                                        cp_type_quals (from_pointee));
    1493      7133716 :           from = build_pointer_type (from_pointee);
    1494      7133716 :           conv = build_conv (ck_ptr, from, conv);
    1495      7133716 :           conv->base_p = true;
    1496              :         }
    1497              : 
    1498    264849474 :       if (same_type_p (from, to))
    1499              :         /* OK */;
    1500    255498997 :       else if (c_cast_p && comp_ptr_ttypes_const (to, from, bounds_either))
    1501              :         /* In a C-style cast, we ignore CV-qualification because we
    1502              :            are allowed to perform a static_cast followed by a
    1503              :            const_cast.  */
    1504          623 :         conv = build_conv (ck_qual, to, conv);
    1505    255498374 :       else if (!c_cast_p && comp_ptr_ttypes (to_pointee, from_pointee))
    1506     73600420 :         conv = build_conv (ck_qual, to, conv);
    1507    181897954 :       else if (expr && string_conv_p (to, expr, 0))
    1508              :         /* converting from string constant to char *.  */
    1509          204 :         conv = build_conv (ck_qual, to, conv);
    1510    181897750 :       else if (fnptr_conv_p (to, from))
    1511       220401 :         conv = build_conv (ck_fnptr, to, conv);
    1512              :       /* Allow conversions among compatible ObjC pointer types (base
    1513              :          conversions have been already handled above).  */
    1514    181677349 :       else if (c_dialect_objc ()
    1515    181677349 :                && objc_compare_types (to, from, -4, NULL_TREE))
    1516            0 :         conv = build_conv (ck_ptr, to, conv);
    1517    181677349 :       else if (ptr_reasonably_similar (to_pointee, from_pointee))
    1518              :         {
    1519     10123122 :           conv = build_conv (ck_ptr, to, conv);
    1520     10123122 :           conv->bad_p = true;
    1521              :         }
    1522              :       else
    1523              :         return NULL;
    1524              : 
    1525    308540146 :       from = to;
    1526              :     }
    1527    463784946 :   else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
    1528              :     {
    1529        82469 :       tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
    1530        82469 :       tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
    1531        82469 :       tree fbase = class_of_this_parm (fromfn);
    1532        82469 :       tree tbase = class_of_this_parm (tofn);
    1533              : 
    1534              :       /* If FBASE and TBASE are equivalent but incomplete, DERIVED_FROM_P
    1535              :          yields false.  But a pointer to member of incomplete class is OK.  */
    1536        82469 :       if (!same_type_p (fbase, tbase) && !DERIVED_FROM_P (fbase, tbase))
    1537              :         return NULL;
    1538              : 
    1539        82308 :       tree fstat = static_fn_type (fromfn);
    1540        82308 :       tree tstat = static_fn_type (tofn);
    1541        82308 :       if (same_type_p (tstat, fstat)
    1542        82308 :           || fnptr_conv_p (tstat, fstat))
    1543              :         /* OK */;
    1544              :       else
    1545              :         return NULL;
    1546              : 
    1547        82040 :       if (!same_type_p (fbase, tbase))
    1548              :         {
    1549        81971 :           from = build_memfn_type (fstat,
    1550              :                                    tbase,
    1551              :                                    cp_type_quals (tbase),
    1552              :                                    type_memfn_rqual (tofn));
    1553        81971 :           from = build_ptrmemfunc_type (build_pointer_type (from));
    1554        81971 :           conv = build_conv (ck_pmem, from, conv);
    1555        81971 :           conv->base_p = true;
    1556              :         }
    1557        82040 :       if (fnptr_conv_p (tstat, fstat))
    1558           69 :         conv = build_conv (ck_fnptr, to, conv);
    1559              :     }
    1560    463702477 :   else if (tcode == BOOLEAN_TYPE)
    1561              :     {
    1562              :       /* [conv.bool]
    1563              : 
    1564              :           A prvalue of arithmetic, unscoped enumeration, pointer, or pointer
    1565              :           to member type can be converted to a prvalue of type bool. ...
    1566              :           For direct-initialization (8.5 [dcl.init]), a prvalue of type
    1567              :           std::nullptr_t can be converted to a prvalue of type bool;  */
    1568      6934201 :       if (ARITHMETIC_TYPE_P (from)
    1569      6746407 :           || UNSCOPED_ENUM_P (from)
    1570      4419928 :           || fcode == POINTER_TYPE
    1571      3137367 :           || TYPE_PTRMEM_P (from)
    1572     16663333 :           || NULLPTR_TYPE_P (from))
    1573              :         {
    1574     10389118 :           conv = build_conv (ck_std, to, conv);
    1575     10389118 :           if (fcode == POINTER_TYPE
    1576      9106557 :               || TYPE_PTRDATAMEM_P (from)
    1577      9106413 :               || (TYPE_PTRMEMFUNC_P (from)
    1578           77 :                   && conv->rank < cr_pbool)
    1579     19495454 :               || NULLPTR_TYPE_P (from))
    1580      1282859 :             conv->rank = cr_pbool;
    1581     10389118 :           if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
    1582           38 :             conv->bad_p = true;
    1583     10389118 :           if (flags & LOOKUP_NO_NARROWING)
    1584        30687 :             conv->check_narrowing = true;
    1585     10389118 :           return conv;
    1586              :         }
    1587              : 
    1588              :       return NULL;
    1589              :     }
    1590              :   /* We don't check for ENUMERAL_TYPE here because there are no standard
    1591              :      conversions to enum type.  */
    1592              :   /* As an extension, allow conversion to complex type.  */
    1593    450176290 :   else if (ARITHMETIC_TYPE_P (to))
    1594              :     {
    1595     32436529 :       if (! (INTEGRAL_CODE_P (fcode)
    1596     25207692 :              || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
    1597    240464502 :           || SCOPED_ENUM_P (from))
    1598              :         return NULL;
    1599              : 
    1600              :       /* If we're parsing an enum with no fixed underlying type, we're
    1601              :          dealing with an incomplete type, which renders the conversion
    1602              :          ill-formed.  */
    1603    205809491 :       if (!COMPLETE_TYPE_P (from))
    1604              :         return NULL;
    1605              : 
    1606    205809485 :       conv = build_conv (ck_std, to, conv);
    1607              : 
    1608    205809485 :       tree underlying_type = NULL_TREE;
    1609    205809485 :       if (TREE_CODE (from) == ENUMERAL_TYPE
    1610    205809485 :           && ENUM_FIXED_UNDERLYING_TYPE_P (from))
    1611      2009637 :         underlying_type = ENUM_UNDERLYING_TYPE (from);
    1612              : 
    1613              :       /* Give this a better rank if it's a promotion.
    1614              : 
    1615              :          To handle CWG 1601, also bump the rank if we are converting
    1616              :          an enumeration with a fixed underlying type to the underlying
    1617              :          type.  */
    1618    205809485 :       if ((same_type_p (to, type_promotes_to (from))
    1619    193108125 :            || (underlying_type && same_type_p (to, underlying_type)))
    1620    205809504 :           && next_conversion (conv)->rank <= cr_promotion)
    1621     12701379 :         conv->rank = cr_promotion;
    1622              : 
    1623              :       /* A prvalue of floating-point type can be converted to a prvalue of
    1624              :          another floating-point type with a greater or equal conversion
    1625              :          rank ([conv.rank]).  A prvalue of standard floating-point type can
    1626              :          be converted to a prvalue of another standard floating-point type.
    1627              :          For backwards compatibility with handling __float128 and other
    1628              :          non-standard floating point types, allow all implicit floating
    1629              :          point conversions if neither type is extended floating-point
    1630              :          type and if at least one of them is, fail if they have unordered
    1631              :          conversion rank or from has higher conversion rank.  */
    1632    205809485 :       if (fcode == REAL_TYPE
    1633    205809485 :           && tcode == REAL_TYPE
    1634     16118035 :           && (extended_float_type_p (from)
    1635     15469934 :               || extended_float_type_p (to))
    1636    208885602 :           && cp_compare_floating_point_conversion_ranks (from, to) >= 2)
    1637      1273904 :         conv->bad_p = true;
    1638              :     }
    1639    234919480 :   else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
    1640    234919480 :            && vector_types_convertible_p (from, to, false))
    1641         4884 :     return build_conv (ck_std, to, conv);
    1642    234914596 :   else if (MAYBE_CLASS_TYPE_P (to) && MAYBE_CLASS_TYPE_P (from)
    1643     89702679 :            && is_properly_derived_from (from, to))
    1644              :     {
    1645       502049 :       if (conv->kind == ck_rvalue)
    1646       501998 :         conv = next_conversion (conv);
    1647       502049 :       conv = build_conv (ck_base, to, conv);
    1648              :       /* The derived-to-base conversion indicates the initialization
    1649              :          of a parameter with base type from an object of a derived
    1650              :          type.  A temporary object is created to hold the result of
    1651              :          the conversion unless we're binding directly to a reference.  */
    1652       502049 :       conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
    1653              :       /* If we're performing copy-initialization, remember to skip
    1654              :          explicit constructors.  */
    1655       502049 :       if (flags & LOOKUP_ONLYCONVERTING)
    1656       501982 :         conv->copy_init_p = true;
    1657              :     }
    1658              :   else
    1659    234412547 :     return NULL;
    1660              : 
    1661    308540146 :   if (flags & LOOKUP_NO_NARROWING)
    1662     90979309 :     conv->check_narrowing = true;
    1663              : 
    1664              :   return conv;
    1665              : }
    1666              : 
    1667              : /* Returns nonzero if T1 is reference-related to T2.
    1668              : 
    1669              :    This is considered when a reference to T1 is initialized by a T2.  */
    1670              : 
    1671              : bool
    1672    360351841 : reference_related_p (tree t1, tree t2)
    1673              : {
    1674    360351841 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1675              :     return false;
    1676              : 
    1677    360351837 :   t1 = TYPE_MAIN_VARIANT (t1);
    1678    360351837 :   t2 = TYPE_MAIN_VARIANT (t2);
    1679              : 
    1680              :   /* [dcl.init.ref]
    1681              : 
    1682              :      Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
    1683              :      to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2.  */
    1684    360351837 :   return (similar_type_p (t1, t2)
    1685    360351837 :           || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    1686     84065534 :               && DERIVED_FROM_P (t1, t2)));
    1687              : }
    1688              : 
    1689              : /* Returns nonzero if T1 is reference-compatible with T2.  */
    1690              : 
    1691              : bool
    1692    324292200 : reference_compatible_p (tree t1, tree t2)
    1693              : {
    1694              :   /* [dcl.init.ref]
    1695              : 
    1696              :      "cv1 T1" is reference compatible with "cv2 T2" if
    1697              :      a prvalue of type "pointer to cv2 T2" can be converted to the type
    1698              :      "pointer to cv1 T1" via a standard conversion sequence.  */
    1699    324292200 :   tree ptype1 = build_pointer_type (t1);
    1700    324292200 :   tree ptype2 = build_pointer_type (t2);
    1701    324292200 :   conversion *conv = standard_conversion (ptype1, ptype2, NULL_TREE,
    1702              :                                           /*c_cast_p=*/false, 0, tf_none);
    1703    324292200 :   if (!conv || conv->bad_p)
    1704    179617539 :     return false;
    1705              :   return true;
    1706              : }
    1707              : 
    1708              : /* Return true if converting FROM to TO would involve a qualification
    1709              :    conversion.  */
    1710              : 
    1711              : static bool
    1712    160234084 : involves_qualification_conversion_p (tree to, tree from)
    1713              : {
    1714              :   /* If we're not convering a pointer to another one, we won't get
    1715              :      a qualification conversion.  */
    1716    160234084 :   if (!((TYPE_PTR_P (to) && TYPE_PTR_P (from))
    1717         2345 :         || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from))))
    1718              :     return false;
    1719              : 
    1720      5019364 :   conversion *conv = standard_conversion (to, from, NULL_TREE,
    1721              :                                           /*c_cast_p=*/false, 0, tf_none);
    1722      9969793 :   for (conversion *t = conv; t; t = next_conversion (t))
    1723      5019380 :     if (t->kind == ck_qual)
    1724              :       return true;
    1725              : 
    1726              :   return false;
    1727              : }
    1728              : 
    1729              : /* Return true if HANDLER is a match for exception object with EXCEPT_TYPE as
    1730              :    per [except.handle]/3.  */
    1731              : 
    1732              : bool
    1733         1917 : handler_match_for_exception_type (tree handler, tree except_type)
    1734              : {
    1735         1917 :   tree handler_type = HANDLER_TYPE (handler);
    1736         1917 :   if (handler_type == NULL_TREE)
    1737              :     return true; /* ... */
    1738         1882 :   if (same_type_ignoring_top_level_qualifiers_p (handler_type, except_type))
    1739              :     return true;
    1740          297 :   if (CLASS_TYPE_P (except_type) && CLASS_TYPE_P (handler_type))
    1741              :     {
    1742           85 :       base_kind b_kind;
    1743           85 :       tree binfo = lookup_base (except_type, handler_type, ba_check, &b_kind,
    1744              :                                 tf_none);
    1745           85 :       if (binfo && binfo != error_mark_node)
    1746           41 :         return true;
    1747              :     }
    1748          256 :   if (TYPE_PTR_P (handler_type) || TYPE_PTRDATAMEM_P (handler_type))
    1749              :     {
    1750           60 :       if (TREE_CODE (except_type) == NULLPTR_TYPE)
    1751              :         return true;
    1752           54 :       if ((TYPE_PTR_P (handler_type) && TYPE_PTR_P (except_type))
    1753            9 :           || (TYPE_PTRDATAMEM_P (handler_type)
    1754            0 :               && TYPE_PTRDATAMEM_P (except_type)))
    1755              :         {
    1756           45 :           conversion *conv
    1757           45 :             = standard_conversion (handler_type, except_type, NULL_TREE,
    1758              :                                    /*c_cast_p=*/false, 0, tf_none);
    1759           45 :           if (conv && !conv->bad_p)
    1760              :             {
    1761           33 :               for (conversion *t = conv; t; t = next_conversion (t))
    1762           22 :                 switch (t->kind)
    1763              :                   {
    1764           22 :                   case ck_ptr:
    1765           22 :                   case ck_fnptr:
    1766           22 :                   case ck_qual:
    1767           22 :                   case ck_identity:
    1768           22 :                     break;
    1769              :                   default:
    1770              :                     return false;
    1771              :                   }
    1772              :               return true;
    1773              :             }
    1774              :         }
    1775              :     }
    1776              :   return false;
    1777              : }
    1778              : 
    1779              : /* A reference of the indicated TYPE is being bound directly to the
    1780              :    expression represented by the implicit conversion sequence CONV.
    1781              :    Return a conversion sequence for this binding.  */
    1782              : 
    1783              : static conversion *
    1784    164147067 : direct_reference_binding (tree type, conversion *conv)
    1785              : {
    1786    164147067 :   tree t;
    1787              : 
    1788    164147067 :   gcc_assert (TYPE_REF_P (type));
    1789    164147067 :   gcc_assert (!TYPE_REF_P (conv->type));
    1790              : 
    1791    164147067 :   t = TREE_TYPE (type);
    1792              : 
    1793    164147067 :   if (conv->kind == ck_identity)
    1794              :     /* Mark the identity conv as to not decay to rvalue.  */
    1795    164147067 :     conv->rvaluedness_matches_p = true;
    1796              : 
    1797              :   /* [over.ics.rank]
    1798              : 
    1799              :      When a parameter of reference type binds directly
    1800              :      (_dcl.init.ref_) to an argument expression, the implicit
    1801              :      conversion sequence is the identity conversion, unless the
    1802              :      argument expression has a type that is a derived class of the
    1803              :      parameter type, in which case the implicit conversion sequence is
    1804              :      a derived-to-base Conversion.
    1805              : 
    1806              :      If the parameter binds directly to the result of applying a
    1807              :      conversion function to the argument expression, the implicit
    1808              :      conversion sequence is a user-defined conversion sequence
    1809              :      (_over.ics.user_), with the second standard conversion sequence
    1810              :      either an identity conversion or, if the conversion function
    1811              :      returns an entity of a type that is a derived class of the
    1812              :      parameter type, a derived-to-base conversion.  */
    1813    164147067 :   if (is_properly_derived_from (conv->type, t))
    1814              :     {
    1815              :       /* Represent the derived-to-base conversion.  */
    1816      3912983 :       conv = build_conv (ck_base, t, conv);
    1817              :       /* We will actually be binding to the base-class subobject in
    1818              :          the derived class, so we mark this conversion appropriately.
    1819              :          That way, convert_like knows not to generate a temporary.  */
    1820      3912983 :       conv->need_temporary_p = false;
    1821              :     }
    1822    160234084 :   else if (involves_qualification_conversion_p (t, conv->type))
    1823              :     /* Represent the qualification conversion.  After DR 2352
    1824              :        #1 and #2 were indistinguishable conversion sequences:
    1825              : 
    1826              :          void f(int*); // #1
    1827              :          void f(const int* const &); // #2
    1828              :          void g(int* p) { f(p); }
    1829              : 
    1830              :        because the types "int *" and "const int *const" are
    1831              :        reference-related and we were binding both directly and they
    1832              :        had the same rank.  To break it up, we add a ck_qual under the
    1833              :        ck_ref_bind so that conversion sequence ranking chooses #1.
    1834              : 
    1835              :        We strip_top_quals here which is also what standard_conversion
    1836              :        does.  Failure to do so would confuse comp_cv_qual_signature
    1837              :        into thinking that in
    1838              : 
    1839              :          void f(const int * const &); // #1
    1840              :          void f(const int *); // #2
    1841              :          int *x;
    1842              :          f(x);
    1843              : 
    1844              :        #2 is a better match than #1 even though they're ambiguous (97296).  */
    1845        68951 :     conv = build_conv (ck_qual, strip_top_quals (t), conv);
    1846              : 
    1847    164147067 :   return build_conv (ck_ref_bind, type, conv);
    1848              : }
    1849              : 
    1850              : /* Returns the conversion path from type FROM to reference type TO for
    1851              :    purposes of reference binding.  For lvalue binding, either pass a
    1852              :    reference type to FROM or an lvalue expression to EXPR.  If the
    1853              :    reference will be bound to a temporary, NEED_TEMPORARY_P is set for
    1854              :    the conversion returned.  If C_CAST_P is true, this
    1855              :    conversion is coming from a C-style cast.  */
    1856              : 
    1857              : static conversion *
    1858    323457150 : reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
    1859              :                    tsubst_flags_t complain)
    1860              : {
    1861    323457150 :   conversion *conv = NULL;
    1862    323457150 :   conversion *bad_direct_conv = nullptr;
    1863    323457150 :   tree to = TREE_TYPE (rto);
    1864    323457150 :   tree from = rfrom;
    1865    323457150 :   tree tfrom;
    1866    323457150 :   bool related_p;
    1867    323457150 :   bool compatible_p;
    1868    323457150 :   cp_lvalue_kind gl_kind;
    1869    323457150 :   bool is_lvalue;
    1870              : 
    1871    323457150 :   if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
    1872              :     {
    1873           49 :       expr = instantiate_type (to, expr, tf_none);
    1874           49 :       if (expr == error_mark_node)
    1875              :         return NULL;
    1876           49 :       from = TREE_TYPE (expr);
    1877              :     }
    1878              : 
    1879    323457150 :   bool copy_list_init = false;
    1880    323457150 :   bool single_list_conv = false;
    1881    323457150 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    1882              :     {
    1883       266824 :       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    1884              :       /* DR 1288: Otherwise, if the initializer list has a single element
    1885              :          of type E and ... [T's] referenced type is reference-related to E,
    1886              :          the object or reference is initialized from that element...
    1887              : 
    1888              :          ??? With P0388R4, we should bind 't' directly to U{}:
    1889              :            using U = A[2];
    1890              :            A (&&t)[] = {U{}};
    1891              :          because A[] and A[2] are reference-related.  But we don't do it
    1892              :          because grok_reference_init has deduced the array size (to 1), and
    1893              :          A[1] and A[2] aren't reference-related.  */
    1894       266824 :       if (CONSTRUCTOR_NELTS (expr) == 1
    1895       144697 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    1896              :         {
    1897         3012 :           tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    1898         3012 :           if (error_operand_p (elt))
    1899              :             return NULL;
    1900         3007 :           tree etype = TREE_TYPE (elt);
    1901         3007 :           if (reference_related_p (to, etype))
    1902              :             {
    1903          595 :               expr = elt;
    1904          595 :               from = etype;
    1905          595 :               goto skip;
    1906              :             }
    1907         2412 :           else if (CLASS_TYPE_P (etype) && TYPE_HAS_CONVERSION (etype))
    1908              :             /* CWG1996: jason's proposed drafting adds "or initializing T from E
    1909              :                would bind directly".  We check that in the direct binding with
    1910              :                conversion code below.  */
    1911              :             single_list_conv = true;
    1912              :         }
    1913              :       /* Otherwise, if T is a reference type, a prvalue temporary of the type
    1914              :          referenced by T is copy-list-initialized, and the reference is bound
    1915              :          to that temporary. */
    1916              :       copy_list_init = true;
    1917    323457145 :     skip:;
    1918              :     }
    1919              : 
    1920    323457145 :   if (TYPE_REF_P (from))
    1921              :     {
    1922        56612 :       from = TREE_TYPE (from);
    1923        56612 :       if (!TYPE_REF_IS_RVALUE (rfrom)
    1924        56612 :           || TREE_CODE (from) == FUNCTION_TYPE)
    1925              :         gl_kind = clk_ordinary;
    1926              :       else
    1927              :         gl_kind = clk_rvalueref;
    1928              :     }
    1929    323400533 :   else if (expr)
    1930    319700944 :     gl_kind = lvalue_kind (expr);
    1931      3449958 :   else if (CLASS_TYPE_P (from)
    1932      3699589 :            || TREE_CODE (from) == ARRAY_TYPE)
    1933              :     gl_kind = clk_class;
    1934              :   else
    1935              :     gl_kind = clk_none;
    1936              : 
    1937              :   /* Don't allow a class prvalue when LOOKUP_NO_TEMP_BIND.  */
    1938    323457145 :   if ((flags & LOOKUP_NO_TEMP_BIND)
    1939      3640630 :       && (gl_kind & clk_class))
    1940              :     gl_kind = clk_none;
    1941              : 
    1942              :   /* Same mask as real_lvalue_p.  */
    1943    320572565 :   is_lvalue = gl_kind && !(gl_kind & (clk_rvalueref|clk_class));
    1944              : 
    1945    282770095 :   tfrom = from;
    1946    282770095 :   if ((gl_kind & clk_bitfield) != 0)
    1947     11844993 :     tfrom = unlowered_expr_type (expr);
    1948              : 
    1949              :   /* Figure out whether or not the types are reference-related and
    1950              :      reference compatible.  We have to do this after stripping
    1951              :      references from FROM.  */
    1952    323457145 :   related_p = reference_related_p (to, tfrom);
    1953              :   /* If this is a C cast, first convert to an appropriately qualified
    1954              :      type, so that we can later do a const_cast to the desired type.  */
    1955    323457145 :   if (related_p && c_cast_p
    1956    323457145 :       && !at_least_as_qualified_p (to, tfrom))
    1957          194 :     to = cp_build_qualified_type (to, cp_type_quals (tfrom));
    1958    323457145 :   compatible_p = reference_compatible_p (to, tfrom);
    1959              : 
    1960              :   /* Directly bind reference when target expression's type is compatible with
    1961              :      the reference and expression is an lvalue. In DR391, the wording in
    1962              :      [8.5.3/5 dcl.init.ref] is changed to also require direct bindings for
    1963              :      const and rvalue references to rvalues of compatible class type.
    1964              :      We should also do direct bindings for non-class xvalues.  */
    1965    323457145 :   if ((related_p || compatible_p) && gl_kind)
    1966              :     {
    1967              :       /* [dcl.init.ref]
    1968              : 
    1969              :          If the initializer expression
    1970              : 
    1971              :          -- is an lvalue (but not an lvalue for a bit-field), and "cv1 T1"
    1972              :             is reference-compatible with "cv2 T2,"
    1973              : 
    1974              :          the reference is bound directly to the initializer expression
    1975              :          lvalue.
    1976              : 
    1977              :          [...]
    1978              :          If the initializer expression is an rvalue, with T2 a class type,
    1979              :          and "cv1 T1" is reference-compatible with "cv2 T2", the reference
    1980              :          is bound to the object represented by the rvalue or to a sub-object
    1981              :          within that object.  */
    1982              : 
    1983    147076814 :       conv = build_identity_conv (tfrom, expr);
    1984    147076814 :       conv = direct_reference_binding (rto, conv);
    1985              : 
    1986    147076814 :       if (TYPE_REF_P (rfrom))
    1987              :         /* Handle rvalue reference to function properly.  */
    1988        15437 :         conv->rvaluedness_matches_p
    1989        15437 :           = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
    1990              :       else
    1991    147061377 :         conv->rvaluedness_matches_p
    1992    147061377 :           = (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
    1993              : 
    1994    147076814 :       if ((gl_kind & clk_bitfield) != 0
    1995    147076814 :           || ((gl_kind & clk_packed) != 0 && !TYPE_PACKED (to)))
    1996              :         /* For the purposes of overload resolution, we ignore the fact
    1997              :            this expression is a bitfield or packed field. (In particular,
    1998              :            [over.ics.ref] says specifically that a function with a
    1999              :            non-const reference parameter is viable even if the
    2000              :            argument is a bitfield.)
    2001              : 
    2002              :            However, when we actually call the function we must create
    2003              :            a temporary to which to bind the reference.  If the
    2004              :            reference is volatile, or isn't const, then we cannot make
    2005              :            a temporary, so we just issue an error when the conversion
    2006              :            actually occurs.  */
    2007          110 :         conv->need_temporary_p = true;
    2008              : 
    2009              :       /* Don't allow binding of lvalues (other than function lvalues) to
    2010              :          rvalue references.  */
    2011    110779211 :       if (is_lvalue && TYPE_REF_IS_RVALUE (rto)
    2012    160113142 :           && TREE_CODE (to) != FUNCTION_TYPE)
    2013     13034734 :         conv->bad_p = true;
    2014              : 
    2015              :       /* Nor the reverse.  */
    2016     36297603 :       if (!is_lvalue && !TYPE_REF_IS_RVALUE (rto)
    2017              :           /* Unless it's really a C++20 lvalue being treated as an xvalue.
    2018              :              But in C++23, such an expression is just an xvalue, not a special
    2019              :              lvalue, so the binding is once again ill-formed.  */
    2020     22600757 :           && !(cxx_dialect <= cxx20
    2021     20010983 :                && (gl_kind & clk_implicit_rval))
    2022     21322884 :           && (!CP_TYPE_CONST_NON_VOLATILE_P (to)
    2023     21152379 :               || (flags & LOOKUP_NO_RVAL_BIND))
    2024    147247319 :           && TREE_CODE (to) != FUNCTION_TYPE)
    2025       170505 :         conv->bad_p = true;
    2026              : 
    2027    147076814 :       if (!compatible_p)
    2028      7972798 :         conv->bad_p = true;
    2029              : 
    2030    147076814 :       return conv;
    2031              :     }
    2032              :   /* [class.conv.fct] A conversion function is never used to convert a
    2033              :      (possibly cv-qualified) object to the (possibly cv-qualified) same
    2034              :      object type (or a reference to it), to a (possibly cv-qualified) base
    2035              :      class of that type (or a reference to it).... */
    2036      4737926 :   else if (!related_p
    2037    171642405 :            && !(flags & LOOKUP_NO_CONVERSION)
    2038     60589351 :            && (CLASS_TYPE_P (from) || single_list_conv))
    2039              :     {
    2040     22139250 :       tree rexpr = expr;
    2041     22139250 :       if (single_list_conv)
    2042           88 :         rexpr = CONSTRUCTOR_ELT (expr, 0)->value;
    2043              : 
    2044              :       /* [dcl.init.ref]
    2045              : 
    2046              :          If the initializer expression
    2047              : 
    2048              :          -- has a class type (i.e., T2 is a class type) can be
    2049              :             implicitly converted to an lvalue of type "cv3 T3," where
    2050              :             "cv1 T1" is reference-compatible with "cv3 T3".  (this
    2051              :             conversion is selected by enumerating the applicable
    2052              :             conversion functions (_over.match.ref_) and choosing the
    2053              :             best one through overload resolution.  (_over.match_).
    2054              : 
    2055              :         the reference is bound to the lvalue result of the conversion
    2056              :         in the second case.  */
    2057     22139250 :       z_candidate *cand = build_user_type_conversion_1 (rto, rexpr, flags,
    2058              :                                                         complain);
    2059     22139250 :       if (cand)
    2060              :         {
    2061        12759 :           if (!cand->second_conv->bad_p)
    2062              :             return cand->second_conv;
    2063              : 
    2064              :           /* Direct reference binding wasn't successful and yielded a bad
    2065              :              conversion.  Proceed with trying to go through a temporary
    2066              :              instead, and if that also fails then we'll return this bad
    2067              :              conversion rather than no conversion for sake of better
    2068              :              diagnostics.  */
    2069              :           bad_direct_conv = cand->second_conv;
    2070              :         }
    2071              :     }
    2072              : 
    2073              :   /* From this point on, we conceptually need temporaries, even if we
    2074              :      elide them.  Only the cases above are "direct bindings".  */
    2075    176367964 :   if (flags & LOOKUP_NO_TEMP_BIND)
    2076              :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2077              : 
    2078              :   /* [over.ics.rank]
    2079              : 
    2080              :      When a parameter of reference type is not bound directly to an
    2081              :      argument expression, the conversion sequence is the one required
    2082              :      to convert the argument expression to the underlying type of the
    2083              :      reference according to _over.best.ics_.  Conceptually, this
    2084              :      conversion sequence corresponds to copy-initializing a temporary
    2085              :      of the underlying type with the argument expression.  Any
    2086              :      difference in top-level cv-qualification is subsumed by the
    2087              :      initialization itself and does not constitute a conversion.  */
    2088              : 
    2089    172945559 :   bool maybe_valid_p = true;
    2090              : 
    2091              :   /* [dcl.init.ref]
    2092              : 
    2093              :      Otherwise, the reference shall be an lvalue reference to a
    2094              :      non-volatile const type, or the reference shall be an rvalue
    2095              :      reference.  */
    2096    224339910 :   if (!CP_TYPE_CONST_NON_VOLATILE_P (to) && !TYPE_REF_IS_RVALUE (rto))
    2097              :     maybe_valid_p = false;
    2098              : 
    2099              :   /* [dcl.init.ref]
    2100              : 
    2101              :      Otherwise, a temporary of type "cv1 T1" is created and
    2102              :      initialized from the initializer expression using the rules for a
    2103              :      non-reference copy initialization.  If T1 is reference-related to
    2104              :      T2, cv1 must be the same cv-qualification as, or greater
    2105              :      cv-qualification than, cv2; otherwise, the program is ill-formed.  */
    2106    172945559 :   if (related_p && !at_least_as_qualified_p (to, from))
    2107              :     maybe_valid_p = false;
    2108              : 
    2109              :   /* We try below to treat an invalid reference binding as a bad conversion
    2110              :      to improve diagnostics, but doing so may cause otherwise unnecessary
    2111              :      instantiations that can lead to a hard error.  So during the first pass
    2112              :      of overload resolution wherein we shortcut bad conversions, instead just
    2113              :      produce a special conversion indicating a second pass is necessary if
    2114              :      there's no strictly viable candidate.  */
    2115    172945559 :   if (!maybe_valid_p && (flags & LOOKUP_SHORTCUT_BAD_CONVS))
    2116              :     {
    2117      7665958 :       if (bad_direct_conv)
    2118              :         return bad_direct_conv;
    2119              : 
    2120      7665629 :       conv = alloc_conversion (ck_deferred_bad);
    2121      7665629 :       conv->bad_p = true;
    2122      7665629 :       return conv;
    2123              :     }
    2124              : 
    2125              :   /* We're generating a temporary now, but don't bind any more in the
    2126              :      conversion (specifically, don't slice the temporary returned by a
    2127              :      conversion operator).  */
    2128    165279601 :   flags |= LOOKUP_NO_TEMP_BIND;
    2129              : 
    2130              :   /* Core issue 899: When [copy-]initializing a temporary to be bound
    2131              :      to the first parameter of a copy constructor (12.8) called with
    2132              :      a single argument in the context of direct-initialization,
    2133              :      explicit conversion functions are also considered.
    2134              : 
    2135              :      So don't set LOOKUP_ONLYCONVERTING in that case.  */
    2136    165279601 :   if (!(flags & LOOKUP_COPY_PARM))
    2137    145340506 :     flags |= LOOKUP_ONLYCONVERTING;
    2138              : 
    2139    165279601 :   if (!conv)
    2140    165279601 :     conv = implicit_conversion (to, from, expr, c_cast_p,
    2141              :                                 flags, complain);
    2142    165279601 :   if (!conv)
    2143              :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2144              : 
    2145     13150285 :   if (conv->user_conv_p)
    2146              :     {
    2147      9126074 :       if (copy_list_init)
    2148              :         /* Remember this was copy-list-initialization.  */
    2149       223895 :         conv->need_temporary_p = true;
    2150              : 
    2151              :       /* If initializing the temporary used a conversion function,
    2152              :          recalculate the second conversion sequence.  */
    2153     26114288 :       for (conversion *t = conv; t; t = next_conversion (t))
    2154     17583754 :         if (t->kind == ck_user
    2155      9051419 :             && c_cast_p && !maybe_valid_p)
    2156              :           {
    2157           12 :             if (complain & tf_warning)
    2158           12 :               warning (OPT_Wcast_user_defined,
    2159              :                        "casting %qT to %qT does not use %qD",
    2160           12 :                        from, rto, t->cand->fn);
    2161              :             /* Don't let recalculation try to make this valid.  */
    2162              :             break;
    2163              :           }
    2164     17583742 :         else if (t->kind == ck_user
    2165     17583742 :                  && DECL_CONV_FN_P (t->cand->fn))
    2166              :           {
    2167       595528 :             tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn));
    2168              :             /* A prvalue of non-class type is cv-unqualified.  */
    2169       595528 :             if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype))
    2170         1637 :               ftype = cv_unqualified (ftype);
    2171       595528 :             int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND;
    2172       595528 :             conversion *new_second
    2173       595528 :               = reference_binding (rto, ftype, NULL_TREE, c_cast_p,
    2174              :                                    sflags, complain);
    2175       595528 :             if (!new_second)
    2176              :               return bad_direct_conv ? bad_direct_conv : nullptr;
    2177       595528 :             conv = merge_conversion_sequences (t, new_second);
    2178       595528 :             gcc_assert (maybe_valid_p || conv->bad_p);
    2179              :             return conv;
    2180              :           }
    2181              :     }
    2182              : 
    2183     12554757 :   conv = build_conv (ck_ref_bind, rto, conv);
    2184              :   /* This reference binding, unlike those above, requires the
    2185              :      creation of a temporary.  */
    2186     12554757 :   conv->need_temporary_p = true;
    2187     12554757 :   conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
    2188     12554757 :   conv->bad_p |= !maybe_valid_p;
    2189              : 
    2190     12554757 :   return conv;
    2191              : }
    2192              : 
    2193              : /* Returns the implicit conversion sequence (see [over.ics]) from type
    2194              :    FROM to type TO.  The optional expression EXPR may affect the
    2195              :    conversion.  FLAGS are the usual overloading flags.  If C_CAST_P is
    2196              :    true, this conversion is coming from a C-style cast.  */
    2197              : 
    2198              : static conversion *
    2199   1807275167 : implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
    2200              :                      int flags, tsubst_flags_t complain)
    2201              : {
    2202   1807275167 :   conversion *conv;
    2203              : 
    2204   1807275167 :   if (from == error_mark_node || to == error_mark_node
    2205   1807273998 :       || expr == error_mark_node)
    2206              :     return NULL;
    2207              : 
    2208              :   /* Other flags only apply to the primary function in overload
    2209              :      resolution, or after we've chosen one.  */
    2210   1807273998 :   flags &= (LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION|LOOKUP_COPY_PARM
    2211              :             |LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND|LOOKUP_NO_NARROWING
    2212              :             |LOOKUP_PROTECT|LOOKUP_NO_NON_INTEGRAL|LOOKUP_SHORTCUT_BAD_CONVS);
    2213              : 
    2214              :   /* FIXME: actually we don't want warnings either, but we can't just
    2215              :      have 'complain &= ~(tf_warning|tf_error)' because it would cause
    2216              :      the regression of, eg, g++.old-deja/g++.benjamin/16077.C.
    2217              :      We really ought not to issue that warning until we've committed
    2218              :      to that conversion.  */
    2219   1807273998 :   complain &= ~tf_error;
    2220              : 
    2221              :   /* Call reshape_init early to remove redundant braces.  */
    2222   1807273998 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) && CLASS_TYPE_P (to))
    2223              :     {
    2224      2494912 :       to = complete_type (to);
    2225      2494912 :       if (!COMPLETE_TYPE_P (to))
    2226              :         return nullptr;
    2227      2494888 :       if (!CLASSTYPE_NON_AGGREGATE (to))
    2228              :         {
    2229      1336375 :           expr = reshape_init (to, expr, complain);
    2230      1336375 :           if (expr == error_mark_node)
    2231              :             return nullptr;
    2232      1336134 :           from = TREE_TYPE (expr);
    2233              :         }
    2234              :     }
    2235              : 
    2236              :   /* An argument should have gone through convert_from_reference.  */
    2237   1807273733 :   gcc_checking_assert (!expr || !TYPE_REF_P (from));
    2238              : 
    2239   1807273733 :   if (TYPE_REF_P (to))
    2240    315100960 :     conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
    2241              :   else
    2242   1492172773 :     conv = standard_conversion (to, from, expr, c_cast_p, flags, complain);
    2243              : 
    2244   1807273733 :   if (conv)
    2245              :     return conv;
    2246              : 
    2247    402780436 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    2248              :     {
    2249      5177162 :       if (is_std_init_list (to) && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2250        81256 :         return build_list_conv (to, expr, flags, complain);
    2251              : 
    2252              :       /* As an extension, allow list-initialization of _Complex.  */
    2253      5014641 :       if (TREE_CODE (to) == COMPLEX_TYPE
    2254      5069056 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2255              :         {
    2256        54406 :           conv = build_complex_conv (to, expr, flags, complain);
    2257        54406 :           if (conv)
    2258              :             return conv;
    2259              :         }
    2260              : 
    2261              :       /* Allow conversion from an initializer-list with one element to a
    2262              :          scalar type.  */
    2263      4960275 :       if (SCALAR_TYPE_P (to))
    2264              :         {
    2265      2506691 :           int nelts = CONSTRUCTOR_NELTS (expr);
    2266       421065 :           tree elt;
    2267              : 
    2268       421065 :           if (nelts == 0)
    2269      2085626 :             elt = build_value_init (to, tf_none);
    2270       421065 :           else if (nelts == 1 && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2271       420349 :             elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2272              :           else
    2273          716 :             elt = error_mark_node;
    2274              : 
    2275      2506691 :           conv = implicit_conversion (to, TREE_TYPE (elt), elt,
    2276              :                                       c_cast_p, flags, complain);
    2277      2506691 :           if (conv)
    2278              :             {
    2279      2505012 :               conv->check_narrowing = true;
    2280      2505012 :               if (BRACE_ENCLOSED_INITIALIZER_P (elt))
    2281              :                 /* Too many levels of braces, i.e. '{{1}}'.  */
    2282           16 :                 conv->bad_p = true;
    2283      2505012 :               return conv;
    2284              :             }
    2285              :         }
    2286      2453584 :       else if (TREE_CODE (to) == ARRAY_TYPE)
    2287         1652 :         return build_array_conv (to, expr, flags, complain);
    2288              :     }
    2289              : 
    2290    400138150 :   if (expr != NULL_TREE
    2291    392165995 :       && (MAYBE_CLASS_TYPE_P (from)
    2292    217588610 :           || MAYBE_CLASS_TYPE_P (to))
    2293    681122124 :       && (flags & LOOKUP_NO_CONVERSION) == 0)
    2294              :     {
    2295    106291189 :       struct z_candidate *cand;
    2296              : 
    2297     75164775 :       if (CLASS_TYPE_P (to)
    2298     75164725 :           && BRACE_ENCLOSED_INITIALIZER_P (expr)
    2299    108704205 :           && !CLASSTYPE_NON_AGGREGATE (complete_type (to)))
    2300      1336079 :         return build_aggr_conv (to, expr, flags, complain);
    2301              : 
    2302    104955110 :       cand = build_user_type_conversion_1 (to, expr, flags, complain);
    2303    104955110 :       if (cand)
    2304              :         {
    2305      1047568 :           if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    2306      1038298 :               && CONSTRUCTOR_NELTS (expr) == 1
    2307        56298 :               && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    2308     16614664 :               && !is_list_ctor (cand->fn))
    2309              :             {
    2310              :               /* "If C is not an initializer-list constructor and the
    2311              :                  initializer list has a single element of type cv U, where U is
    2312              :                  X or a class derived from X, the implicit conversion sequence
    2313              :                  has Exact Match rank if U is X, or Conversion rank if U is
    2314              :                  derived from X."  */
    2315        55950 :               tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2316        55950 :               tree elttype = TREE_TYPE (elt);
    2317        55950 :               if (reference_related_p (to, elttype))
    2318           67 :                 return implicit_conversion (to, elttype, elt,
    2319           67 :                                             c_cast_p, flags, complain);
    2320              :             }
    2321     16558299 :           conv = cand->second_conv;
    2322              :         }
    2323              : 
    2324              :       /* We used to try to bind a reference to a temporary here, but that
    2325              :          is now handled after the recursive call to this function at the end
    2326              :          of reference_binding.  */
    2327    104955043 :       return conv;
    2328              :     }
    2329              : 
    2330              :   return NULL;
    2331              : }
    2332              : 
    2333              : /* Like implicit_conversion, but return NULL if the conversion is bad.
    2334              : 
    2335              :    This is not static so that check_non_deducible_conversion can call it within
    2336              :    add_template_candidate_real as part of overload resolution; it should not be
    2337              :    called outside of overload resolution.  */
    2338              : 
    2339              : conversion *
    2340      8098475 : good_conversion (tree to, tree from, tree expr,
    2341              :                  int flags, tsubst_flags_t complain)
    2342              : {
    2343      8098475 :   conversion *c = implicit_conversion (to, from, expr, /*cast*/false,
    2344              :                                        flags, complain);
    2345      8098475 :   if (c && c->bad_p)
    2346      2794626 :     c = NULL;
    2347      8098475 :   return c;
    2348              : }
    2349              : 
    2350              : /* Add a new entry to the list of candidates.  Used by the add_*_candidate
    2351              :    functions.  ARGS will not be changed until a single candidate is
    2352              :    selected.  */
    2353              : 
    2354              : static struct z_candidate *
    2355   1490287376 : add_candidate (struct z_candidate **candidates,
    2356              :                tree fn, tree first_arg, const vec<tree, va_gc> *args,
    2357              :                size_t num_convs, conversion **convs,
    2358              :                tree access_path, tree conversion_path,
    2359              :                int viable, struct rejection_reason *reason,
    2360              :                int flags)
    2361              : {
    2362   1490287376 :   struct z_candidate *cand = (struct z_candidate *)
    2363   1490287376 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2364              : 
    2365   1490287376 :   cand->fn = fn;
    2366   1490287376 :   cand->first_arg = first_arg;
    2367   1490287376 :   cand->args = args;
    2368   1490287376 :   cand->convs = convs;
    2369   1490287376 :   cand->num_convs = num_convs;
    2370   1490287376 :   cand->access_path = access_path;
    2371   1490287376 :   cand->conversion_path = conversion_path;
    2372   1490287376 :   cand->viable = viable;
    2373   1490287376 :   cand->reason = reason;
    2374   1490287376 :   cand->next = *candidates;
    2375   1490287376 :   cand->flags = flags;
    2376   1490287376 :   *candidates = cand;
    2377              : 
    2378   1490287376 :   if (convs && cand->reversed ())
    2379              :     /* Swap the conversions for comparison in joust; we'll swap them back
    2380              :        before build_over_call.  */
    2381    143796645 :     std::swap (convs[0], convs[1]);
    2382              : 
    2383   1490287376 :   return cand;
    2384              : }
    2385              : 
    2386              : /* FN is a function from the overload set that we outright didn't even
    2387              :    consider (for some reason); add it to the list as an non-viable "ignored"
    2388              :    candidate.  */
    2389              : 
    2390              : static z_candidate *
    2391   1036052094 : add_ignored_candidate (z_candidate **candidates, tree fn)
    2392              : {
    2393              :   /* No need to dynamically allocate these.  */
    2394   1036052094 :   static const rejection_reason reason_ignored = { rr_ignored, {} };
    2395              : 
    2396   1036052094 :   struct z_candidate *cand = (struct z_candidate *)
    2397   1036047214 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2398              : 
    2399   1036052094 :   cand->fn = fn;
    2400   1036052094 :   cand->reason = const_cast<rejection_reason *> (&reason_ignored);
    2401   1036052094 :   cand->next = *candidates;
    2402   1036052094 :   *candidates = cand;
    2403              : 
    2404   1036052094 :   return cand;
    2405              : }
    2406              : 
    2407              : /* True iff CAND is a candidate added by add_ignored_candidate.  */
    2408              : 
    2409              : static bool
    2410    812197183 : ignored_candidate_p (const z_candidate *cand)
    2411              : {
    2412    812191124 :   return cand->reason && cand->reason->code == rr_ignored;
    2413              : }
    2414              : 
    2415              : /* Return the number of remaining arguments in the parameter list
    2416              :    beginning with ARG.  */
    2417              : 
    2418              : int
    2419    212989036 : remaining_arguments (tree arg)
    2420              : {
    2421    212989036 :   int n;
    2422              : 
    2423    355751500 :   for (n = 0; arg != NULL_TREE && arg != void_list_node;
    2424    142762464 :        arg = TREE_CHAIN (arg))
    2425    142762464 :     n++;
    2426              : 
    2427    212989036 :   return n;
    2428              : }
    2429              : 
    2430              : /* [over.match.copy]: When initializing a temporary object (12.2) to be bound
    2431              :    to the first parameter of a constructor where the parameter is of type
    2432              :    "reference to possibly cv-qualified T" and the constructor is called with a
    2433              :    single argument in the context of direct-initialization of an object of type
    2434              :    "cv2 T", explicit conversion functions are also considered.
    2435              : 
    2436              :    So set LOOKUP_COPY_PARM to let reference_binding know that
    2437              :    it's being called in that context.  */
    2438              : 
    2439              : int
    2440    605434189 : conv_flags (int i, int nargs, tree fn, tree arg, int flags)
    2441              : {
    2442    605434189 :   int lflags = flags;
    2443    605434189 :   tree t;
    2444    585629766 :   if (i == 0 && nargs == 1 && DECL_CONSTRUCTOR_P (fn)
    2445    193870463 :       && (t = FUNCTION_FIRST_USER_PARMTYPE (fn))
    2446    799304652 :       && (same_type_ignoring_top_level_qualifiers_p
    2447    193870463 :           (non_reference (TREE_VALUE (t)), DECL_CONTEXT (fn))))
    2448              :     {
    2449    153831097 :       if (!(flags & LOOKUP_ONLYCONVERTING))
    2450     40052521 :         lflags |= LOOKUP_COPY_PARM;
    2451    153831097 :       if ((flags & LOOKUP_LIST_INIT_CTOR)
    2452    153831097 :           && BRACE_ENCLOSED_INITIALIZER_P (arg))
    2453         1398 :         lflags |= LOOKUP_NO_CONVERSION;
    2454              :     }
    2455              :   else
    2456    451603092 :     lflags |= LOOKUP_ONLYCONVERTING;
    2457              : 
    2458    605434189 :   return lflags;
    2459              : }
    2460              : 
    2461              : /* Build an appropriate 'this' conversion for the method FN and class
    2462              :    type CTYPE from the value ARG (having type ARGTYPE) to the type PARMTYPE.
    2463              :    This function modifies PARMTYPE, ARGTYPE and ARG.  */
    2464              : 
    2465              : static conversion *
    2466    122941254 : build_this_conversion (tree fn, tree ctype,
    2467              :                        tree& parmtype, tree& argtype, tree& arg,
    2468              :                        int flags, tsubst_flags_t complain)
    2469              : {
    2470    245882508 :   gcc_assert (DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2471              :               && !DECL_CONSTRUCTOR_P (fn));
    2472              : 
    2473              :   /* The type of the implicit object parameter ('this') for
    2474              :      overload resolution is not always the same as for the
    2475              :      function itself; conversion functions are considered to
    2476              :      be members of the class being converted, and functions
    2477              :      introduced by a using-declaration are considered to be
    2478              :      members of the class that uses them.
    2479              : 
    2480              :      Since build_over_call ignores the ICS for the `this'
    2481              :      parameter, we can just change the parm type.  */
    2482    122941254 :   parmtype = cp_build_qualified_type (ctype,
    2483    122941254 :                                       cp_type_quals (TREE_TYPE (parmtype)));
    2484    122941254 :   bool this_p = true;
    2485    122941254 :   if (FUNCTION_REF_QUALIFIED (TREE_TYPE (fn)))
    2486              :     {
    2487              :       /* If the function has a ref-qualifier, the implicit
    2488              :          object parameter has reference type.  */
    2489       155287 :       bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
    2490       155287 :       parmtype = cp_build_reference_type (parmtype, rv);
    2491              :       /* The special handling of 'this' conversions in compare_ics
    2492              :          does not apply if there is a ref-qualifier.  */
    2493       155287 :       this_p = false;
    2494              :     }
    2495              :   else
    2496              :     {
    2497    122785967 :       parmtype = build_pointer_type (parmtype);
    2498              :       /* We don't use build_this here because we don't want to
    2499              :          capture the object argument until we've chosen a
    2500              :          non-static member function.  */
    2501    122785967 :       arg = build_address (arg);
    2502    122785967 :       argtype = lvalue_type (arg);
    2503              :     }
    2504    122941254 :   flags |= LOOKUP_ONLYCONVERTING;
    2505    122941254 :   conversion *t = implicit_conversion (parmtype, argtype, arg,
    2506              :                                        /*c_cast_p=*/false, flags, complain);
    2507    122941254 :   t->this_p = this_p;
    2508    122941254 :   return t;
    2509              : }
    2510              : 
    2511              : /* Create an overload candidate for the function or method FN called
    2512              :    with the argument list FIRST_ARG/ARGS and add it to CANDIDATES.
    2513              :    FLAGS is passed on to implicit_conversion.
    2514              : 
    2515              :    This does not change ARGS.
    2516              : 
    2517              :    CTYPE, if non-NULL, is the type we want to pretend this function
    2518              :    comes from for purposes of overload resolution.
    2519              : 
    2520              :    SHORTCUT_BAD_CONVS controls how we handle "bad" argument conversions.
    2521              :    If true, we stop computing conversions upon seeing the first bad
    2522              :    conversion.  This is used by add_candidates to avoid computing
    2523              :    more conversions than necessary in the presence of a strictly viable
    2524              :    candidate, while preserving the defacto behavior of overload resolution
    2525              :    when it turns out there are only non-strictly viable candidates.  */
    2526              : 
    2527              : static struct z_candidate *
    2528    832259034 : add_function_candidate (struct z_candidate **candidates,
    2529              :                         tree fn, tree ctype, tree first_arg,
    2530              :                         const vec<tree, va_gc> *args, tree access_path,
    2531              :                         tree conversion_path, int flags,
    2532              :                         conversion **convs,
    2533              :                         bool shortcut_bad_convs,
    2534              :                         tsubst_flags_t complain)
    2535              : {
    2536    832259034 :   tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2537    832259034 :   int i, len;
    2538    832259034 :   tree parmnode;
    2539    832259034 :   tree orig_first_arg = first_arg;
    2540    832259034 :   int skip;
    2541    832259034 :   int viable = 1;
    2542    832259034 :   struct rejection_reason *reason = NULL;
    2543              : 
    2544              :   /* The `this', `in_chrg' and VTT arguments to constructors are not
    2545              :      considered in overload resolution.  */
    2546   1664518068 :   if (DECL_CONSTRUCTOR_P (fn))
    2547              :     {
    2548    385883616 :       if (ctor_omit_inherited_parms (fn))
    2549              :         /* Bring back parameters omitted from an inherited ctor.  */
    2550          150 :         parmlist = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn));
    2551              :       else
    2552    385883541 :         parmlist = skip_artificial_parms_for (fn, parmlist);
    2553    385883616 :       skip = num_artificial_parms_for (fn);
    2554    385883616 :       if (skip > 0 && first_arg != NULL_TREE)
    2555              :         {
    2556    385883616 :           --skip;
    2557    385883616 :           first_arg = NULL_TREE;
    2558              :         }
    2559              :     }
    2560              :   else
    2561              :     skip = 0;
    2562              : 
    2563   1614992672 :   len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0);
    2564    832259034 :   if (!convs)
    2565    707307434 :     convs = alloc_conversions (len);
    2566              : 
    2567              :   /* 13.3.2 - Viable functions [over.match.viable]
    2568              :      First, to be a viable function, a candidate function shall have enough
    2569              :      parameters to agree in number with the arguments in the list.
    2570              : 
    2571              :      We need to check this first; otherwise, checking the ICSes might cause
    2572              :      us to produce an ill-formed template instantiation.  */
    2573              : 
    2574    832259034 :   parmnode = parmlist;
    2575   1746141272 :   for (i = 0; i < len; ++i)
    2576              :     {
    2577   1024275723 :       if (parmnode == NULL_TREE || parmnode == void_list_node)
    2578              :         break;
    2579    913882238 :       parmnode = TREE_CHAIN (parmnode);
    2580              :     }
    2581              : 
    2582    832259034 :   if ((i < len && parmnode)
    2583    832259034 :       || !sufficient_parms_p (parmnode))
    2584              :     {
    2585    212985714 :       int remaining = remaining_arguments (parmnode);
    2586    212985714 :       viable = 0;
    2587    212985714 :       reason = arity_rejection (first_arg, i + remaining, len);
    2588              :     }
    2589              : 
    2590              :   /* An inherited constructor (12.6.3 [class.inhctor.init]) that has a first
    2591              :      parameter of type "reference to cv C" (including such a constructor
    2592              :      instantiated from a template) is excluded from the set of candidate
    2593              :      functions when used to construct an object of type D with an argument list
    2594              :      containing a single argument if C is reference-related to D.  */
    2595    726861412 :   if (viable && len == 1 && parmlist && DECL_CONSTRUCTOR_P (fn)
    2596    196595898 :       && flag_new_inheriting_ctors
    2597   1028846247 :       && DECL_INHERITED_CTOR (fn))
    2598              :     {
    2599       903163 :       tree ptype = non_reference (TREE_VALUE (parmlist));
    2600       903163 :       tree dtype = DECL_CONTEXT (fn);
    2601      1806326 :       tree btype = DECL_INHERITED_CTOR_BASE (fn);
    2602       903163 :       if (reference_related_p (ptype, dtype)
    2603       903163 :           && reference_related_p (btype, ptype))
    2604              :         {
    2605       627134 :           viable = false;
    2606       627134 :           reason = inherited_ctor_rejection ();
    2607              :         }
    2608              :     }
    2609              : 
    2610              :   /* Second, for a function to be viable, its constraints must be
    2611              :      satisfied. */
    2612    832259034 :   if (flag_concepts && viable && !constraints_satisfied_p (fn))
    2613              :     {
    2614       229429 :       reason = constraint_failure ();
    2615       229429 :       viable = false;
    2616              :     }
    2617              : 
    2618              :   /* When looking for a function from a subobject from an implicit
    2619              :      copy/move constructor/operator=, don't consider anything that takes (a
    2620              :      reference to) an unrelated type.  See c++/44909 and core 1092.  */
    2621    832259034 :   if (viable && parmlist && (flags & LOOKUP_DEFAULTED))
    2622              :     {
    2623     94277024 :       if (DECL_CONSTRUCTOR_P (fn))
    2624              :         i = 1;
    2625     23950834 :       else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    2626     23950834 :                && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    2627              :         i = 2;
    2628              :       else
    2629              :         i = 0;
    2630     47138512 :       if (i && len == i)
    2631              :         {
    2632     25793183 :           parmnode = chain_index (i-1, parmlist);
    2633     25793183 :           if (!reference_related_p (non_reference (TREE_VALUE (parmnode)),
    2634              :                                     ctype))
    2635      5046227 :             viable = 0;
    2636              :         }
    2637              : 
    2638              :       /* This only applies at the top level.  */
    2639     42092285 :       flags &= ~LOOKUP_DEFAULTED;
    2640              :     }
    2641              : 
    2642    832259034 :   if (! viable)
    2643    218888504 :     goto out;
    2644              : 
    2645    613370530 :   if (shortcut_bad_convs)
    2646    613243311 :     flags |= LOOKUP_SHORTCUT_BAD_CONVS;
    2647              :   else
    2648       127219 :     flags &= ~LOOKUP_SHORTCUT_BAD_CONVS;
    2649              : 
    2650              :   /* Third, for F to be a viable function, there shall exist for each
    2651              :      argument an implicit conversion sequence that converts that argument
    2652              :      to the corresponding parameter of F.  */
    2653              : 
    2654    613370530 :   parmnode = parmlist;
    2655              : 
    2656   1073541155 :   for (i = 0; i < len; ++i)
    2657              :     {
    2658    699762926 :       tree argtype, to_type;
    2659    699762926 :       tree arg;
    2660              : 
    2661    699762926 :       if (parmnode == void_list_node)
    2662              :         break;
    2663              : 
    2664    699762926 :       if (convs[i])
    2665              :         {
    2666              :           /* Already set during deduction.  */
    2667     10413288 :           parmnode = TREE_CHAIN (parmnode);
    2668     10413288 :           continue;
    2669              :         }
    2670              : 
    2671    689349638 :       if (i == 0 && first_arg != NULL_TREE)
    2672    116138100 :         arg = first_arg;
    2673              :       else
    2674    573211538 :         arg = const_cast<tree> (
    2675   1093297325 :                 (*args)[i + skip - (first_arg != NULL_TREE ? 1 : 0)]);
    2676    689349638 :       argtype = lvalue_type (arg);
    2677              : 
    2678    689349638 :       conversion *t;
    2679    689349638 :       if (parmnode)
    2680              :         {
    2681    683710399 :           tree parmtype = TREE_VALUE (parmnode);
    2682    683710399 :           if (i == 0
    2683    529301546 :               && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2684   1306867381 :               && !DECL_CONSTRUCTOR_P (fn))
    2685    116129094 :             t = build_this_conversion (fn, ctype, parmtype, argtype, arg,
    2686              :                                        flags, complain);
    2687              :           else
    2688              :             {
    2689    567581305 :               int lflags = conv_flags (i, len-skip, fn, arg, flags);
    2690    567581305 :               t = implicit_conversion (parmtype, argtype, arg,
    2691              :                                        /*c_cast_p=*/false, lflags, complain);
    2692              :             }
    2693    683710399 :           to_type = parmtype;
    2694    683710399 :           parmnode = TREE_CHAIN (parmnode);
    2695              :         }
    2696              :       else
    2697              :         {
    2698      5639239 :           t = build_identity_conv (argtype, arg);
    2699      5639239 :           t->ellipsis_p = true;
    2700      5639239 :           to_type = argtype;
    2701              :         }
    2702              : 
    2703    689349638 :       convs[i] = t;
    2704    689349638 :       if (! t)
    2705              :         {
    2706    214092399 :           viable = 0;
    2707    214092399 :           reason = arg_conversion_rejection (first_arg, i, argtype, to_type,
    2708    214092399 :                                              EXPR_LOCATION (arg));
    2709    214092399 :           break;
    2710              :         }
    2711              : 
    2712    475257239 :       if (t->bad_p)
    2713              :         {
    2714     25530776 :           viable = -1;
    2715     25530776 :           reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type,
    2716     25530776 :                                                  EXPR_LOCATION (arg));
    2717     25530776 :           if (shortcut_bad_convs)
    2718              :             break;
    2719              :         }
    2720              :     }
    2721              : 
    2722    373778229 :  out:
    2723    832259034 :   return add_candidate (candidates, fn, orig_first_arg, args, len, convs,
    2724    832259034 :                         access_path, conversion_path, viable, reason, flags);
    2725              : }
    2726              : 
    2727              : /* Create an overload candidate for the conversion function FN which will
    2728              :    be invoked for expression OBJ, producing a pointer-to-function which
    2729              :    will in turn be called with the argument list FIRST_ARG/ARGLIST,
    2730              :    and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    2731              :    passed on to implicit_conversion.
    2732              : 
    2733              :    Actually, we don't really care about FN; we care about the type it
    2734              :    converts to.  There may be multiple conversion functions that will
    2735              :    convert to that type, and we rely on build_user_type_conversion_1 to
    2736              :    choose the best one; so when we create our candidate, we record the type
    2737              :    instead of the function.  */
    2738              : 
    2739              : static struct z_candidate *
    2740       111202 : add_conv_candidate (struct z_candidate **candidates, tree fn, tree obj,
    2741              :                     const vec<tree, va_gc> *arglist,
    2742              :                     tree access_path, tree conversion_path,
    2743              :                     tsubst_flags_t complain)
    2744              : {
    2745       111202 :   tree totype = TREE_TYPE (TREE_TYPE (fn));
    2746       111202 :   int i, len, viable, flags;
    2747       111202 :   tree parmlist, parmnode;
    2748       111202 :   conversion **convs;
    2749       111202 :   struct rejection_reason *reason;
    2750              : 
    2751       222553 :   for (parmlist = totype; TREE_CODE (parmlist) != FUNCTION_TYPE; )
    2752       111351 :     parmlist = TREE_TYPE (parmlist);
    2753       111202 :   parmlist = TYPE_ARG_TYPES (parmlist);
    2754              : 
    2755       111202 :   len = vec_safe_length (arglist) + 1;
    2756       111202 :   convs = alloc_conversions (len);
    2757       111202 :   parmnode = parmlist;
    2758       111202 :   viable = 1;
    2759       111202 :   flags = LOOKUP_IMPLICIT;
    2760       111202 :   reason = NULL;
    2761              : 
    2762              :   /* Don't bother looking up the same type twice.  */
    2763       111202 :   if (*candidates && (*candidates)->fn == totype)
    2764              :     return NULL;
    2765              : 
    2766       111187 :   if (!constraints_satisfied_p (fn))
    2767              :     {
    2768            9 :       reason = constraint_failure ();
    2769            9 :       viable = 0;
    2770            9 :       return add_candidate (candidates, fn, obj, arglist, len, convs,
    2771            9 :                             access_path, conversion_path, viable, reason, flags);
    2772              :     }
    2773              : 
    2774       342839 :   for (i = 0; i < len; ++i)
    2775              :     {
    2776       231818 :       tree arg, argtype, convert_type = NULL_TREE;
    2777       231818 :       conversion *t;
    2778              : 
    2779       231818 :       if (i == 0)
    2780              :         arg = obj;
    2781              :       else
    2782       120640 :         arg = (*arglist)[i - 1];
    2783       231818 :       argtype = lvalue_type (arg);
    2784              : 
    2785       231818 :       if (i == 0)
    2786              :         {
    2787       111178 :           t = build_identity_conv (argtype, NULL_TREE);
    2788       111178 :           t = build_conv (ck_user, totype, t);
    2789              :           /* Leave the 'cand' field null; we'll figure out the conversion in
    2790              :              convert_like if this candidate is chosen.  */
    2791       111178 :           convert_type = totype;
    2792              :         }
    2793       120640 :       else if (parmnode == void_list_node)
    2794              :         break;
    2795       120544 :       else if (parmnode)
    2796              :         {
    2797       120535 :           t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg,
    2798              :                                    /*c_cast_p=*/false, flags, complain);
    2799       120535 :           convert_type = TREE_VALUE (parmnode);
    2800              :         }
    2801              :       else
    2802              :         {
    2803            9 :           t = build_identity_conv (argtype, arg);
    2804            9 :           t->ellipsis_p = true;
    2805            9 :           convert_type = argtype;
    2806              :         }
    2807              : 
    2808       231722 :       convs[i] = t;
    2809       231722 :       if (! t)
    2810              :         break;
    2811              : 
    2812       231661 :       if (t->bad_p)
    2813              :         {
    2814           17 :           viable = -1;
    2815           51 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, arg, convert_type,
    2816           17 :                                                  EXPR_LOCATION (arg));
    2817              :         }
    2818              : 
    2819       231661 :       if (i == 0)
    2820       111178 :         continue;
    2821              : 
    2822       120483 :       if (parmnode)
    2823       120474 :         parmnode = TREE_CHAIN (parmnode);
    2824              :     }
    2825              : 
    2826       111178 :   if (i < len
    2827       111178 :       || ! sufficient_parms_p (parmnode))
    2828              :     {
    2829          181 :       int remaining = remaining_arguments (parmnode);
    2830          181 :       viable = 0;
    2831          181 :       reason = arity_rejection (NULL_TREE, i + remaining, len);
    2832              :     }
    2833              : 
    2834       111178 :   return add_candidate (candidates, totype, obj, arglist, len, convs,
    2835       111178 :                         access_path, conversion_path, viable, reason, flags);
    2836              : }
    2837              : 
    2838              : static void
    2839     11473514 : build_builtin_candidate (struct z_candidate **candidates, tree fnname,
    2840              :                          tree type1, tree type2, const vec<tree,va_gc> &args,
    2841              :                          tree *argtypes, int flags, tsubst_flags_t complain)
    2842              : {
    2843     11473514 :   conversion *t;
    2844     11473514 :   conversion **convs;
    2845     11473514 :   size_t num_convs;
    2846     11473514 :   int viable = 1;
    2847     11473514 :   tree types[2];
    2848     11473514 :   struct rejection_reason *reason = NULL;
    2849              : 
    2850     11473514 :   types[0] = type1;
    2851     11473514 :   types[1] = type2;
    2852              : 
    2853     11473514 :   num_convs = args.length ();
    2854     11473514 :   convs = alloc_conversions (num_convs);
    2855              : 
    2856              :   /* TRUTH_*_EXPR do "contextual conversion to bool", which means explicit
    2857              :      conversion ops are allowed.  We handle that here by just checking for
    2858              :      boolean_type_node because other operators don't ask for it.  COND_EXPR
    2859              :      also does contextual conversion to bool for the first operand, but we
    2860              :      handle that in build_conditional_expr, and type1 here is operand 2.  */
    2861     11473514 :   if (type1 != boolean_type_node)
    2862     10939711 :     flags |= LOOKUP_ONLYCONVERTING;
    2863              : 
    2864     33729232 :   for (unsigned i = 0; i < 2 && i < num_convs; ++i)
    2865              :     {
    2866     22255718 :       t = implicit_conversion (types[i], argtypes[i], args[i],
    2867              :                                /*c_cast_p=*/false, flags, complain);
    2868     22255718 :       if (! t)
    2869              :         {
    2870      1784723 :           viable = 0;
    2871              :           /* We need something for printing the candidate.  */
    2872      1784723 :           t = build_identity_conv (types[i], NULL_TREE);
    2873      1784723 :           reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i],
    2874      1784723 :                                              types[i], EXPR_LOCATION (args[i]));
    2875              :         }
    2876     20470995 :       else if (t->bad_p)
    2877              :         {
    2878          174 :           viable = 0;
    2879          174 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, args[i],
    2880              :                                                  types[i],
    2881          174 :                                                  EXPR_LOCATION (args[i]));
    2882              :         }
    2883     22255718 :       convs[i] = t;
    2884              :     }
    2885              : 
    2886              :   /* For COND_EXPR we rearranged the arguments; undo that now.  */
    2887     11473514 :   if (num_convs == 3)
    2888              :     {
    2889          144 :       convs[2] = convs[1];
    2890          144 :       convs[1] = convs[0];
    2891          144 :       t = implicit_conversion (boolean_type_node, argtypes[2], args[2],
    2892              :                                /*c_cast_p=*/false, flags,
    2893              :                                complain);
    2894          144 :       if (t)
    2895          144 :         convs[0] = t;
    2896              :       else
    2897              :         {
    2898            0 :           viable = 0;
    2899            0 :           reason = arg_conversion_rejection (NULL_TREE, 0, argtypes[2],
    2900              :                                              boolean_type_node,
    2901            0 :                                              EXPR_LOCATION (args[2]));
    2902              :         }
    2903              :     }
    2904              : 
    2905     11473514 :   add_candidate (candidates, fnname, /*first_arg=*/NULL_TREE, /*args=*/NULL,
    2906              :                  num_convs, convs,
    2907              :                  /*access_path=*/NULL_TREE,
    2908              :                  /*conversion_path=*/NULL_TREE,
    2909              :                  viable, reason, flags);
    2910     11473514 : }
    2911              : 
    2912              : static bool
    2913            9 : is_complete (tree t)
    2914              : {
    2915            9 :   return COMPLETE_TYPE_P (complete_type (t));
    2916              : }
    2917              : 
    2918              : /* Returns nonzero if TYPE is a promoted arithmetic type.  */
    2919              : 
    2920              : static bool
    2921         2867 : promoted_arithmetic_type_p (tree type)
    2922              : {
    2923              :   /* [over.built]
    2924              : 
    2925              :      In this section, the term promoted integral type is used to refer
    2926              :      to those integral types which are preserved by integral promotion
    2927              :      (including e.g.  int and long but excluding e.g.  char).
    2928              :      Similarly, the term promoted arithmetic type refers to promoted
    2929              :      integral types plus floating types.  */
    2930         2867 :   return ((CP_INTEGRAL_TYPE_P (type)
    2931          204 :            && same_type_p (type_promotes_to (type), type))
    2932         2867 :           || SCALAR_FLOAT_TYPE_P (type));
    2933              : }
    2934              : 
    2935              : /* Create any builtin operator overload candidates for the operator in
    2936              :    question given the converted operand types TYPE1 and TYPE2.  The other
    2937              :    args are passed through from add_builtin_candidates to
    2938              :    build_builtin_candidate.
    2939              : 
    2940              :    TYPE1 and TYPE2 may not be permissible, and we must filter them.
    2941              :    If CODE is requires candidates operands of the same type of the kind
    2942              :    of which TYPE1 and TYPE2 are, we add both candidates
    2943              :    CODE (TYPE1, TYPE1) and CODE (TYPE2, TYPE2).  */
    2944              : 
    2945              : static void
    2946     16112860 : add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
    2947              :                        enum tree_code code2, tree fnname, tree type1,
    2948              :                        tree type2, vec<tree,va_gc> &args, tree *argtypes,
    2949              :                        int flags, tsubst_flags_t complain)
    2950              : {
    2951     16112860 :   switch (code)
    2952              :     {
    2953           21 :     case POSTINCREMENT_EXPR:
    2954           21 :     case POSTDECREMENT_EXPR:
    2955           21 :       args[1] = integer_zero_node;
    2956           21 :       type2 = integer_type_node;
    2957           21 :       break;
    2958              :     default:
    2959              :       break;
    2960              :     }
    2961              : 
    2962     16112860 :   switch (code)
    2963              :     {
    2964              : 
    2965              : /* 4 For every pair (T, VQ), where T is an arithmetic type other than bool,
    2966              :      and  VQ  is  either  volatile or empty, there exist candidate operator
    2967              :      functions of the form
    2968              :              VQ T&   operator++(VQ T&);
    2969              :              T       operator++(VQ T&, int);
    2970              :    5 For every pair (T, VQ), where T is an arithmetic type other than bool,
    2971              :      and VQ is either volatile or empty, there exist candidate operator
    2972              :      functions of the form
    2973              :              VQ T&   operator--(VQ T&);
    2974              :              T       operator--(VQ T&, int);
    2975              :    6 For every pair (T, VQ), where T is a cv-qualified or cv-unqualified object
    2976              :      type, and VQ is either volatile or empty, there exist candidate operator
    2977              :      functions of the form
    2978              :              T*VQ&   operator++(T*VQ&);
    2979              :              T*VQ&   operator--(T*VQ&);
    2980              :              T*      operator++(T*VQ&, int);
    2981              :              T*      operator--(T*VQ&, int);  */
    2982              : 
    2983           18 :     case POSTDECREMENT_EXPR:
    2984           18 :     case PREDECREMENT_EXPR:
    2985           18 :       if (TREE_CODE (type1) == BOOLEAN_TYPE)
    2986              :         return;
    2987              :       /* FALLTHRU */
    2988           39 :     case POSTINCREMENT_EXPR:
    2989           39 :     case PREINCREMENT_EXPR:
    2990              :       /* P0002R1, Remove deprecated operator++(bool) added "other than bool"
    2991              :          to p4.  */
    2992           39 :       if (TREE_CODE (type1) == BOOLEAN_TYPE && cxx_dialect >= cxx17)
    2993              :         return;
    2994           33 :       if (ARITHMETIC_TYPE_P (type1) || TYPE_PTROB_P (type1))
    2995              :         {
    2996           24 :           type1 = build_reference_type (type1);
    2997           24 :           break;
    2998              :         }
    2999              :       return;
    3000              : 
    3001              : /* 7 For every cv-qualified or cv-unqualified object type T, there
    3002              :      exist candidate operator functions of the form
    3003              : 
    3004              :              T&      operator*(T*);
    3005              : 
    3006              : 
    3007              :    8 For every function type T that does not have cv-qualifiers or
    3008              :      a ref-qualifier, there exist candidate operator functions of the form
    3009              :              T&      operator*(T*);  */
    3010              : 
    3011       107410 :     case INDIRECT_REF:
    3012       107410 :       if (TYPE_PTR_P (type1)
    3013       107410 :           && (TYPE_PTROB_P (type1)
    3014           12 :               || TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE))
    3015              :         break;
    3016              :       return;
    3017              : 
    3018              : /* 9 For every type T, there exist candidate operator functions of the form
    3019              :              T*      operator+(T*);
    3020              : 
    3021              :    10 For every floating-point or promoted integral type T, there exist
    3022              :       candidate operator functions of the form
    3023              :              T       operator+(T);
    3024              :              T       operator-(T);  */
    3025              : 
    3026          320 :     case UNARY_PLUS_EXPR: /* unary + */
    3027          320 :       if (TYPE_PTR_P (type1))
    3028              :         break;
    3029              :       /* FALLTHRU */
    3030       189187 :     case NEGATE_EXPR:
    3031       189187 :       if (ARITHMETIC_TYPE_P (type1))
    3032              :         break;
    3033              :       return;
    3034              : 
    3035              : /* 11 For every promoted integral type T,  there  exist  candidate  operator
    3036              :       functions of the form
    3037              :              T       operator~(T);  */
    3038              : 
    3039       148346 :     case BIT_NOT_EXPR:
    3040       148346 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1))
    3041              :         break;
    3042              :       return;
    3043              : 
    3044              : /* 12 For every quintuple (C1, C2, T, CV1, CV2), where C2 is a class type, C1
    3045              :      is the same type as C2 or is a derived class of C2, and T is an object
    3046              :      type or a function type there exist candidate operator functions of the
    3047              :      form
    3048              :              CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
    3049              :      where CV12 is the union of CV1 and CV2.  */
    3050              : 
    3051           28 :     case MEMBER_REF:
    3052           28 :       if (TYPE_PTR_P (type1) && TYPE_PTRMEM_P (type2))
    3053              :         {
    3054           28 :           tree c1 = TREE_TYPE (type1);
    3055           28 :           tree c2 = TYPE_PTRMEM_CLASS_TYPE (type2);
    3056              : 
    3057           25 :           if (CLASS_TYPE_P (c1) && DERIVED_FROM_P (c2, c1)
    3058           50 :               && (TYPE_PTRMEMFUNC_P (type2)
    3059            9 :                   || is_complete (TYPE_PTRMEM_POINTED_TO_TYPE (type2))))
    3060              :             break;
    3061              :         }
    3062              :       return;
    3063              : 
    3064              : /* 13 For every pair of types L and R, where each of L and R is a floating-point
    3065              :       or promoted integral type, there exist candidate operator functions of the
    3066              :       form
    3067              :              LR      operator*(L, R);
    3068              :              LR      operator/(L, R);
    3069              :              LR      operator+(L, R);
    3070              :              LR      operator-(L, R);
    3071              :              bool    operator<(L, R);
    3072              :              bool    operator>(L, R);
    3073              :              bool    operator<=(L, R);
    3074              :              bool    operator>=(L, R);
    3075              :              bool    operator==(L, R);
    3076              :              bool    operator!=(L, R);
    3077              :       where  LR  is  the  result of the usual arithmetic conversions between
    3078              :       types L and R.
    3079              : 
    3080              :    14 For every integral type T there exists a candidate operator function of
    3081              :       the form
    3082              : 
    3083              :        std::strong_ordering operator<=>(T, T);
    3084              : 
    3085              :    15 For every pair of floating-point types L and R, there exists a candidate
    3086              :       operator function of the form
    3087              : 
    3088              :        std::partial_ordering operator<=>(L, R);
    3089              : 
    3090              :    16 For every cv-qualified or cv-unqualified object type T there exist
    3091              :       candidate operator functions of the form
    3092              :              T*      operator+(T*, std::ptrdiff_t);
    3093              :              T&      operator[](T*, std::ptrdiff_t);
    3094              :              T*      operator-(T*, std::ptrdiff_t);
    3095              :              T*      operator+(std::ptrdiff_t, T*);
    3096              :              T&      operator[](std::ptrdiff_t, T*);
    3097              : 
    3098              :    17 For every T, where T is a pointer to object type, there exist candidate
    3099              :       operator functions of the form
    3100              :              std::ptrdiff_t operator-(T, T);
    3101              : 
    3102              :    18 For every T, where T is an enumeration type or a pointer type, there
    3103              :       exist candidate operator functions of the form
    3104              :              bool    operator<(T, T);
    3105              :              bool    operator>(T, T);
    3106              :              bool    operator<=(T, T);
    3107              :              bool    operator>=(T, T);
    3108              :              bool    operator==(T, T);
    3109              :              bool    operator!=(T, T);
    3110              :              R       operator<=>(T, T);
    3111              : 
    3112              :       where R is the result type specified in [expr.spaceship].
    3113              : 
    3114              :    19 For every T, where T is a pointer-to-member type or std::nullptr_t,
    3115              :       there exist candidate operator functions of the form
    3116              :              bool    operator==(T, T);
    3117              :              bool    operator!=(T, T);  */
    3118              : 
    3119       195938 :     case MINUS_EXPR:
    3120       195938 :       if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
    3121              :         break;
    3122           13 :       if (TYPE_PTROB_P (type1)
    3123       195924 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3124              :         {
    3125            4 :           type2 = ptrdiff_type_node;
    3126            4 :           break;
    3127              :         }
    3128              :       /* FALLTHRU */
    3129       828686 :     case MULT_EXPR:
    3130       828686 :     case TRUNC_DIV_EXPR:
    3131       828686 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3132              :         break;
    3133              :       return;
    3134              : 
    3135              :       /* This isn't exactly what's specified above for operator<=>, but it's
    3136              :          close enough.  In particular, we don't care about the return type
    3137              :          specified above; it doesn't participate in overload resolution and it
    3138              :          doesn't affect the semantics of the built-in operator.  */
    3139      9321215 :     case SPACESHIP_EXPR:
    3140      9321215 :     case EQ_EXPR:
    3141      9321215 :     case NE_EXPR:
    3142       218785 :       if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3143      9540000 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)))
    3144              :         break;
    3145      9321181 :       if (NULLPTR_TYPE_P (type1) && NULLPTR_TYPE_P (type2))
    3146              :         break;
    3147      9321175 :       if (TYPE_PTRMEM_P (type1) && null_ptr_cst_p (args[1]))
    3148              :         {
    3149              :           type2 = type1;
    3150              :           break;
    3151              :         }
    3152      9321172 :       if (TYPE_PTRMEM_P (type2) && null_ptr_cst_p (args[0]))
    3153              :         {
    3154              :           type1 = type2;
    3155              :           break;
    3156              :         }
    3157              :       /* Fall through.  */
    3158      9984813 :     case LT_EXPR:
    3159      9984813 :     case GT_EXPR:
    3160      9984813 :     case LE_EXPR:
    3161      9984813 :     case GE_EXPR:
    3162      9984813 :     case MAX_EXPR:
    3163      9984813 :     case MIN_EXPR:
    3164      9984813 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3165              :         break;
    3166      8181370 :       if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3167              :         break;
    3168      8177692 :       if (TREE_CODE (type1) == ENUMERAL_TYPE
    3169      6434812 :           && TREE_CODE (type2) == ENUMERAL_TYPE)
    3170              :         break;
    3171      3038080 :       if (TYPE_PTR_P (type1)
    3172      3038080 :           && null_ptr_cst_p (args[1]))
    3173              :         {
    3174              :           type2 = type1;
    3175              :           break;
    3176              :         }
    3177      3038061 :       if (null_ptr_cst_p (args[0])
    3178      3038061 :           && TYPE_PTR_P (type2))
    3179              :         {
    3180              :           type1 = type2;
    3181              :           break;
    3182              :         }
    3183              :       return;
    3184              : 
    3185       214950 :     case PLUS_EXPR:
    3186       214950 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3187              :         break;
    3188              :       /* FALLTHRU */
    3189       162621 :     case ARRAY_REF:
    3190       162621 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && TYPE_PTROB_P (type2))
    3191              :         {
    3192            6 :           type1 = ptrdiff_type_node;
    3193            6 :           break;
    3194              :         }
    3195       162615 :       if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3196              :         {
    3197        35217 :           type2 = ptrdiff_type_node;
    3198        35217 :           break;
    3199              :         }
    3200              :       return;
    3201              : 
    3202              : /* 18For  every pair of promoted integral types L and R, there exist candi-
    3203              :      date operator functions of the form
    3204              :              LR      operator%(L, R);
    3205              :              LR      operator&(L, R);
    3206              :              LR      operator^(L, R);
    3207              :              LR      operator|(L, R);
    3208              :              L       operator<<(L, R);
    3209              :              L       operator>>(L, R);
    3210              :      where LR is the result of the  usual  arithmetic  conversions  between
    3211              :      types L and R.  */
    3212              : 
    3213      2904032 :     case TRUNC_MOD_EXPR:
    3214      2904032 :     case BIT_AND_EXPR:
    3215      2904032 :     case BIT_IOR_EXPR:
    3216      2904032 :     case BIT_XOR_EXPR:
    3217      2904032 :     case LSHIFT_EXPR:
    3218      2904032 :     case RSHIFT_EXPR:
    3219      2904032 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3220              :         break;
    3221              :       return;
    3222              : 
    3223              : /* 19For  every  triple  L, VQ, R), where L is an arithmetic or enumeration
    3224              :      type, VQ is either volatile or empty, and R is a  promoted  arithmetic
    3225              :      type, there exist candidate operator functions of the form
    3226              :              VQ L&   operator=(VQ L&, R);
    3227              :              VQ L&   operator*=(VQ L&, R);
    3228              :              VQ L&   operator/=(VQ L&, R);
    3229              :              VQ L&   operator+=(VQ L&, R);
    3230              :              VQ L&   operator-=(VQ L&, R);
    3231              : 
    3232              :    20For  every  pair T, VQ), where T is any type and VQ is either volatile
    3233              :      or empty, there exist candidate operator functions of the form
    3234              :              T*VQ&   operator=(T*VQ&, T*);
    3235              : 
    3236              :    21For every pair T, VQ), where T is a pointer to member type and  VQ  is
    3237              :      either  volatile or empty, there exist candidate operator functions of
    3238              :      the form
    3239              :              VQ T&   operator=(VQ T&, T);
    3240              : 
    3241              :    22For every triple  T,  VQ,  I),  where  T  is  a  cv-qualified  or  cv-
    3242              :      unqualified  complete object type, VQ is either volatile or empty, and
    3243              :      I is a promoted integral type, there exist  candidate  operator  func-
    3244              :      tions of the form
    3245              :              T*VQ&   operator+=(T*VQ&, I);
    3246              :              T*VQ&   operator-=(T*VQ&, I);
    3247              : 
    3248              :    23For  every  triple  L,  VQ,  R), where L is an integral or enumeration
    3249              :      type, VQ is either volatile or empty, and R  is  a  promoted  integral
    3250              :      type, there exist candidate operator functions of the form
    3251              : 
    3252              :              VQ L&   operator%=(VQ L&, R);
    3253              :              VQ L&   operator<<=(VQ L&, R);
    3254              :              VQ L&   operator>>=(VQ L&, R);
    3255              :              VQ L&   operator&=(VQ L&, R);
    3256              :              VQ L&   operator^=(VQ L&, R);
    3257              :              VQ L&   operator|=(VQ L&, R);  */
    3258              : 
    3259      1688140 :     case MODIFY_EXPR:
    3260      1688140 :       switch (code2)
    3261              :         {
    3262        98836 :         case PLUS_EXPR:
    3263        98836 :         case MINUS_EXPR:
    3264        98836 :           if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3265              :             {
    3266            0 :               type2 = ptrdiff_type_node;
    3267            0 :               break;
    3268              :             }
    3269              :           /* FALLTHRU */
    3270        98841 :         case MULT_EXPR:
    3271        98841 :         case TRUNC_DIV_EXPR:
    3272        98841 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3273              :             break;
    3274              :           return;
    3275              : 
    3276      1589299 :         case TRUNC_MOD_EXPR:
    3277      1589299 :         case BIT_AND_EXPR:
    3278      1589299 :         case BIT_IOR_EXPR:
    3279      1589299 :         case BIT_XOR_EXPR:
    3280      1589299 :         case LSHIFT_EXPR:
    3281      1589299 :         case RSHIFT_EXPR:
    3282      1589299 :           if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3283              :             break;
    3284              :           return;
    3285              : 
    3286            0 :         case NOP_EXPR:
    3287            0 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3288              :             break;
    3289            0 :           if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3290            0 :               || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3291            0 :               || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3292            0 :               || ((TYPE_PTRMEMFUNC_P (type1)
    3293            0 :                    || TYPE_PTR_P (type1))
    3294            0 :                   && null_ptr_cst_p (args[1])))
    3295              :             {
    3296              :               type2 = type1;
    3297              :               break;
    3298              :             }
    3299              :           return;
    3300              : 
    3301            0 :         default:
    3302            0 :           gcc_unreachable ();
    3303              :         }
    3304      1356067 :       type1 = build_reference_type (type1);
    3305      1356067 :       break;
    3306              : 
    3307         2686 :     case COND_EXPR:
    3308              :       /* [over.built]
    3309              : 
    3310              :          For every pair of promoted arithmetic types L and R, there
    3311              :          exist candidate operator functions of the form
    3312              : 
    3313              :          LR operator?(bool, L, R);
    3314              : 
    3315              :          where LR is the result of the usual arithmetic conversions
    3316              :          between types L and R.
    3317              : 
    3318              :          For every type T, where T is a pointer or pointer-to-member
    3319              :          type, there exist candidate operator functions of the form T
    3320              :          operator?(bool, T, T);  */
    3321              : 
    3322         2686 :       if (promoted_arithmetic_type_p (type1)
    3323         2686 :           && promoted_arithmetic_type_p (type2))
    3324              :         /* That's OK.  */
    3325              :         break;
    3326              : 
    3327              :       /* Otherwise, the types should be pointers.  */
    3328         2663 :       if (!((TYPE_PTR_OR_PTRMEM_P (type1) || null_ptr_cst_p (args[0]))
    3329          337 :             && (TYPE_PTR_OR_PTRMEM_P (type2) || null_ptr_cst_p (args[1]))))
    3330         2542 :         return;
    3331              : 
    3332              :       /* We don't check that the two types are the same; the logic
    3333              :          below will actually create two candidates; one in which both
    3334              :          parameter types are TYPE1, and one in which both parameter
    3335              :          types are TYPE2.  */
    3336              :       break;
    3337              : 
    3338            3 :     case REALPART_EXPR:
    3339            3 :     case IMAGPART_EXPR:
    3340            3 :       if (ARITHMETIC_TYPE_P (type1))
    3341              :         break;
    3342              :       return;
    3343              : 
    3344            0 :     default:
    3345            0 :       gcc_unreachable ();
    3346              :     }
    3347              : 
    3348              :   /* Make sure we don't create builtin candidates with dependent types.  */
    3349     10939587 :   bool u1 = uses_template_parms (type1);
    3350     10939587 :   bool u2 = type2 ? uses_template_parms (type2) : false;
    3351     10939574 :   if (u1 || u2)
    3352              :     {
    3353              :       /* Try to recover if one of the types is non-dependent.  But if
    3354              :          there's only one type, there's nothing we can do.  */
    3355           19 :       if (!type2)
    3356              :         return;
    3357              :       /* And we lose if both are dependent.  */
    3358           16 :       if (u1 && u2)
    3359              :         return;
    3360              :       /* Or if they have different forms.  */
    3361            9 :       if (TREE_CODE (type1) != TREE_CODE (type2))
    3362              :         return;
    3363              : 
    3364            9 :       if (u1 && !u2)
    3365              :         type1 = type2;
    3366            6 :       else if (u2 && !u1)
    3367     10939577 :         type2 = type1;
    3368              :     }
    3369              : 
    3370              :   /* If we're dealing with two pointer types or two enumeral types,
    3371              :      we need candidates for both of them.  */
    3372     10720334 :   if (type2 && !same_type_p (type1, type2)
    3373      1808432 :       && TREE_CODE (type1) == TREE_CODE (type2)
    3374     11356436 :       && (TYPE_REF_P (type1)
    3375       416859 :           || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3376       416748 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3377       416730 :           || TYPE_PTRMEMFUNC_P (type1)
    3378       416730 :           || MAYBE_CLASS_TYPE_P (type1)
    3379       416730 :           || TREE_CODE (type1) == ENUMERAL_TYPE))
    3380              :     {
    3381          223 :       if (TYPE_PTR_OR_PTRMEM_P (type1))
    3382              :         {
    3383          129 :           tree cptype = composite_pointer_type (input_location,
    3384              :                                                 type1, type2,
    3385              :                                                 error_mark_node,
    3386              :                                                 error_mark_node,
    3387              :                                                 CPO_CONVERSION,
    3388              :                                                 tf_none);
    3389          129 :           if (cptype != error_mark_node)
    3390              :             {
    3391           89 :               build_builtin_candidate
    3392           89 :                 (candidates, fnname, cptype, cptype, args, argtypes,
    3393              :                  flags, complain);
    3394           89 :               return;
    3395              :             }
    3396              :         }
    3397              : 
    3398          134 :       build_builtin_candidate
    3399          134 :         (candidates, fnname, type1, type1, args, argtypes, flags, complain);
    3400          134 :       build_builtin_candidate
    3401          134 :         (candidates, fnname, type2, type2, args, argtypes, flags, complain);
    3402          134 :       return;
    3403              :     }
    3404              : 
    3405     10939354 :   build_builtin_candidate
    3406     10939354 :     (candidates, fnname, type1, type2, args, argtypes, flags, complain);
    3407              : }
    3408              : 
    3409              : tree
    3410    884593444 : type_decays_to (tree type)
    3411              : {
    3412    884593444 :   if (TREE_CODE (type) == ARRAY_TYPE)
    3413      8310158 :     return build_pointer_type (TREE_TYPE (type));
    3414    876283286 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    3415        31503 :     return build_pointer_type (type);
    3416              :   return type;
    3417              : }
    3418              : 
    3419              : /* There are three conditions of builtin candidates:
    3420              : 
    3421              :    1) bool-taking candidates.  These are the same regardless of the input.
    3422              :    2) pointer-pair taking candidates.  These are generated for each type
    3423              :       one of the input types converts to.
    3424              :    3) arithmetic candidates.  According to the standard, we should generate
    3425              :       all of these, but I'm trying not to...
    3426              : 
    3427              :    Here we generate a superset of the possible candidates for this particular
    3428              :    case.  That is a subset of the full set the standard defines, plus some
    3429              :    other cases which the standard disallows. add_builtin_candidate will
    3430              :    filter out the invalid set.  */
    3431              : 
    3432              : static void
    3433     31989483 : add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
    3434              :                         enum tree_code code2, tree fnname,
    3435              :                         vec<tree, va_gc> *argv,
    3436              :                         int flags, tsubst_flags_t complain)
    3437              : {
    3438     31989483 :   int ref1;
    3439     31989483 :   int enum_p = 0;
    3440     31989483 :   tree type, argtypes[3], t;
    3441              :   /* TYPES[i] is the set of possible builtin-operator parameter types
    3442              :      we will consider for the Ith argument.  */
    3443     31989483 :   vec<tree, va_gc> *types[2];
    3444     31989483 :   unsigned ix;
    3445     31989483 :   vec<tree, va_gc> &args = *argv;
    3446     31989483 :   unsigned len = args.length ();
    3447              : 
    3448     89970499 :   for (unsigned i = 0; i < len; ++i)
    3449              :     {
    3450     57981016 :       if (args[i])
    3451     57981016 :         argtypes[i] = unlowered_expr_type (args[i]);
    3452              :       else
    3453            0 :         argtypes[i] = NULL_TREE;
    3454              :     }
    3455              : 
    3456     31989483 :   switch (code)
    3457              :     {
    3458              : /* 4 For every pair T, VQ), where T is an arithmetic or  enumeration  type,
    3459              :      and  VQ  is  either  volatile or empty, there exist candidate operator
    3460              :      functions of the form
    3461              :                  VQ T&   operator++(VQ T&);  */
    3462              : 
    3463              :     case POSTINCREMENT_EXPR:
    3464              :     case PREINCREMENT_EXPR:
    3465              :     case POSTDECREMENT_EXPR:
    3466              :     case PREDECREMENT_EXPR:
    3467              :     case MODIFY_EXPR:
    3468              :       ref1 = 1;
    3469              :       break;
    3470              : 
    3471              : /* 24There also exist candidate operator functions of the form
    3472              :              bool    operator!(bool);
    3473              :              bool    operator&&(bool, bool);
    3474              :              bool    operator||(bool, bool);  */
    3475              : 
    3476       472067 :     case TRUTH_NOT_EXPR:
    3477       472067 :       build_builtin_candidate
    3478       472067 :         (candidates, fnname, boolean_type_node,
    3479              :          NULL_TREE, args, argtypes, flags, complain);
    3480     19639163 :       return;
    3481              : 
    3482        61736 :     case TRUTH_ORIF_EXPR:
    3483        61736 :     case TRUTH_ANDIF_EXPR:
    3484        61736 :       build_builtin_candidate
    3485        61736 :         (candidates, fnname, boolean_type_node,
    3486              :          boolean_type_node, args, argtypes, flags, complain);
    3487        61736 :       return;
    3488              : 
    3489              :     case ADDR_EXPR:
    3490              :     case COMPOUND_EXPR:
    3491              :     case COMPONENT_REF:
    3492              :     case CO_AWAIT_EXPR:
    3493              :       return;
    3494              : 
    3495      9446581 :     case COND_EXPR:
    3496      9446581 :     case EQ_EXPR:
    3497      9446581 :     case NE_EXPR:
    3498      9446581 :     case LT_EXPR:
    3499      9446581 :     case LE_EXPR:
    3500      9446581 :     case GT_EXPR:
    3501      9446581 :     case GE_EXPR:
    3502      9446581 :     case SPACESHIP_EXPR:
    3503      9446581 :       enum_p = 1;
    3504              :       /* Fall through.  */
    3505              : 
    3506              :     default:
    3507              :       ref1 = 0;
    3508              :     }
    3509              : 
    3510     29361774 :   types[0] = make_tree_vector ();
    3511     29361774 :   types[1] = make_tree_vector ();
    3512              : 
    3513     29361774 :   if (len == 3)
    3514          685 :     len = 2;
    3515     55370121 :   for (unsigned i = 0; i < len; ++i)
    3516              :     {
    3517     42547734 :       if (MAYBE_CLASS_TYPE_P (argtypes[i]))
    3518              :         {
    3519     20772440 :           tree convs;
    3520              : 
    3521     20772440 :           if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
    3522              :             return;
    3523              : 
    3524     14567528 :           convs = lookup_conversions (argtypes[i]);
    3525              : 
    3526     14567528 :           if (code == COND_EXPR)
    3527              :             {
    3528         1200 :               if (lvalue_p (args[i]))
    3529          877 :                 vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3530              : 
    3531         1200 :               vec_safe_push (types[i], TYPE_MAIN_VARIANT (argtypes[i]));
    3532              :             }
    3533              : 
    3534     14566328 :           else if (! convs)
    3535              :             return;
    3536              : 
    3537     10389027 :           for (; convs; convs = TREE_CHAIN (convs))
    3538              :             {
    3539      6155974 :               type = TREE_TYPE (convs);
    3540              : 
    3541      7607724 :               if (i == 0 && ref1
    3542      6155974 :                   && (!TYPE_REF_P (type)
    3543         1319 :                       || CP_TYPE_CONST_P (TREE_TYPE (type))))
    3544      1451750 :                 continue;
    3545              : 
    3546      4704224 :               if (code == COND_EXPR && TYPE_REF_P (type))
    3547           23 :                 vec_safe_push (types[i], type);
    3548              : 
    3549      4704224 :               type = non_reference (type);
    3550      4704224 :               if (i != 0 || ! ref1)
    3551              :                 {
    3552      4704185 :                   type = cv_unqualified (type_decays_to (type));
    3553      4704185 :                   if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
    3554          328 :                     vec_safe_push (types[i], type);
    3555      4704185 :                   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3556      2656727 :                     type = type_promotes_to (type);
    3557              :                 }
    3558              : 
    3559      4704224 :               if (! vec_member (type, types[i]))
    3560      4700407 :                 vec_safe_push (types[i], type);
    3561              :             }
    3562              :         }
    3563              :       else
    3564              :         {
    3565     21775294 :           if (code == COND_EXPR && lvalue_p (args[i]))
    3566           88 :             vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3567     21775294 :           type = non_reference (argtypes[i]);
    3568     21775294 :           if (i != 0 || ! ref1)
    3569              :             {
    3570     20087241 :               type = cv_unqualified (type_decays_to (type));
    3571     20087241 :               if (enum_p && UNSCOPED_ENUM_P (type))
    3572      2237130 :                 vec_safe_push (types[i], type);
    3573     20087241 :               if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3574      9100495 :                 type = type_promotes_to (type);
    3575              :             }
    3576     21775294 :           vec_safe_push (types[i], type);
    3577              :         }
    3578              :     }
    3579              : 
    3580              :   /* Run through the possible parameter types of both arguments,
    3581              :      creating candidates with those parameter types.  */
    3582     26374287 :   FOR_EACH_VEC_ELT_REVERSE (*(types[0]), ix, t)
    3583              :     {
    3584     13551900 :       unsigned jx;
    3585     13551900 :       tree u;
    3586              : 
    3587     13551900 :       if (!types[1]->is_empty ())
    3588     29219734 :         FOR_EACH_VEC_ELT_REVERSE (*(types[1]), jx, u)
    3589     15667834 :           add_builtin_candidate
    3590     15667834 :             (candidates, code, code2, fnname, t,
    3591              :              u, args, argtypes, flags, complain);
    3592              :       else
    3593       445026 :         add_builtin_candidate
    3594       445026 :           (candidates, code, code2, fnname, t,
    3595              :            NULL_TREE, args, argtypes, flags, complain);
    3596              :     }
    3597              : 
    3598     12822387 :   release_tree_vector (types[0]);
    3599     12822387 :   release_tree_vector (types[1]);
    3600              : }
    3601              : 
    3602              : 
    3603              : /* If TMPL can be successfully instantiated as indicated by
    3604              :    EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
    3605              : 
    3606              :    TMPL is the template.  EXPLICIT_TARGS are any explicit template
    3607              :    arguments.  ARGLIST is the arguments provided at the call-site.
    3608              :    This does not change ARGLIST.  The RETURN_TYPE is the desired type
    3609              :    for conversion operators.  If OBJ is NULL_TREE, FLAGS and CTYPE are
    3610              :    as for add_function_candidate.  If an OBJ is supplied, FLAGS and
    3611              :    CTYPE are ignored, and OBJ is as for add_conv_candidate.
    3612              : 
    3613              :    SHORTCUT_BAD_CONVS is as in add_function_candidate.  */
    3614              : 
    3615              : static struct z_candidate*
    3616    771413681 : add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
    3617              :                              tree ctype, tree explicit_targs, tree first_arg,
    3618              :                              const vec<tree, va_gc> *arglist, tree return_type,
    3619              :                              tree access_path, tree conversion_path,
    3620              :                              int flags, tree obj, unification_kind_t strict,
    3621              :                              bool shortcut_bad_convs, tsubst_flags_t complain)
    3622              : {
    3623    771413681 :   int ntparms = DECL_NTPARMS (tmpl);
    3624    771413681 :   tree targs = make_tree_vec (ntparms);
    3625    771413681 :   unsigned int len = vec_safe_length (arglist);
    3626    771413681 :   unsigned int nargs = (first_arg == NULL_TREE ? 0 : 1) + len;
    3627    771413681 :   unsigned int skip_without_in_chrg = 0;
    3628    771413681 :   tree first_arg_without_in_chrg = first_arg;
    3629    771413681 :   tree *args_without_in_chrg;
    3630    771413681 :   unsigned int nargs_without_in_chrg;
    3631    771413681 :   unsigned int ia, ix;
    3632    771413681 :   tree arg;
    3633    771413681 :   struct z_candidate *cand;
    3634    771413681 :   tree fn;
    3635    771413681 :   struct rejection_reason *reason = NULL;
    3636    771413681 :   int errs;
    3637    771413681 :   conversion **convs = NULL;
    3638              : 
    3639              :   /* We don't do deduction on the in-charge parameter, the VTT
    3640              :      parameter or 'this'.  */
    3641    771413681 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (tmpl))
    3642              :     {
    3643     70363485 :       if (first_arg_without_in_chrg != NULL_TREE)
    3644              :         first_arg_without_in_chrg = NULL_TREE;
    3645           12 :       else if (return_type && strict == DEDUCE_CALL)
    3646              :         /* We're deducing for a call to the result of a template conversion
    3647              :            function, so the args don't contain 'this'; leave them alone.  */;
    3648              :       else
    3649    771413681 :         ++skip_without_in_chrg;
    3650              :     }
    3651              : 
    3652    771413681 :   if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
    3653    771413681 :        || DECL_BASE_CONSTRUCTOR_P (tmpl))
    3654    772333883 :       && CLASSTYPE_VBASECLASSES (DECL_CONTEXT (tmpl)))
    3655              :     {
    3656          177 :       if (first_arg_without_in_chrg != NULL_TREE)
    3657              :         first_arg_without_in_chrg = NULL_TREE;
    3658              :       else
    3659          177 :         ++skip_without_in_chrg;
    3660              :     }
    3661              : 
    3662    771413681 :   if (len < skip_without_in_chrg)
    3663            0 :     return add_ignored_candidate (candidates, tmpl);
    3664              : 
    3665    834481709 :   if (DECL_CONSTRUCTOR_P (tmpl) && nargs == 2
    3666    828864223 :       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (first_arg),
    3667     57450542 :                                                     TREE_TYPE ((*arglist)[0])))
    3668              :     {
    3669              :       /* 12.8/6 says, "A declaration of a constructor for a class X is
    3670              :          ill-formed if its first parameter is of type (optionally cv-qualified)
    3671              :          X and either there are no other parameters or else all other
    3672              :          parameters have default arguments. A member function template is never
    3673              :          instantiated to produce such a constructor signature."
    3674              : 
    3675              :          So if we're trying to copy an object of the containing class, don't
    3676              :          consider a template constructor that has a first parameter type that
    3677              :          is just a template parameter, as we would deduce a signature that we
    3678              :          would then reject in the code below.  */
    3679      5037944 :       if (tree firstparm = FUNCTION_FIRST_USER_PARMTYPE (tmpl))
    3680              :         {
    3681      5037944 :           firstparm = TREE_VALUE (firstparm);
    3682      5037944 :           if (PACK_EXPANSION_P (firstparm))
    3683         1884 :             firstparm = PACK_EXPANSION_PATTERN (firstparm);
    3684      5037944 :           if (TREE_CODE (firstparm) == TEMPLATE_TYPE_PARM)
    3685              :             {
    3686      2022441 :               gcc_assert (!explicit_targs);
    3687      2022441 :               reason = invalid_copy_with_fn_template_rejection ();
    3688      2022441 :               goto fail;
    3689              :             }
    3690              :         }
    3691              :     }
    3692              : 
    3693    769391240 :   nargs_without_in_chrg = ((first_arg_without_in_chrg != NULL_TREE ? 1 : 0)
    3694    769391240 :                            + (len - skip_without_in_chrg));
    3695    769391240 :   args_without_in_chrg = XALLOCAVEC (tree, nargs_without_in_chrg);
    3696    769391240 :   ia = 0;
    3697    769391240 :   if (first_arg_without_in_chrg != NULL_TREE)
    3698              :     {
    3699         6336 :       args_without_in_chrg[ia] = first_arg_without_in_chrg;
    3700         6336 :       ++ia;
    3701              :     }
    3702   1305255694 :   for (ix = skip_without_in_chrg;
    3703   2074646934 :        vec_safe_iterate (arglist, ix, &arg);
    3704              :        ++ix)
    3705              :     {
    3706   1305255694 :       args_without_in_chrg[ia] = arg;
    3707   1305255694 :       ++ia;
    3708              :     }
    3709    769391240 :   gcc_assert (ia == nargs_without_in_chrg);
    3710              : 
    3711    769391240 :   if (!obj)
    3712              :     {
    3713              :       /* Check that there's no obvious arity mismatch before proceeding with
    3714              :          deduction.  This avoids substituting explicit template arguments
    3715              :          into the template or e.g. derived-to-base parm/arg unification
    3716              :          (which could result in an error outside the immediate context) when
    3717              :          the resulting candidate would be unviable anyway.  */
    3718    769391228 :       int min_arity = 0, max_arity = 0;
    3719    769391228 :       tree parms = TYPE_ARG_TYPES (TREE_TYPE (tmpl));
    3720    769391228 :       parms = skip_artificial_parms_for (tmpl, parms);
    3721   2896947922 :       for (; parms != void_list_node; parms = TREE_CHAIN (parms))
    3722              :         {
    3723   2722148301 :           if (!parms || PACK_EXPANSION_P (TREE_VALUE (parms)))
    3724              :             {
    3725              :               max_arity = -1;
    3726              :               break;
    3727              :             }
    3728   1358165466 :           if (TREE_PURPOSE (parms))
    3729              :             /* A parameter with a default argument.  */
    3730     10520295 :             ++max_arity;
    3731              :           else
    3732   1347645171 :             ++min_arity, ++max_arity;
    3733              :         }
    3734    769391228 :       if (ia < (unsigned)min_arity)
    3735              :         {
    3736              :           /* Too few arguments.  */
    3737     43789898 :           reason = arity_rejection (NULL_TREE, min_arity, ia,
    3738              :                                     /*least_p=*/(max_arity == -1));
    3739     43789898 :           goto fail;
    3740              :         }
    3741    725601330 :       else if (max_arity != -1 && ia > (unsigned)max_arity)
    3742              :         {
    3743              :           /* Too many arguments.  */
    3744      4938904 :           reason = arity_rejection (NULL_TREE, max_arity, ia);
    3745      4938904 :           goto fail;
    3746              :         }
    3747              : 
    3748    720662426 :       convs = alloc_conversions (nargs);
    3749              : 
    3750    720662426 :       if (shortcut_bad_convs
    3751    720657887 :           && DECL_IOBJ_MEMBER_FUNCTION_P (tmpl)
    3752    825496122 :           && !DECL_CONSTRUCTOR_P (tmpl))
    3753              :         {
    3754              :           /* Check the 'this' conversion before proceeding with deduction.
    3755              :              This is effectively an extension of the DR 1391 resolution
    3756              :              that we perform in check_non_deducible_conversions, though it's
    3757              :              convenient to do this extra check here instead of there.  */
    3758      6812160 :           tree parmtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (tmpl)));
    3759      6812160 :           tree argtype = lvalue_type (first_arg);
    3760      6812160 :           tree arg = first_arg;
    3761      6812160 :           conversion *t = build_this_conversion (tmpl, ctype,
    3762              :                                                  parmtype, argtype, arg,
    3763              :                                                  flags, complain);
    3764      6812160 :           convs[0] = t;
    3765      6812160 :           if (t->bad_p)
    3766              :             {
    3767        31332 :               reason = bad_arg_conversion_rejection (first_arg, 0,
    3768              :                                                      arg, parmtype,
    3769        31332 :                                                      EXPR_LOCATION (arg));
    3770        31332 :               goto fail;
    3771              :             }
    3772              :         }
    3773              :     }
    3774              : 
    3775    720631106 :   errs = errorcount+sorrycount;
    3776   1441248661 :   fn = fn_type_unification (tmpl, explicit_targs, targs,
    3777              :                             args_without_in_chrg,
    3778              :                             nargs_without_in_chrg,
    3779              :                             return_type, strict, flags, convs,
    3780    720631106 :                             false, complain & tf_decltype);
    3781              : 
    3782    720617555 :   if (fn == error_mark_node)
    3783              :     {
    3784              :       /* Don't repeat unification later if it already resulted in errors.  */
    3785    595660494 :       if (errorcount+sorrycount == errs)
    3786    595660384 :         reason = template_unification_rejection (tmpl, explicit_targs,
    3787              :                                                  targs, args_without_in_chrg,
    3788              :                                                  nargs_without_in_chrg,
    3789              :                                                  return_type, strict, flags);
    3790              :       else
    3791          110 :         reason = template_unification_error_rejection ();
    3792    595660494 :       goto fail;
    3793              :     }
    3794              : 
    3795              :   /* Now the explicit specifier might have been deduced; check if this
    3796              :      declaration is explicit.  If it is and we're ignoring non-converting
    3797              :      constructors, don't add this function to the set of candidates.  */
    3798    124957061 :   if (((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    3799              :        == LOOKUP_ONLYCONVERTING)
    3800    124957061 :       && DECL_NONCONVERTING_P (fn))
    3801         4880 :     return add_ignored_candidate (candidates, fn);
    3802              : 
    3803    249904362 :   if (DECL_CONSTRUCTOR_P (fn) && nargs == 2)
    3804              :     {
    3805      6193178 :       tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3806     12386329 :       if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
    3807              :                                     ctype))
    3808              :         {
    3809              :           /* We're trying to produce a constructor with a prohibited signature,
    3810              :              as discussed above; handle here any cases we didn't catch then,
    3811              :              such as X(X<T>).  */
    3812          572 :           reason = invalid_copy_with_fn_template_rejection ();
    3813          572 :           goto fail;
    3814              :         }
    3815              :     }
    3816              : 
    3817    124951609 :   if (obj != NULL_TREE)
    3818              :     /* Aha, this is a conversion function.  */
    3819            9 :     cand = add_conv_candidate (candidates, fn, obj, arglist,
    3820              :                                access_path, conversion_path, complain);
    3821              :   else
    3822    124951600 :     cand = add_function_candidate (candidates, fn, ctype,
    3823              :                                    first_arg, arglist, access_path,
    3824              :                                    conversion_path, flags, convs,
    3825              :                                    shortcut_bad_convs, complain);
    3826    124951609 :   if (DECL_TI_TEMPLATE (fn) != tmpl)
    3827              :     /* This situation can occur if a member template of a template
    3828              :        class is specialized.  Then, instantiate_template might return
    3829              :        an instantiation of the specialization, in which case the
    3830              :        DECL_TI_TEMPLATE field will point at the original
    3831              :        specialization.  For example:
    3832              : 
    3833              :          template <class T> struct S { template <class U> void f(U);
    3834              :                                        template <> void f(int) {}; };
    3835              :          S<double> sd;
    3836              :          sd.f(3);
    3837              : 
    3838              :        Here, TMPL will be template <class U> S<double>::f(U).
    3839              :        And, instantiate template will give us the specialization
    3840              :        template <> S<double>::f(int).  But, the DECL_TI_TEMPLATE field
    3841              :        for this will point at template <class T> template <> S<T>::f(int),
    3842              :        so that we can find the definition.  For the purposes of
    3843              :        overload resolution, however, we want the original TMPL.  */
    3844      6996442 :     cand->template_decl = build_template_info (tmpl, targs);
    3845              :   else
    3846    117955167 :     cand->template_decl = DECL_TEMPLATE_INFO (fn);
    3847    124951609 :   cand->explicit_targs = explicit_targs;
    3848              : 
    3849    124951609 :   return cand;
    3850    646443641 :  fail:
    3851    646443641 :   int viable = (reason->code == rr_bad_arg_conversion ? -1 : 0);
    3852    646443641 :   return add_candidate (candidates, tmpl, first_arg, arglist, nargs, convs,
    3853    646443641 :                         access_path, conversion_path, viable, reason, flags);
    3854              : }
    3855              : 
    3856              : 
    3857              : static struct z_candidate *
    3858    771413669 : add_template_candidate (struct z_candidate **candidates, tree tmpl, tree ctype,
    3859              :                         tree explicit_targs, tree first_arg,
    3860              :                         const vec<tree, va_gc> *arglist, tree return_type,
    3861              :                         tree access_path, tree conversion_path, int flags,
    3862              :                         unification_kind_t strict, bool shortcut_bad_convs,
    3863              :                         tsubst_flags_t complain)
    3864              : {
    3865    771413669 :   return
    3866            0 :     add_template_candidate_real (candidates, tmpl, ctype,
    3867              :                                  explicit_targs, first_arg, arglist,
    3868              :                                  return_type, access_path, conversion_path,
    3869              :                                  flags, NULL_TREE, strict, shortcut_bad_convs,
    3870    771400118 :                                  complain);
    3871              : }
    3872              : 
    3873              : /* Create an overload candidate for the conversion function template TMPL,
    3874              :    returning RETURN_TYPE, which will be invoked for expression OBJ to produce a
    3875              :    pointer-to-function which will in turn be called with the argument list
    3876              :    ARGLIST, and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    3877              :    passed on to implicit_conversion.  */
    3878              : 
    3879              : static struct z_candidate *
    3880           12 : add_template_conv_candidate (struct z_candidate **candidates, tree tmpl,
    3881              :                              tree obj,
    3882              :                              const vec<tree, va_gc> *arglist,
    3883              :                              tree return_type, tree access_path,
    3884              :                              tree conversion_path, tsubst_flags_t complain)
    3885              : {
    3886           12 :   return
    3887           12 :     add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE,
    3888              :                                  NULL_TREE, arglist, return_type, access_path,
    3889              :                                  conversion_path, 0, obj, DEDUCE_CALL,
    3890           12 :                                  /*shortcut_bad_convs=*/false, complain);
    3891              : }
    3892              : 
    3893              : /* The CANDS are the set of candidates that were considered for
    3894              :    overload resolution.  Sort CANDS so that the strictly viable
    3895              :    candidates appear first, followed by non-strictly viable candidates,
    3896              :    followed by non-viable candidates.  Returns the first candidate
    3897              :    in this sorted list.  If any of the candidates were viable, set
    3898              :    *ANY_VIABLE_P to true.  STRICT_P is true if a candidate should be
    3899              :    considered viable only if it is strictly viable when setting
    3900              :    *ANY_VIABLE_P.  */
    3901              : 
    3902              : static struct z_candidate*
    3903    419547392 : splice_viable (struct z_candidate *cands,
    3904              :                bool strict_p,
    3905              :                bool *any_viable_p)
    3906              : {
    3907    419547392 :   z_candidate *strictly_viable = nullptr;
    3908    419547392 :   z_candidate **strictly_viable_tail = &strictly_viable;
    3909              : 
    3910    419547392 :   z_candidate *non_strictly_viable = nullptr;
    3911    419547392 :   z_candidate **non_strictly_viable_tail = &non_strictly_viable;
    3912              : 
    3913    419547392 :   z_candidate *non_viable = nullptr;
    3914    419547392 :   z_candidate **non_viable_tail = &non_viable;
    3915              : 
    3916    419547392 :   z_candidate *non_viable_ignored = nullptr;
    3917    419547392 :   z_candidate **non_viable_ignored_tail = &non_viable_ignored;
    3918              : 
    3919              :   /* Be strict inside templates, since build_over_call won't actually
    3920              :      do the conversions to get pedwarns.  */
    3921    419547392 :   if (processing_template_decl)
    3922     55774682 :     strict_p = true;
    3923              : 
    3924   1626865810 :   for (z_candidate *cand = cands; cand; cand = cand->next)
    3925              :     {
    3926   1207318418 :       if (!strict_p
    3927    431737960 :           && (cand->viable == 1 || TREE_CODE (cand->fn) == TEMPLATE_DECL))
    3928              :         /* Be strict in the presence of a viable candidate.  Also if
    3929              :            there are template candidates, so that we get deduction errors
    3930              :            for them instead of silently preferring a bad conversion.  */
    3931   1072282295 :         strict_p = true;
    3932              : 
    3933              :       /* Move this candidate to the appropriate list according to
    3934              :          its viability.  */
    3935   1207318418 :       auto& tail = (cand->viable == 1 ? strictly_viable_tail
    3936              :                     : cand->viable == -1 ? non_strictly_viable_tail
    3937   1950138409 :                     : ignored_candidate_p (cand) ? non_viable_ignored_tail
    3938   1950138409 :                     : non_viable_tail);
    3939   1207318418 :       *tail = cand;
    3940   1207318418 :       tail = &cand->next;
    3941              :     }
    3942              : 
    3943    839094784 :   *any_viable_p = (strictly_viable != nullptr
    3944    419547392 :                    || (!strict_p && non_strictly_viable != nullptr));
    3945              : 
    3946              :   /* Combine the lists.  */
    3947    419547392 :   *non_viable_ignored_tail = nullptr;
    3948    419547392 :   *non_viable_tail = non_viable_ignored;
    3949    419547392 :   *non_strictly_viable_tail = non_viable;
    3950    419547392 :   *strictly_viable_tail = non_strictly_viable;
    3951              : 
    3952    419547392 :   return strictly_viable;
    3953              : }
    3954              : 
    3955              : static bool
    3956    400904603 : any_strictly_viable (struct z_candidate *cands)
    3957              : {
    3958    578468377 :   for (; cands; cands = cands->next)
    3959    190105321 :     if (cands->viable == 1)
    3960              :       return true;
    3961              :   return false;
    3962              : }
    3963              : 
    3964              : /* OBJ is being used in an expression like "OBJ.f (...)".  In other
    3965              :    words, it is about to become the "this" pointer for a member
    3966              :    function call.  Take the address of the object.  */
    3967              : 
    3968              : static tree
    3969     94174186 : build_this (tree obj)
    3970              : {
    3971              :   /* In a template, we are only concerned about the type of the
    3972              :      expression, so we can take a shortcut.  */
    3973     94174186 :   if (processing_template_decl)
    3974        73037 :     return build_address (obj);
    3975              : 
    3976     94101149 :   return cp_build_addr_expr (obj, tf_warning_or_error);
    3977              : }
    3978              : 
    3979              : /* Returns true iff functions are equivalent. Equivalent functions are
    3980              :    not '==' only if one is a function-local extern function or if
    3981              :    both are extern "C".  */
    3982              : 
    3983              : static inline int
    3984      7119082 : equal_functions (tree fn1, tree fn2)
    3985              : {
    3986      7119082 :   if (TREE_CODE (fn1) != TREE_CODE (fn2))
    3987              :     return 0;
    3988      7103737 :   if (TREE_CODE (fn1) == TEMPLATE_DECL)
    3989        36043 :     return fn1 == fn2;
    3990     14135370 :   if (DECL_LOCAL_DECL_P (fn1) || DECL_LOCAL_DECL_P (fn2)
    3991     14135367 :       || DECL_EXTERN_C_FUNCTION_P (fn1))
    3992      2876616 :     return decls_match (fn1, fn2);
    3993      4191078 :   return fn1 == fn2;
    3994              : }
    3995              : 
    3996              : /* Print information about a candidate FN being rejected due to INFO.  */
    3997              : 
    3998              : static void
    3999         5295 : print_conversion_rejection (location_t loc, struct conversion_info *info,
    4000              :                             tree fn)
    4001              : {
    4002         5295 :   tree from = info->from;
    4003         5295 :   if (!TYPE_P (from))
    4004         4355 :     from = lvalue_type (from);
    4005         5295 :   if (info->n_arg == -1)
    4006              :     {
    4007              :       /* Conversion of implicit `this' argument failed.  */
    4008           24 :       if (!TYPE_P (info->from))
    4009              :         /* A bad conversion for 'this' must be discarding cv-quals.  */
    4010           24 :         inform (loc, "passing %qT as %<this%> "
    4011              :                 "argument discards qualifiers",
    4012              :                 from);
    4013              :       else
    4014            0 :         inform (loc, "no known conversion for implicit "
    4015              :                 "%<this%> parameter from %qH to %qI",
    4016              :                 from, info->to_type);
    4017              :     }
    4018         5271 :   else if (!TYPE_P (info->from))
    4019              :     {
    4020         4331 :       if (info->n_arg >= 0)
    4021         4331 :         inform (loc, "conversion of argument %d would be ill-formed:",
    4022              :                 info->n_arg + 1);
    4023         4331 :       iloc_sentinel ils = loc;
    4024         4331 :       perform_implicit_conversion (info->to_type, info->from,
    4025              :                                    tf_warning_or_error);
    4026         4331 :     }
    4027          940 :   else if (info->n_arg == -2)
    4028              :     /* Conversion of conversion function return value failed.  */
    4029           33 :     inform (loc, "no known conversion from %qH to %qI",
    4030              :             from, info->to_type);
    4031              :   else
    4032              :     {
    4033          907 :       if (TREE_CODE (fn) == FUNCTION_DECL)
    4034          751 :         loc = get_fndecl_argument_location (fn, info->n_arg);
    4035          907 :       inform (loc, "no known conversion for argument %d from %qH to %qI",
    4036          907 :               info->n_arg + 1, from, info->to_type);
    4037              :     }
    4038         5295 : }
    4039              : 
    4040              : /* Print information about a candidate with WANT parameters and we found
    4041              :    HAVE.  */
    4042              : 
    4043              : static void
    4044         1449 : print_arity_information (location_t loc, unsigned int have, unsigned int want,
    4045              :                          bool least_p)
    4046              : {
    4047         1449 :   if (least_p)
    4048           41 :     inform_n (loc, want,
    4049              :               "candidate expects at least %d argument, %d provided",
    4050              :               "candidate expects at least %d arguments, %d provided",
    4051              :               want, have);
    4052              :   else
    4053         1408 :     inform_n (loc, want,
    4054              :               "candidate expects %d argument, %d provided",
    4055              :               "candidate expects %d arguments, %d provided",
    4056              :               want, have);
    4057         1449 : }
    4058              : 
    4059              : /* Print information about one overload candidate CANDIDATE.  MSGSTR
    4060              :    is the text to print before the candidate itself.
    4061              : 
    4062              :    NOTE: Unlike most diagnostic functions in GCC, MSGSTR is expected
    4063              :    to have been run through gettext by the caller.  This wart makes
    4064              :    life simpler in print_z_candidates and for the translators.  */
    4065              : 
    4066              : static void
    4067        13163 : print_z_candidate (location_t loc, const char *msgstr,
    4068              :                    struct z_candidate *candidate)
    4069              : {
    4070        13163 :   const char *msg = (msgstr == NULL
    4071        13163 :                      ? ""
    4072        13163 :                      : ACONCAT ((_(msgstr), " ", NULL)));
    4073        13163 :   tree fn = candidate->fn;
    4074        13163 :   if (flag_new_inheriting_ctors)
    4075        13136 :     fn = strip_inheriting_ctors (fn);
    4076        13163 :   location_t cloc = location_of (fn);
    4077              : 
    4078        13163 :   if (identifier_p (fn))
    4079              :     {
    4080          214 :       cloc = loc;
    4081          214 :       if (candidate->num_convs == 3)
    4082            0 :         inform (cloc, "%s%<%D(%T, %T, %T)%> (built-in)", msg, fn,
    4083            0 :                 candidate->convs[0]->type,
    4084            0 :                 candidate->convs[1]->type,
    4085            0 :                 candidate->convs[2]->type);
    4086          214 :       else if (candidate->num_convs == 2)
    4087          190 :         inform (cloc, "%s%<%D(%T, %T)%> (built-in)", msg, fn,
    4088          190 :                 candidate->convs[0]->type,
    4089          190 :                 candidate->convs[1]->type);
    4090              :       else
    4091           24 :         inform (cloc, "%s%<%D(%T)%> (built-in)", msg, fn,
    4092           24 :                 candidate->convs[0]->type);
    4093              :     }
    4094        12949 :   else if (TYPE_P (fn))
    4095           11 :     inform (cloc, "%s%qT (conversion)", msg, fn);
    4096        12938 :   else if (candidate->viable == -1)
    4097         4366 :     inform (cloc, "%s%#qD (near match)", msg, fn);
    4098         8572 :   else if (ignored_candidate_p (candidate))
    4099            6 :     inform (cloc, "%s%#qD (ignored)", msg, fn);
    4100         8566 :   else if (DECL_DELETED_FN (fn))
    4101           60 :     inform (cloc, "%s%#qD (deleted)", msg, fn);
    4102         8506 :   else if (candidate->reversed ())
    4103          300 :     inform (cloc, "%s%#qD (reversed)", msg, fn);
    4104         8206 :   else if (candidate->rewritten ())
    4105          150 :     inform (cloc, "%s%#qD (rewritten)", msg, fn);
    4106              :   else
    4107         8056 :     inform (cloc, "%s%#qD", msg, fn);
    4108              : 
    4109        13163 :   auto_diagnostic_nesting_level sentinel;
    4110              : 
    4111        13163 :   if (fn != candidate->fn)
    4112              :     {
    4113           57 :       cloc = location_of (candidate->fn);
    4114           57 :       inform (cloc, "inherited here");
    4115              :     }
    4116              : 
    4117              :   /* Give the user some information about why this candidate failed.  */
    4118        13163 :   if (candidate->reason != NULL)
    4119              :     {
    4120        10072 :       struct rejection_reason *r = candidate->reason;
    4121              : 
    4122        10072 :       switch (r->code)
    4123              :         {
    4124         1449 :         case rr_arity:
    4125         1449 :           print_arity_information (cloc, r->u.arity.actual,
    4126         1449 :                                    r->u.arity.expected,
    4127         1449 :                                    r->u.arity.least_p);
    4128         1449 :           break;
    4129          913 :         case rr_arg_conversion:
    4130          913 :           print_conversion_rejection (cloc, &r->u.conversion, fn);
    4131          913 :           break;
    4132         4382 :         case rr_bad_arg_conversion:
    4133         4382 :           print_conversion_rejection (cloc, &r->u.bad_conversion, fn);
    4134         4382 :           break;
    4135           11 :         case rr_explicit_conversion:
    4136           11 :           inform (cloc, "return type %qT of explicit conversion function "
    4137              :                   "cannot be converted to %qT with a qualification "
    4138              :                   "conversion", r->u.conversion.from,
    4139              :                   r->u.conversion.to_type);
    4140           11 :           break;
    4141            6 :         case rr_template_conversion:
    4142            6 :           inform (cloc, "conversion from return type %qT of template "
    4143              :                   "conversion function specialization to %qT is not an "
    4144              :                   "exact match", r->u.conversion.from,
    4145              :                   r->u.conversion.to_type);
    4146            6 :           break;
    4147         3178 :         case rr_template_unification:
    4148              :           /* We use template_unification_error_rejection if unification caused
    4149              :              actual non-SFINAE errors, in which case we don't need to repeat
    4150              :              them here.  */
    4151         3178 :           if (r->u.template_unification.tmpl == NULL_TREE)
    4152              :             {
    4153           45 :               inform (cloc, "substitution of deduced template arguments "
    4154              :                       "resulted in errors seen above");
    4155           45 :               break;
    4156              :             }
    4157              :           /* Re-run template unification with diagnostics.  */
    4158         3133 :           inform (cloc, "template argument deduction/substitution failed:");
    4159         3133 :           {
    4160         3133 :             auto_diagnostic_nesting_level sentinel;
    4161         3133 :             fn_type_unification (r->u.template_unification.tmpl,
    4162              :                                  r->u.template_unification.explicit_targs,
    4163              :                                  (make_tree_vec
    4164              :                                   (r->u.template_unification.num_targs)),
    4165              :                                  r->u.template_unification.args,
    4166              :                                  r->u.template_unification.nargs,
    4167              :                                  r->u.template_unification.return_type,
    4168              :                                  r->u.template_unification.strict,
    4169              :                                  r->u.template_unification.flags,
    4170              :                                  NULL, true, false);
    4171         3133 :           }
    4172         3133 :           break;
    4173            2 :         case rr_invalid_copy:
    4174            2 :           inform (cloc,
    4175              :                   "a constructor taking a single argument of its own "
    4176              :                   "class type is invalid");
    4177            2 :           break;
    4178           93 :         case rr_constraint_failure:
    4179           93 :           diagnose_constraints (cloc, fn, NULL_TREE);
    4180           93 :           break;
    4181           32 :         case rr_inherited_ctor:
    4182           32 :           inform (cloc, "an inherited constructor is not a candidate for "
    4183              :                   "initialization from an expression of the same or derived "
    4184              :                   "type");
    4185           32 :           break;
    4186              :         case rr_ignored:
    4187              :           break;
    4188            0 :         case rr_none:
    4189            0 :         default:
    4190              :           /* This candidate didn't have any issues or we failed to
    4191              :              handle a particular code.  Either way...  */
    4192            0 :           gcc_unreachable ();
    4193              :         }
    4194              :     }
    4195        13163 : }
    4196              : 
    4197              : /* Print information about each overload candidate in CANDIDATES,
    4198              :    which is assumed to have gone through splice_viable and tourney
    4199              :    (if splice_viable succeeded).  */
    4200              : 
    4201              : static void
    4202         5440 : print_z_candidates (location_t loc, struct z_candidate *candidates,
    4203              :                     tristate only_viable_p /* = tristate::unknown () */)
    4204              : {
    4205         5440 :   struct z_candidate *cand1;
    4206         5440 :   struct z_candidate **cand2;
    4207              : 
    4208         5440 :   if (!candidates)
    4209         1004 :     return;
    4210              : 
    4211              :   /* Remove non-viable deleted candidates.  */
    4212         4436 :   cand1 = candidates;
    4213        20174 :   for (cand2 = &cand1; *cand2; )
    4214              :     {
    4215        15738 :       if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
    4216        11395 :           && !(*cand2)->viable
    4217        19497 :           && DECL_DELETED_FN ((*cand2)->fn))
    4218          102 :         *cand2 = (*cand2)->next;
    4219              :       else
    4220        15636 :         cand2 = &(*cand2)->next;
    4221              :     }
    4222              :   /* ...if there are any non-deleted ones.  */
    4223         4436 :   if (cand1)
    4224         4430 :     candidates = cand1;
    4225              : 
    4226              :   /* There may be duplicates in the set of candidates.  We put off
    4227              :      checking this condition as long as possible, since we have no way
    4228              :      to eliminate duplicates from a set of functions in less than n^2
    4229              :      time.  Now we are about to emit an error message, so it is more
    4230              :      permissible to go slowly.  */
    4231        19772 :   for (cand1 = candidates; cand1; cand1 = cand1->next)
    4232              :     {
    4233        15336 :       tree fn = cand1->fn;
    4234              :       /* Skip builtin candidates and conversion functions.  */
    4235        15336 :       if (!DECL_P (fn))
    4236          285 :         continue;
    4237        15051 :       cand2 = &cand1->next;
    4238       143153 :       while (*cand2)
    4239              :         {
    4240       128102 :           if (DECL_P ((*cand2)->fn)
    4241       128102 :               && equal_functions (fn, (*cand2)->fn))
    4242          306 :             *cand2 = (*cand2)->next;
    4243              :           else
    4244       127796 :             cand2 = &(*cand2)->next;
    4245              :         }
    4246              :     }
    4247              : 
    4248              :   /* Unless otherwise specified, if there's a (strictly) viable candidate
    4249              :      then we assume we're being called as part of diagnosing ambiguity, in
    4250              :      which case we want to print only viable candidates since non-viable
    4251              :      candidates couldn't have contributed to the ambiguity.  */
    4252         4436 :   if (only_viable_p.is_unknown ())
    4253         4427 :     only_viable_p = candidates->viable == 1;
    4254              : 
    4255         4436 :   auto_diagnostic_nesting_level sentinel;
    4256              : 
    4257         4436 :   int num_candidates = 0;
    4258        17487 :   for (auto iter = candidates; iter; iter = iter->next)
    4259              :     {
    4260        13392 :       if (only_viable_p.is_true () && iter->viable != 1)
    4261              :         break;
    4262        13051 :       ++num_candidates;
    4263              :     }
    4264              : 
    4265         4436 :   inform_num_candidates (loc, num_candidates);
    4266              : 
    4267         4436 :   auto_diagnostic_nesting_level sentinel2;
    4268              : 
    4269         4436 :   int candidate_idx = 0;
    4270        21890 :   for (; candidates; candidates = candidates->next)
    4271              :     {
    4272        13388 :       if (only_viable_p.is_true () && candidates->viable != 1)
    4273              :         break;
    4274        13082 :       if (ignored_candidate_p (candidates) && !flag_diagnostics_all_candidates)
    4275              :         {
    4276           29 :           inform (loc, "some candidates omitted; "
    4277              :                        "use %<-fdiagnostics-all-candidates%> to display them");
    4278           29 :           break;
    4279              :         }
    4280        13018 :       pretty_printer pp;
    4281        13018 :       pp_printf (&pp, N_("candidate %i:"), candidate_idx + 1);
    4282        13018 :       const char *const msgstr = pp_formatted_text (&pp);
    4283        13018 :       print_z_candidate (loc, msgstr, candidates);
    4284        13018 :       ++candidate_idx;
    4285        13018 :     }
    4286         4436 : }
    4287              : 
    4288              : /* USER_SEQ is a user-defined conversion sequence, beginning with a
    4289              :    USER_CONV.  STD_SEQ is the standard conversion sequence applied to
    4290              :    the result of the conversion function to convert it to the final
    4291              :    desired type.  Merge the two sequences into a single sequence,
    4292              :    and return the merged sequence.  */
    4293              : 
    4294              : static conversion *
    4295     17216343 : merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
    4296              : {
    4297     17216343 :   conversion **t;
    4298     17216343 :   bool bad = user_seq->bad_p;
    4299              : 
    4300     17216343 :   gcc_assert (user_seq->kind == ck_user);
    4301              : 
    4302              :   /* Find the end of the second conversion sequence.  */
    4303     18114392 :   for (t = &std_seq; (*t)->kind != ck_identity; t = &((*t)->u.next))
    4304              :     {
    4305              :       /* The entire sequence is a user-conversion sequence.  */
    4306       898049 :       (*t)->user_conv_p = true;
    4307       898049 :       if (bad)
    4308         2929 :         (*t)->bad_p = true;
    4309              :     }
    4310              : 
    4311     17216343 :   if ((*t)->rvaluedness_matches_p)
    4312              :     /* We're binding a reference directly to the result of the conversion.
    4313              :        build_user_type_conversion_1 stripped the REFERENCE_TYPE from the return
    4314              :        type, but we want it back.  */
    4315       606677 :     user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
    4316              : 
    4317              :   /* Replace the identity conversion with the user conversion
    4318              :      sequence.  */
    4319     17216343 :   *t = user_seq;
    4320              : 
    4321     17216343 :   return std_seq;
    4322              : }
    4323              : 
    4324              : /* Handle overload resolution for initializing an object of class type from
    4325              :    an initializer list.  First we look for a suitable constructor that
    4326              :    takes a std::initializer_list; if we don't find one, we then look for a
    4327              :    non-list constructor.
    4328              : 
    4329              :    Parameters are as for add_candidates, except that the arguments are in
    4330              :    the form of a CONSTRUCTOR (the initializer list) rather than a vector, and
    4331              :    the RETURN_TYPE parameter is replaced by TOTYPE, the desired type.  */
    4332              : 
    4333              : static void
    4334      2668595 : add_list_candidates (tree fns, tree first_arg,
    4335              :                      const vec<tree, va_gc> *args, tree totype,
    4336              :                      tree explicit_targs, bool template_only,
    4337              :                      tree conversion_path, tree access_path,
    4338              :                      int flags,
    4339              :                      struct z_candidate **candidates,
    4340              :                      tsubst_flags_t complain)
    4341              : {
    4342      2668595 :   gcc_assert (*candidates == NULL);
    4343              : 
    4344              :   /* We're looking for a ctor for list-initialization.  */
    4345      2668595 :   flags |= LOOKUP_LIST_INIT_CTOR;
    4346              :   /* And we don't allow narrowing conversions.  We also use this flag to
    4347              :      avoid the copy constructor call for copy-list-initialization.  */
    4348      2668595 :   flags |= LOOKUP_NO_NARROWING;
    4349              : 
    4350      5337190 :   unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1;
    4351      2668595 :   tree init_list = (*args)[nart];
    4352              : 
    4353              :   /* Always use the default constructor if the list is empty (DR 990).  */
    4354      2668595 :   if (CONSTRUCTOR_NELTS (init_list) == 0
    4355      2668595 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
    4356              :     ;
    4357      2369886 :   else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list)
    4358      2369886 :            && !CP_AGGREGATE_TYPE_P (totype))
    4359              :     {
    4360           48 :       if (complain & tf_error)
    4361           12 :         error ("designated initializers cannot be used with a "
    4362              :                "non-aggregate type %qT", totype);
    4363         6647 :       return;
    4364              :     }
    4365              :   /* If the class has a list ctor, try passing the list as a single
    4366              :      argument first, but only consider list ctors.  */
    4367      2369838 :   else if (TYPE_HAS_LIST_CTOR (totype))
    4368              :     {
    4369        88149 :       flags |= LOOKUP_LIST_ONLY;
    4370        88149 :       add_candidates (fns, first_arg, args, NULL_TREE,
    4371              :                       explicit_targs, template_only, conversion_path,
    4372              :                       access_path, flags, candidates, complain);
    4373       176298 :       if (any_strictly_viable (*candidates))
    4374              :         return;
    4375              :     }
    4376              : 
    4377              :   /* Expand the CONSTRUCTOR into a new argument vec.  */
    4378      2661948 :   vec<tree, va_gc> *new_args;
    4379      5024485 :   vec_alloc (new_args, nart + CONSTRUCTOR_NELTS (init_list));
    4380      2661951 :   for (unsigned i = 0; i < nart; ++i)
    4381            3 :     new_args->quick_push ((*args)[i]);
    4382      2661948 :   new_args = append_ctor_to_tree_vector (new_args, init_list);
    4383              : 
    4384              :   /* We aren't looking for list-ctors anymore.  */
    4385      2661948 :   flags &= ~LOOKUP_LIST_ONLY;
    4386              :   /* We allow more user-defined conversions within an init-list.  */
    4387      2661948 :   flags &= ~LOOKUP_NO_CONVERSION;
    4388              : 
    4389      2661948 :   add_candidates (fns, first_arg, new_args, NULL_TREE,
    4390              :                   explicit_targs, template_only, conversion_path,
    4391              :                   access_path, flags, candidates, complain);
    4392              : }
    4393              : 
    4394              : /* Given C(std::initializer_list<A>), return A.  */
    4395              : 
    4396              : static tree
    4397         1217 : list_ctor_element_type (tree fn)
    4398              : {
    4399         1217 :   gcc_checking_assert (is_list_ctor (fn));
    4400              : 
    4401         1217 :   tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    4402         1217 :   parm = non_reference (TREE_VALUE (parm));
    4403         1217 :   return TREE_VEC_ELT (CLASSTYPE_TI_ARGS (parm), 0);
    4404              : }
    4405              : 
    4406              : /* If EXPR is a braced-init-list where the elements all decay to the same type,
    4407              :    return that type.  */
    4408              : 
    4409              : static tree
    4410         1296 : braced_init_element_type (tree expr)
    4411              : {
    4412         1296 :   if (TREE_CODE (expr) == CONSTRUCTOR
    4413         1296 :       && TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE)
    4414            0 :     return TREE_TYPE (TREE_TYPE (expr));
    4415         1296 :   if (!BRACE_ENCLOSED_INITIALIZER_P (expr))
    4416              :     return NULL_TREE;
    4417              : 
    4418         1296 :   tree elttype = NULL_TREE;
    4419        13858 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (expr))
    4420              :     {
    4421        10146 :       tree type = TREE_TYPE (e.value);
    4422        10146 :       type = type_decays_to (type);
    4423        10146 :       if (!elttype)
    4424              :         elttype = type;
    4425         8869 :       else if (!same_type_p (type, elttype))
    4426              :         return NULL_TREE;
    4427              :     }
    4428              :   return elttype;
    4429              : }
    4430              : 
    4431              : /* True iff EXPR contains any temporaries with non-trivial destruction.
    4432              : 
    4433              :    ??? Also ignore classes with non-trivial but no-op destruction other than
    4434              :    std::allocator?  */
    4435              : 
    4436              : static bool
    4437          191 : has_non_trivial_temporaries (tree expr)
    4438              : {
    4439          191 :   auto_vec<tree*> temps;
    4440          191 :   cp_walk_tree_without_duplicates (&expr, find_temps_r, &temps);
    4441          380 :   for (tree *p : temps)
    4442              :     {
    4443           63 :       tree t = TREE_TYPE (*p);
    4444           63 :       if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (t)
    4445           63 :           && !is_std_allocator (t))
    4446              :         return true;
    4447              :     }
    4448              :   return false;
    4449          191 : }
    4450              : 
    4451              : /* Return number of initialized elements in CTOR.  */
    4452              : 
    4453              : unsigned HOST_WIDE_INT
    4454          249 : count_ctor_elements (tree ctor)
    4455              : {
    4456          249 :   unsigned HOST_WIDE_INT len = 0;
    4457         2051 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (ctor))
    4458         1304 :     if (TREE_CODE (e.value) == RAW_DATA_CST)
    4459            9 :       len += RAW_DATA_LENGTH (e.value);
    4460              :     else
    4461         1295 :       ++len;
    4462          249 :   return len;
    4463              : }
    4464              : 
    4465              : /* We're initializing an array of ELTTYPE from INIT.  If it seems useful,
    4466              :    return INIT as an array (of its own type) so the caller can initialize the
    4467              :    target array in a loop.  */
    4468              : 
    4469              : static tree
    4470        10930 : maybe_init_list_as_array (tree elttype, tree init)
    4471              : {
    4472              :   /* Only do this if the array can go in rodata but not once converted.  */
    4473        10930 :   if (!TYPE_NON_AGGREGATE_CLASS (elttype))
    4474              :     return NULL_TREE;
    4475         1296 :   tree init_elttype = braced_init_element_type (init);
    4476         1296 :   if (!init_elttype || !SCALAR_TYPE_P (init_elttype) || !TREE_CONSTANT (init))
    4477              :     return NULL_TREE;
    4478              : 
    4479              :   /* Check with a stub expression to weed out special cases, and check whether
    4480              :      we call the same function for direct-init as copy-list-init.  */
    4481          353 :   conversion_obstack_sentinel cos;
    4482          353 :   init_elttype = cp_build_qualified_type (init_elttype, TYPE_QUAL_CONST);
    4483          353 :   tree arg = build_stub_object (init_elttype);
    4484          353 :   conversion *c = implicit_conversion (elttype, init_elttype, arg, false,
    4485              :                                        LOOKUP_NORMAL, tf_none);
    4486          353 :   if (c && c->kind == ck_rvalue)
    4487            0 :     c = next_conversion (c);
    4488          347 :   if (!c || c->kind != ck_user)
    4489              :     return NULL_TREE;
    4490              :   /* Check that we actually can perform the conversion.  */
    4491          344 :   if (convert_like (c, arg, tf_none) == error_mark_node)
    4492              :     /* Let the normal code give the error.  */
    4493              :     return NULL_TREE;
    4494              : 
    4495              :   /* A glvalue initializer might be significant to a reference constructor
    4496              :      or conversion operator.  */
    4497          338 :   if (!DECL_CONSTRUCTOR_P (c->cand->fn)
    4498          338 :       || (TYPE_REF_P (TREE_VALUE
    4499              :                       (FUNCTION_FIRST_USER_PARMTYPE (c->cand->fn)))))
    4500          240 :     for (auto &ce : CONSTRUCTOR_ELTS (init))
    4501          108 :       if (non_mergeable_glvalue_p (ce.value))
    4502              :         return NULL_TREE;
    4503              : 
    4504          335 :   tree first = CONSTRUCTOR_ELT (init, 0)->value;
    4505          335 :   conversion *fc = implicit_conversion (elttype, init_elttype, first, false,
    4506              :                                         LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING,
    4507              :                                         tf_none);
    4508          335 :   if (fc && fc->kind == ck_rvalue)
    4509           48 :     fc = next_conversion (fc);
    4510          335 :   if (!fc || fc->kind != ck_user || fc->cand->fn != c->cand->fn)
    4511              :     return NULL_TREE;
    4512          293 :   first = convert_like (fc, first, tf_none);
    4513          293 :   if (first == error_mark_node)
    4514              :     /* Let the normal code give the error.  */
    4515              :     return NULL_TREE;
    4516              : 
    4517              :   /* Don't do this if the conversion would be constant.  */
    4518          290 :   first = maybe_constant_init (first);
    4519          290 :   if (TREE_CONSTANT (first))
    4520              :     return NULL_TREE;
    4521              : 
    4522              :   /* We can't do this if the conversion creates temporaries that need
    4523              :      to live until the whole array is initialized.  */
    4524          191 :   if (has_non_trivial_temporaries (first))
    4525              :     return NULL_TREE;
    4526              : 
    4527              :   /* We can't do this if copying from the initializer_list would be
    4528              :      ill-formed.  */
    4529          191 :   tree copy_argtypes = make_tree_vec (1);
    4530          191 :   TREE_VEC_ELT (copy_argtypes, 0)
    4531          191 :     = cp_build_qualified_type (elttype, TYPE_QUAL_CONST);
    4532          191 :   if (!is_xible (INIT_EXPR, elttype, copy_argtypes))
    4533              :     return NULL_TREE;
    4534              : 
    4535          185 :   unsigned HOST_WIDE_INT len = count_ctor_elements (init);
    4536          185 :   tree arr = build_array_of_n_type (init_elttype, len);
    4537          185 :   arr = finish_compound_literal (arr, init, tf_none);
    4538          185 :   DECL_MERGEABLE (TARGET_EXPR_SLOT (arr)) = true;
    4539          185 :   return arr;
    4540          353 : }
    4541              : 
    4542              : /* If we were going to call e.g. vector(initializer_list<string>) starting
    4543              :    with a list of string-literals (which is inefficient, see PR105838),
    4544              :    instead build an array of const char* and pass it to the range constructor.
    4545              :    But only do this for standard library types, where we can assume the
    4546              :    transformation makes sense.
    4547              : 
    4548              :    Really the container classes should have initializer_list<U> constructors to
    4549              :    get the same effect more simply; this is working around that lack.  */
    4550              : 
    4551              : static tree
    4552     16620815 : maybe_init_list_as_range (tree fn, tree expr)
    4553              : {
    4554     16620815 :   if (!processing_template_decl
    4555     16121166 :       && BRACE_ENCLOSED_INITIALIZER_P (expr)
    4556      1019872 :       && is_list_ctor (fn)
    4557     16622185 :       && decl_in_std_namespace_p (fn))
    4558              :     {
    4559         1217 :       tree to = list_ctor_element_type (fn);
    4560         1217 :       if (tree init = maybe_init_list_as_array (to, expr))
    4561              :         {
    4562           53 :           tree begin = decay_conversion (TARGET_EXPR_SLOT (init), tf_none);
    4563           53 :           tree nelts = array_type_nelts_top (TREE_TYPE (init));
    4564           53 :           tree end = cp_build_binary_op (input_location, PLUS_EXPR, begin,
    4565              :                                          nelts, tf_none);
    4566           53 :           begin = cp_build_compound_expr (init, begin, tf_none);
    4567           53 :           return build_constructor_va (init_list_type_node, 2,
    4568           53 :                                        NULL_TREE, begin, NULL_TREE, end);
    4569              :         }
    4570              :     }
    4571              : 
    4572              :   return NULL_TREE;
    4573              : }
    4574              : 
    4575              : /* Returns the best overload candidate to perform the requested
    4576              :    conversion.  This function is used for three the overloading situations
    4577              :    described in [over.match.copy], [over.match.conv], and [over.match.ref].
    4578              :    If TOTYPE is a REFERENCE_TYPE, we're trying to find a direct binding as
    4579              :    per [dcl.init.ref], so we ignore temporary bindings.  */
    4580              : 
    4581              : static struct z_candidate *
    4582    127145595 : build_user_type_conversion_1 (tree totype, tree expr, int flags,
    4583              :                               tsubst_flags_t complain)
    4584              : {
    4585    127145595 :   struct z_candidate *candidates, *cand;
    4586    127145595 :   tree fromtype;
    4587    127145595 :   tree ctors = NULL_TREE;
    4588    127145595 :   tree conv_fns = NULL_TREE;
    4589    127145595 :   conversion *conv = NULL;
    4590    127145595 :   tree first_arg = NULL_TREE;
    4591    127145595 :   vec<tree, va_gc> *args = NULL;
    4592    127145595 :   bool any_viable_p;
    4593    127145595 :   int convflags;
    4594              : 
    4595    127145595 :   if (!expr)
    4596              :     return NULL;
    4597              : 
    4598    127145589 :   fromtype = TREE_TYPE (expr);
    4599              : 
    4600              :   /* We represent conversion within a hierarchy using RVALUE_CONV and
    4601              :      BASE_CONV, as specified by [over.best.ics]; these become plain
    4602              :      constructor calls, as specified in [dcl.init].  */
    4603    127145589 :   gcc_assert (!MAYBE_CLASS_TYPE_P (fromtype) || !MAYBE_CLASS_TYPE_P (totype)
    4604              :               || !DERIVED_FROM_P (totype, fromtype));
    4605              : 
    4606    127145589 :   if (CLASS_TYPE_P (totype))
    4607              :     /* Use lookup_fnfields_slot instead of lookup_fnfields to avoid
    4608              :        creating a garbage BASELINK; constructors can't be inherited.  */
    4609     73879600 :     ctors = get_class_binding (totype, complete_ctor_identifier);
    4610              : 
    4611    127145589 :   tree to_nonref = non_reference (totype);
    4612    127145589 :   if (MAYBE_CLASS_TYPE_P (fromtype))
    4613              :     {
    4614     84737416 :       if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
    4615     84710184 :           (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
    4616     69294829 :            && DERIVED_FROM_P (to_nonref, fromtype)))
    4617              :         {
    4618              :           /* [class.conv.fct] A conversion function is never used to
    4619              :              convert a (possibly cv-qualified) object to the (possibly
    4620              :              cv-qualified) same object type (or a reference to it), to a
    4621              :              (possibly cv-qualified) base class of that type (or a
    4622              :              reference to it)...  */
    4623              :         }
    4624              :       else
    4625     84710181 :         conv_fns = lookup_conversions (fromtype);
    4626              :     }
    4627              : 
    4628    127145589 :   candidates = 0;
    4629    127145589 :   flags |= LOOKUP_NO_CONVERSION;
    4630    127145589 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4631      1076990 :     flags |= LOOKUP_NO_NARROWING;
    4632              :   /* Prevent add_candidates from treating a non-strictly viable candidate
    4633              :      as unviable.  */
    4634    127145589 :   complain |= tf_conv;
    4635              : 
    4636              :   /* It's OK to bind a temporary for converting constructor arguments, but
    4637              :      not in converting the return value of a conversion operator.  */
    4638    127145589 :   convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION
    4639    127145589 :                | (flags & LOOKUP_NO_NARROWING));
    4640    127145589 :   flags &= ~LOOKUP_NO_TEMP_BIND;
    4641              : 
    4642    127145589 :   if (ctors)
    4643              :     {
    4644     73671252 :       int ctorflags = flags;
    4645              : 
    4646     73671252 :       first_arg = build_dummy_object (totype);
    4647              : 
    4648              :       /* We should never try to call the abstract or base constructor
    4649              :          from here.  */
    4650    516637152 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (OVL_FIRST (ctors))
    4651              :                   && !DECL_HAS_VTT_PARM_P (OVL_FIRST (ctors)));
    4652              : 
    4653     73671252 :       args = make_tree_vector_single (expr);
    4654     73671252 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4655              :         {
    4656              :           /* List-initialization.  */
    4657      1076990 :           add_list_candidates (ctors, first_arg, args, totype, NULL_TREE,
    4658      1076990 :                                false, TYPE_BINFO (totype), TYPE_BINFO (totype),
    4659              :                                ctorflags, &candidates, complain);
    4660              :         }
    4661              :       else
    4662              :         {
    4663     72594262 :           add_candidates (ctors, first_arg, args, NULL_TREE, NULL_TREE, false,
    4664     72594262 :                           TYPE_BINFO (totype), TYPE_BINFO (totype),
    4665              :                           ctorflags, &candidates, complain);
    4666              :         }
    4667              : 
    4668    394045235 :       for (cand = candidates; cand; cand = cand->next)
    4669              :         {
    4670    320373983 :           cand->second_conv = build_identity_conv (totype, NULL_TREE);
    4671              : 
    4672              :           /* If totype isn't a reference, and LOOKUP_ONLYCONVERTING is
    4673              :              set, then this is copy-initialization.  In that case, "The
    4674              :              result of the call is then used to direct-initialize the
    4675              :              object that is the destination of the copy-initialization."
    4676              :              [dcl.init]
    4677              : 
    4678              :              We represent this in the conversion sequence with an
    4679              :              rvalue conversion, which means a constructor call.  */
    4680    320373983 :           if (!TYPE_REF_P (totype)
    4681    320373983 :               && cxx_dialect < cxx17
    4682       404788 :               && (flags & LOOKUP_ONLYCONVERTING)
    4683       350314 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4684       111068 :             cand->second_conv
    4685       111068 :               = build_conv (ck_rvalue, totype, cand->second_conv);
    4686              :         }
    4687              :     }
    4688              : 
    4689    127145589 :   if (conv_fns)
    4690              :     {
    4691     30109255 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4692            0 :         first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
    4693              :       else
    4694    127145589 :         first_arg = expr;
    4695              :     }
    4696              : 
    4697    162210999 :   for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
    4698              :     {
    4699     35065410 :       tree conversion_path = TREE_PURPOSE (conv_fns);
    4700     35065410 :       struct z_candidate *old_candidates;
    4701              : 
    4702              :       /* If LOOKUP_NO_CONVERSION, don't consider a conversion function that
    4703              :          would need an addional user-defined conversion, i.e. if the return
    4704              :          type differs in class-ness from the desired type.  So we avoid
    4705              :          considering operator bool when calling a copy constructor.
    4706              : 
    4707              :          This optimization avoids the failure in PR97600, and is allowed by
    4708              :          [temp.inst]/9: "If the function selected by overload resolution can be
    4709              :          determined without instantiating a class template definition, it is
    4710              :          unspecified whether that instantiation actually takes place."     */
    4711     35065410 :       tree convtype = non_reference (TREE_TYPE (conv_fns));
    4712     51072778 :       if ((flags & LOOKUP_NO_CONVERSION)
    4713     35065410 :           && !WILDCARD_TYPE_P (convtype)
    4714     66867478 :           && (CLASS_TYPE_P (to_nonref)
    4715     33433739 :               != CLASS_TYPE_P (convtype)))
    4716     16007368 :         continue;
    4717              : 
    4718              :       /* If we are called to convert to a reference type, we are trying to
    4719              :          find a direct binding, so don't even consider temporaries.  If
    4720              :          we don't find a direct binding, the caller will try again to
    4721              :          look for a temporary binding.  */
    4722     19058042 :       if (TYPE_REF_P (totype))
    4723      5087668 :         convflags |= LOOKUP_NO_TEMP_BIND;
    4724              : 
    4725     19058042 :       old_candidates = candidates;
    4726     19058042 :       add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype,
    4727              :                       NULL_TREE, false,
    4728     19058042 :                       conversion_path, TYPE_BINFO (fromtype),
    4729              :                       flags, &candidates, complain);
    4730              : 
    4731     38116079 :       for (cand = candidates; cand != old_candidates; cand = cand->next)
    4732              :         {
    4733     19058037 :           if (cand->viable == 0)
    4734              :             /* Already rejected, don't change to -1.  */
    4735      6472018 :             continue;
    4736              : 
    4737     12586019 :           tree rettype = TREE_TYPE (TREE_TYPE (cand->fn));
    4738     12586019 :           conversion *ics
    4739     12586019 :             = implicit_conversion (totype,
    4740              :                                    rettype,
    4741              :                                    0,
    4742              :                                    /*c_cast_p=*/false, convflags,
    4743              :                                    complain);
    4744              : 
    4745              :           /* If LOOKUP_NO_TEMP_BIND isn't set, then this is
    4746              :              copy-initialization.  In that case, "The result of the
    4747              :              call is then used to direct-initialize the object that is
    4748              :              the destination of the copy-initialization."  [dcl.init]
    4749              : 
    4750              :              We represent this in the conversion sequence with an
    4751              :              rvalue conversion, which means a constructor call.  But
    4752              :              don't add a second rvalue conversion if there's already
    4753              :              one there.  Which there really shouldn't be, but it's
    4754              :              harmless since we'd add it here anyway. */
    4755      4614374 :           if (ics && MAYBE_CLASS_TYPE_P (totype) && ics->kind != ck_rvalue
    4756     13430136 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4757       251371 :             ics = build_conv (ck_rvalue, totype, ics);
    4758              : 
    4759     12586019 :           cand->second_conv = ics;
    4760              : 
    4761     12586019 :           if (!ics)
    4762              :             {
    4763      7971645 :               cand->viable = 0;
    4764     15941511 :               cand->reason = arg_conversion_rejection (NULL_TREE, -2,
    4765              :                                                        rettype, totype,
    4766      7971645 :                                                        EXPR_LOCATION (expr));
    4767              :             }
    4768        14177 :           else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p
    4769              :                    /* Limit this to non-templates for now (PR90546).  */
    4770         1359 :                    && !cand->template_decl
    4771      4615728 :                    && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE)
    4772              :             {
    4773              :               /* If we are called to convert to a reference type, we are trying
    4774              :                  to find a direct binding per [over.match.ref], so rvaluedness
    4775              :                  must match for non-functions.  */
    4776         1348 :               cand->viable = 0;
    4777              :             }
    4778      4613026 :           else if (DECL_NONCONVERTING_P (cand->fn)
    4779      4613026 :                    && ics->rank > cr_exact)
    4780              :             {
    4781              :               /* 13.3.1.5: For direct-initialization, those explicit
    4782              :                  conversion functions that are not hidden within S and
    4783              :                  yield type T or a type that can be converted to type T
    4784              :                  with a qualification conversion (4.4) are also candidate
    4785              :                  functions.  */
    4786              :               /* 13.3.1.6 doesn't have a parallel restriction, but it should;
    4787              :                  I've raised this issue with the committee. --jason 9/2011 */
    4788         2621 :               cand->viable = -1;
    4789         2621 :               cand->reason = explicit_conversion_rejection (rettype, totype);
    4790              :             }
    4791      4610405 :           else if (cand->viable == 1 && ics->bad_p)
    4792              :             {
    4793         1992 :               cand->viable = -1;
    4794         1992 :               cand->reason
    4795         3984 :                 = bad_arg_conversion_rejection (NULL_TREE, -2,
    4796              :                                                 rettype, totype,
    4797         1992 :                                                 EXPR_LOCATION (expr));
    4798              :             }
    4799      4608413 :           else if (primary_template_specialization_p (cand->fn)
    4800      4608413 :                    && ics->rank > cr_exact)
    4801              :             {
    4802              :               /* 13.3.3.1.2: If the user-defined conversion is specified by
    4803              :                  a specialization of a conversion function template, the
    4804              :                  second standard conversion sequence shall have exact match
    4805              :                  rank.  */
    4806           21 :               cand->viable = -1;
    4807           21 :               cand->reason = template_conversion_rejection (rettype, totype);
    4808              :             }
    4809              :         }
    4810              :     }
    4811              : 
    4812    127145589 :   candidates = splice_viable (candidates, false, &any_viable_p);
    4813    127145589 :   if (!any_viable_p)
    4814              :     {
    4815    110523435 :       if (args)
    4816     60805950 :         release_tree_vector (args);
    4817    110523435 :       return NULL;
    4818              :     }
    4819              : 
    4820     16622154 :   cand = tourney (candidates, complain);
    4821     16622154 :   if (cand == NULL)
    4822              :     {
    4823         1339 :       if (complain & tf_error)
    4824              :         {
    4825           71 :           auto_diagnostic_group d;
    4826           74 :           error_at (cp_expr_loc_or_input_loc (expr),
    4827              :                     "conversion from %qH to %qI is ambiguous",
    4828              :                     fromtype, totype);
    4829           71 :           print_z_candidates (location_of (expr), candidates);
    4830           71 :         }
    4831              : 
    4832         1339 :       cand = candidates;        /* any one will do */
    4833         1339 :       cand->second_conv = build_ambiguous_conv (totype, expr);
    4834         1339 :       cand->second_conv->user_conv_p = true;
    4835         2678 :       if (!any_strictly_viable (candidates))
    4836           12 :         cand->second_conv->bad_p = true;
    4837         1339 :       if (flags & LOOKUP_ONLYCONVERTING)
    4838         1266 :         cand->second_conv->need_temporary_p = true;
    4839              :       /* If there are viable candidates, don't set ICS_BAD_FLAG; an
    4840              :          ambiguous conversion is no worse than another user-defined
    4841              :          conversion.  */
    4842              : 
    4843         1339 :       return cand;
    4844              :     }
    4845              : 
    4846              :   /* Maybe pass { } as iterators instead of an initializer_list.  */
    4847     16620815 :   if (tree iters = maybe_init_list_as_range (cand->fn, expr))
    4848          106 :     if (z_candidate *cand2
    4849           53 :         = build_user_type_conversion_1 (totype, iters, flags, tf_none))
    4850           50 :       if (cand2->viable == 1 && !is_list_ctor (cand2->fn))
    4851              :         {
    4852              :           cand = cand2;
    4853              :           expr = iters;
    4854              :         }
    4855              : 
    4856     16620815 :   tree convtype;
    4857     33241630 :   if (!DECL_CONSTRUCTOR_P (cand->fn))
    4858      4600933 :     convtype = non_reference (TREE_TYPE (TREE_TYPE (cand->fn)));
    4859     12019882 :   else if (cand->second_conv->kind == ck_rvalue)
    4860              :     /* DR 5: [in the first step of copy-initialization]...if the function
    4861              :        is a constructor, the call initializes a temporary of the
    4862              :        cv-unqualified version of the destination type. */
    4863        11494 :     convtype = cv_unqualified (totype);
    4864              :   else
    4865              :     convtype = totype;
    4866              :   /* Build the user conversion sequence.  */
    4867     16620815 :   conv = build_conv
    4868     16620815 :     (ck_user,
    4869              :      convtype,
    4870     16620815 :      build_identity_conv (TREE_TYPE (expr), expr));
    4871     16620815 :   conv->cand = cand;
    4872     16620815 :   if (cand->viable == -1)
    4873         7772 :     conv->bad_p = true;
    4874              : 
    4875              :   /* Remember that this was a list-initialization.  */
    4876     16620815 :   if (flags & LOOKUP_NO_NARROWING)
    4877      3343101 :     conv->check_narrowing = true;
    4878              : 
    4879              :   /* Combine it with the second conversion sequence.  */
    4880     16620815 :   cand->second_conv = merge_conversion_sequences (conv,
    4881              :                                                   cand->second_conv);
    4882              : 
    4883     16620815 :   return cand;
    4884              : }
    4885              : 
    4886              : /* Wrapper for above. */
    4887              : 
    4888              : tree
    4889        51118 : build_user_type_conversion (tree totype, tree expr, int flags,
    4890              :                             tsubst_flags_t complain)
    4891              : {
    4892        51118 :   struct z_candidate *cand;
    4893        51118 :   tree ret;
    4894              : 
    4895        51118 :   auto_cond_timevar tv (TV_OVERLOAD);
    4896              : 
    4897        51118 :   conversion_obstack_sentinel cos;
    4898              : 
    4899        51118 :   cand = build_user_type_conversion_1 (totype, expr, flags, complain);
    4900              : 
    4901        51118 :   if (cand)
    4902              :     {
    4903        50915 :       if (cand->second_conv->kind == ck_ambig)
    4904           65 :         ret = error_mark_node;
    4905              :       else
    4906              :         {
    4907        50850 :           expr = convert_like (cand->second_conv, expr, complain);
    4908        50850 :           ret = convert_from_reference (expr);
    4909              :         }
    4910              :     }
    4911              :   else
    4912              :     ret = NULL_TREE;
    4913              : 
    4914       102236 :   return ret;
    4915        51118 : }
    4916              : 
    4917              : /* Give a helpful diagnostic when implicit_conversion fails.  */
    4918              : 
    4919              : static void
    4920          668 : implicit_conversion_error (location_t loc, tree type, tree expr,
    4921              :                            int flags)
    4922              : {
    4923          668 :   tsubst_flags_t complain = tf_warning_or_error;
    4924              : 
    4925              :   /* If expr has unknown type, then it is an overloaded function.
    4926              :      Call instantiate_type to get good error messages.  */
    4927          668 :   if (TREE_TYPE (expr) == unknown_type_node)
    4928           58 :     instantiate_type (type, expr, complain);
    4929          610 :   else if (invalid_nonstatic_memfn_p (loc, expr, complain))
    4930              :     /* We gave an error.  */;
    4931           70 :   else if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    4932           67 :            && CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    4933          623 :            && !CP_AGGREGATE_TYPE_P (type))
    4934           18 :     error_at (loc, "designated initializers cannot be used with a "
    4935              :               "non-aggregate type %qT", type);
    4936              :   else
    4937              :     {
    4938          587 :       auto_diagnostic_group d;
    4939          587 :       if (is_stub_object (expr))
    4940              :         /* The expression is generated by a trait check, we don't have
    4941              :            a useful location to highlight the label.  */
    4942           17 :         error_at (loc, "could not convert %qH to %qI",
    4943           17 :                   TREE_TYPE (expr), type);
    4944              :       else
    4945              :         {
    4946          570 :           range_label_for_type_mismatch label (TREE_TYPE (expr), type);
    4947          570 :           gcc_rich_location rich_loc (loc, &label,
    4948          570 :                                       highlight_colors::percent_h);
    4949          570 :           error_at (&rich_loc, "could not convert %qE from %qH to %qI",
    4950          570 :                     expr, TREE_TYPE (expr), type);
    4951          570 :         }
    4952          587 :       maybe_show_nonconverting_candidate (type, TREE_TYPE (expr), expr, flags);
    4953          587 :     }
    4954          668 : }
    4955              : 
    4956              : /* Worker for build_converted_constant_expr.  */
    4957              : 
    4958              : static tree
    4959    345150226 : build_converted_constant_expr_internal (tree type, tree expr,
    4960              :                                         int flags, tsubst_flags_t complain)
    4961              : {
    4962    345150226 :   conversion *conv;
    4963    345150226 :   tree t;
    4964    345150226 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    4965              : 
    4966    345150226 :   if (error_operand_p (expr))
    4967           51 :     return error_mark_node;
    4968              : 
    4969    345150175 :   conversion_obstack_sentinel cos;
    4970              : 
    4971    345150175 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
    4972              :                               /*c_cast_p=*/false, flags, complain);
    4973              : 
    4974              :   /* A converted constant expression of type T is an expression, implicitly
    4975              :      converted to type T, where the converted expression is a constant
    4976              :      expression and the implicit conversion sequence contains only
    4977              : 
    4978              :        * user-defined conversions,
    4979              :        * lvalue-to-rvalue conversions (7.1),
    4980              :        * array-to-pointer conversions (7.2),
    4981              :        * function-to-pointer conversions (7.3),
    4982              :        * qualification conversions (7.5),
    4983              :        * integral promotions (7.6),
    4984              :        * integral conversions (7.8) other than narrowing conversions (11.6.4),
    4985              :        * null pointer conversions (7.11) from std::nullptr_t,
    4986              :        * null member pointer conversions (7.12) from std::nullptr_t, and
    4987              :        * function pointer conversions (7.13),
    4988              : 
    4989              :      and where the reference binding (if any) binds directly.  */
    4990              : 
    4991    345150175 :   for (conversion *c = conv;
    4992    408576270 :        c && c->kind != ck_identity;
    4993     63426095 :        c = next_conversion (c))
    4994              :     {
    4995     63426095 :       switch (c->kind)
    4996              :         {
    4997              :           /* A conversion function is OK.  If it isn't constexpr, we'll
    4998              :              complain later that the argument isn't constant.  */
    4999              :         case ck_user:
    5000              :           /* List-initialization is OK.  */
    5001              :         case ck_aggr:
    5002              :           /* The lvalue-to-rvalue conversion is OK.  */
    5003              :         case ck_rvalue:
    5004              :           /* Array-to-pointer and function-to-pointer.  */
    5005              :         case ck_lvalue:
    5006              :           /* Function pointer conversions.  */
    5007              :         case ck_fnptr:
    5008              :           /* Qualification conversions.  */
    5009              :         case ck_qual:
    5010              :           break;
    5011              : 
    5012          536 :         case ck_ref_bind:
    5013          536 :           if (c->need_temporary_p)
    5014              :             {
    5015            0 :               if (complain & tf_error)
    5016            0 :                 error_at (loc, "initializing %qH with %qI in converted "
    5017              :                           "constant expression does not bind directly",
    5018            0 :                           type, next_conversion (c)->type);
    5019              :               conv = NULL;
    5020              :             }
    5021              :           break;
    5022              : 
    5023     10334877 :         case ck_base:
    5024     10334877 :         case ck_pmem:
    5025     10334877 :         case ck_ptr:
    5026     10334877 :         case ck_std:
    5027     10334877 :           t = next_conversion (c)->type;
    5028     10334877 :           if (INTEGRAL_OR_ENUMERATION_TYPE_P (t)
    5029     10334802 :               && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    5030              :             /* Integral promotion or conversion.  */
    5031              :             break;
    5032          106 :           if (NULLPTR_TYPE_P (t))
    5033              :             /* Conversion from nullptr to pointer or pointer-to-member.  */
    5034              :             break;
    5035              : 
    5036          106 :           if (complain & tf_error)
    5037           80 :             error_at (loc, "conversion from %qH to %qI in a "
    5038              :                       "converted constant expression", t, type);
    5039              :           /* fall through.  */
    5040              : 
    5041              :         default:
    5042              :           conv = NULL;
    5043              :           break;
    5044              :         }
    5045              :     }
    5046              : 
    5047              :   /* Avoid confusing convert_nontype_argument by introducing
    5048              :      a redundant conversion to the same reference type.  */
    5049    345149523 :   if (conv && conv->kind == ck_ref_bind
    5050    345150711 :       && REFERENCE_REF_P (expr))
    5051              :     {
    5052          290 :       tree ref = TREE_OPERAND (expr, 0);
    5053          290 :       if (same_type_p (type, TREE_TYPE (ref)))
    5054              :         return ref;
    5055              :     }
    5056              : 
    5057    345149907 :   if (conv)
    5058              :     {
    5059              :       /* Don't copy a class in a template.  */
    5060        26979 :       if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue
    5061    345163510 :           && processing_template_decl)
    5062          155 :         conv = next_conversion (conv);
    5063              : 
    5064              :       /* Issuing conversion warnings for value-dependent expressions is
    5065              :          likely too noisy.  */
    5066    345149255 :       warning_sentinel w (warn_conversion);
    5067    345149255 :       conv->check_narrowing = true;
    5068    345149255 :       conv->check_narrowing_const_only = true;
    5069    345149255 :       expr = convert_like (conv, expr, complain);
    5070    345149255 :     }
    5071              :   else
    5072              :     {
    5073          652 :       if (complain & tf_error)
    5074          189 :         implicit_conversion_error (loc, type, expr, flags);
    5075          652 :       expr = error_mark_node;
    5076              :     }
    5077              : 
    5078              :   return expr;
    5079    345150175 : }
    5080              : 
    5081              : /* Subroutine of convert_nontype_argument.
    5082              : 
    5083              :    EXPR is an expression used in a context that requires a converted
    5084              :    constant-expression, such as a template non-type parameter.  Do any
    5085              :    necessary conversions (that are permitted for converted
    5086              :    constant-expressions) to convert it to the desired type.
    5087              : 
    5088              :    This function doesn't consider explicit conversion functions.  If
    5089              :    you mean to use "a contextually converted constant expression of type
    5090              :    bool", use build_converted_constant_bool_expr.
    5091              : 
    5092              :    If conversion is successful, returns the converted expression;
    5093              :    otherwise, returns error_mark_node.  */
    5094              : 
    5095              : tree
    5096    214834705 : build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
    5097              : {
    5098    214834705 :   return build_converted_constant_expr_internal (type, expr, LOOKUP_IMPLICIT,
    5099    214834705 :                                                  complain);
    5100              : }
    5101              : 
    5102              : /* Used to create "a contextually converted constant expression of type
    5103              :    bool".  This differs from build_converted_constant_expr in that it
    5104              :    also considers explicit conversion functions.  */
    5105              : 
    5106              : tree
    5107    130315521 : build_converted_constant_bool_expr (tree expr, tsubst_flags_t complain)
    5108              : {
    5109    130315521 :   return build_converted_constant_expr_internal (boolean_type_node, expr,
    5110    130315521 :                                                  LOOKUP_NORMAL, complain);
    5111              : }
    5112              : 
    5113              : /* Do any initial processing on the arguments to a function call.  */
    5114              : 
    5115              : vec<tree, va_gc> *
    5116    268011570 : resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
    5117              : {
    5118    268011570 :   unsigned int ix;
    5119    268011570 :   tree arg;
    5120              : 
    5121    493722814 :   FOR_EACH_VEC_SAFE_ELT (args, ix, arg)
    5122              :     {
    5123    225711845 :       if (error_operand_p (arg))
    5124              :         return NULL;
    5125    225711376 :       else if (VOID_TYPE_P (TREE_TYPE (arg)))
    5126              :         {
    5127          105 :           if (complain & tf_error)
    5128           12 :             error_at (cp_expr_loc_or_input_loc (arg),
    5129              :                       "invalid use of void expression");
    5130          105 :           return NULL;
    5131              :         }
    5132    225711271 :       else if (invalid_nonstatic_memfn_p (EXPR_LOCATION (arg), arg, complain))
    5133              :         return NULL;
    5134              : 
    5135              :       /* Force auto deduction now.  Omit tf_warning to avoid redundant
    5136              :          deprecated warning on deprecated-14.C.  */
    5137    225711244 :       if (!mark_single_function (arg, complain & ~tf_warning))
    5138              :         return NULL;
    5139              :     }
    5140              :   return args;
    5141              : }
    5142              : 
    5143              : /* Perform overload resolution on FN, which is called with the ARGS.
    5144              : 
    5145              :    Return the candidate function selected by overload resolution, or
    5146              :    NULL if the event that overload resolution failed.  In the case
    5147              :    that overload resolution fails, *CANDIDATES will be the set of
    5148              :    candidates considered, and ANY_VIABLE_P will be set to true or
    5149              :    false to indicate whether or not any of the candidates were
    5150              :    viable.
    5151              : 
    5152              :    The ARGS should already have gone through RESOLVE_ARGS before this
    5153              :    function is called.  */
    5154              : 
    5155              : static struct z_candidate *
    5156    131602880 : perform_overload_resolution (tree fn,
    5157              :                              const vec<tree, va_gc> *args,
    5158              :                              struct z_candidate **candidates,
    5159              :                              bool *any_viable_p, tsubst_flags_t complain)
    5160              : {
    5161    131602880 :   struct z_candidate *cand;
    5162    131602880 :   tree explicit_targs;
    5163    131602880 :   int template_only;
    5164              : 
    5165    131602880 :   auto_cond_timevar tv (TV_OVERLOAD);
    5166              : 
    5167    131602880 :   explicit_targs = NULL_TREE;
    5168    131602880 :   template_only = 0;
    5169              : 
    5170    131602880 :   *candidates = NULL;
    5171    131602880 :   *any_viable_p = true;
    5172              : 
    5173              :   /* Check FN.  */
    5174    131602880 :   gcc_assert (OVL_P (fn) || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
    5175              : 
    5176    131602880 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5177              :     {
    5178     50367036 :       explicit_targs = TREE_OPERAND (fn, 1);
    5179     50367036 :       fn = TREE_OPERAND (fn, 0);
    5180     50367036 :       template_only = 1;
    5181              :     }
    5182              : 
    5183              :   /* Add the various candidate functions.  */
    5184    131602880 :   add_candidates (fn, NULL_TREE, args, NULL_TREE,
    5185              :                   explicit_targs, template_only,
    5186              :                   /*conversion_path=*/NULL_TREE,
    5187              :                   /*access_path=*/NULL_TREE,
    5188              :                   LOOKUP_NORMAL,
    5189              :                   candidates, complain & ~tf_any_viable);
    5190              : 
    5191    131589362 :   *candidates = splice_viable (*candidates, false, any_viable_p);
    5192    131589362 :   if (*any_viable_p)
    5193              :     {
    5194    131320483 :       if (complain & tf_any_viable)
    5195              :         cand = *candidates;
    5196              :       else
    5197    131320375 :         cand = tourney (*candidates, complain);
    5198              :     }
    5199              :   else
    5200              :     cand = NULL;
    5201              : 
    5202    263178724 :   return cand;
    5203    131589362 : }
    5204              : 
    5205              : /* Print an error message about being unable to build a call to FN with
    5206              :    ARGS.  ANY_VIABLE_P indicates whether any candidate functions could
    5207              :    be located; CANDIDATES is a possibly empty list of such
    5208              :    functions.  */
    5209              : 
    5210              : static void
    5211         2896 : print_error_for_call_failure (tree fn, const vec<tree, va_gc> *args,
    5212              :                               struct z_candidate *candidates)
    5213              : {
    5214         2896 :   tree targs = NULL_TREE;
    5215         2896 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5216              :     {
    5217          501 :       targs = TREE_OPERAND (fn, 1);
    5218          501 :       fn = TREE_OPERAND (fn, 0);
    5219              :     }
    5220         5792 :   tree name = OVL_NAME (fn);
    5221         2896 :   location_t loc = location_of (name);
    5222         2896 :   if (targs)
    5223          501 :     name = lookup_template_function (name, targs);
    5224              : 
    5225         2896 :   auto_diagnostic_group d;
    5226         5792 :   if (!any_strictly_viable (candidates))
    5227         2419 :     error_at (loc, "no matching function for call to %<%D(%A)%>",
    5228              :               name, build_tree_list_vec (args));
    5229              :   else
    5230          477 :     error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous",
    5231              :               name, build_tree_list_vec (args));
    5232         2896 :   if (candidates)
    5233         2896 :     print_z_candidates (loc, candidates);
    5234         2896 : }
    5235              : 
    5236              : /* Perform overload resolution on the set of deduction guides DGUIDES
    5237              :    using ARGS.  Returns the selected deduction guide, or error_mark_node
    5238              :    if overload resolution fails.  */
    5239              : 
    5240              : tree
    5241        42474 : perform_dguide_overload_resolution (tree dguides, const vec<tree, va_gc> *args,
    5242              :                                     tsubst_flags_t complain)
    5243              : {
    5244        42474 :   z_candidate *candidates;
    5245        42474 :   bool any_viable_p;
    5246        42474 :   tree result;
    5247              : 
    5248        84948 :   gcc_assert (deduction_guide_p (OVL_FIRST (dguides)));
    5249              : 
    5250        42474 :   conversion_obstack_sentinel cos;
    5251              : 
    5252        42474 :   z_candidate *cand = perform_overload_resolution (dguides, args, &candidates,
    5253              :                                                    &any_viable_p, complain);
    5254        42474 :   if (!cand)
    5255              :     {
    5256          896 :       if (complain & tf_error)
    5257          192 :         print_error_for_call_failure (dguides, args, candidates);
    5258          896 :       result = error_mark_node;
    5259              :     }
    5260              :   else
    5261        41578 :     result = cand->fn;
    5262              : 
    5263        84948 :   return result;
    5264        42474 : }
    5265              : 
    5266              : /* Return an expression for a call to FN (a namespace-scope function,
    5267              :    or a static member function) with the ARGS.  This may change
    5268              :    ARGS.  */
    5269              : 
    5270              : tree
    5271    130528988 : build_new_function_call (tree fn, vec<tree, va_gc> **args,
    5272              :                          tsubst_flags_t complain)
    5273              : {
    5274    130528988 :   struct z_candidate *candidates, *cand;
    5275    130528988 :   bool any_viable_p;
    5276    130528988 :   tree result;
    5277              : 
    5278    130528988 :   if (args != NULL && *args != NULL)
    5279              :     {
    5280    130528988 :       *args = resolve_args (*args, complain & ~tf_any_viable);
    5281    130528988 :       if (*args == NULL)
    5282          328 :         return error_mark_node;
    5283              :     }
    5284              : 
    5285    130528660 :   if (flag_tm)
    5286         3537 :     tm_malloc_replacement (fn);
    5287              : 
    5288    130528660 :   conversion_obstack_sentinel cos;
    5289              : 
    5290    130528660 :   cand = perform_overload_resolution (fn, *args, &candidates, &any_viable_p,
    5291              :                                       complain);
    5292              : 
    5293    130515142 :   if (!cand)
    5294              :     {
    5295       352513 :       if (complain & tf_error)
    5296              :         {
    5297              :           // If there is a single (non-viable) function candidate,
    5298              :           // let the error be diagnosed by cp_build_function_call_vec.
    5299         3118 :           if (!any_viable_p && candidates && ! candidates->next
    5300         1343 :               && TREE_CODE (candidates->fn) == FUNCTION_DECL
    5301              :               /* A template-id callee consisting of a single (ignored)
    5302              :                  non-template candidate needs to be diagnosed the
    5303              :                  ordinary way.  */
    5304          433 :               && (TREE_CODE (fn) != TEMPLATE_ID_EXPR
    5305           31 :                   || candidates->template_decl))
    5306          423 :             return cp_build_function_call_vec (candidates->fn, args, complain);
    5307              : 
    5308              :           // Otherwise, emit notes for non-viable candidates.
    5309         2695 :           print_error_for_call_failure (fn, *args, candidates);
    5310              :         }
    5311       352090 :       result = error_mark_node;
    5312              :     }
    5313    130162629 :   else if (complain & tf_any_viable)
    5314          108 :     return void_node;
    5315              :   else
    5316    130162521 :     result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5317              : 
    5318    130514611 :   if (flag_coroutines
    5319    128459559 :       && result
    5320    128459559 :       && TREE_CODE (result) == CALL_EXPR
    5321    203595517 :       && DECL_BUILT_IN_CLASS (TREE_OPERAND (CALL_EXPR_FN (result), 0))
    5322     73080906 :           == BUILT_IN_NORMAL)
    5323      8716098 :    result = coro_validate_builtin_call (result);
    5324              : 
    5325              :   return result;
    5326    130515142 : }
    5327              : 
    5328              : /* Build a call to a global operator new.  FNNAME is the name of the
    5329              :    operator (either "operator new" or "operator new[]") and ARGS are
    5330              :    the arguments provided.  This may change ARGS.  *SIZE points to the
    5331              :    total number of bytes required by the allocation, and is updated if
    5332              :    that is changed here.  *COOKIE_SIZE is non-NULL if a cookie should
    5333              :    be used.  If this function determines that no cookie should be
    5334              :    used, after all, *COOKIE_SIZE is set to NULL_TREE.  If SIZE_CHECK
    5335              :    is not NULL_TREE, it is evaluated before calculating the final
    5336              :    array size, and if it fails, the array size is replaced with
    5337              :    (size_t)-1 (usually triggering a std::bad_alloc exception).  If FN
    5338              :    is non-NULL, it will be set, upon return, to the allocation
    5339              :    function called.  */
    5340              : 
    5341              : tree
    5342      1031723 : build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
    5343              :                          tree *size, tree *cookie_size,
    5344              :                          tree align_arg, tree size_check,
    5345              :                          tree *fn, tsubst_flags_t complain)
    5346              : {
    5347      1031723 :   tree original_size = *size;
    5348      1031723 :   tree fns;
    5349      1031723 :   struct z_candidate *candidates;
    5350      1031723 :   struct z_candidate *cand = NULL;
    5351      1031723 :   bool any_viable_p;
    5352              : 
    5353      1031723 :   if (fn)
    5354      1030303 :     *fn = NULL_TREE;
    5355              :   /* Set to (size_t)-1 if the size check fails.  */
    5356      1031723 :   if (size_check != NULL_TREE)
    5357              :     {
    5358        19937 :       tree errval = TYPE_MAX_VALUE (sizetype);
    5359        19937 :       if (cxx_dialect >= cxx11 && flag_exceptions)
    5360        19577 :         errval = throw_bad_array_new_length ();
    5361        19937 :       *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5362              :                            original_size, errval);
    5363              :     }
    5364      1031723 :   vec_safe_insert (*args, 0, *size);
    5365      1031723 :   *args = resolve_args (*args, complain);
    5366      1031723 :   if (*args == NULL)
    5367            0 :     return error_mark_node;
    5368              : 
    5369      1031723 :   conversion_obstack_sentinel cos;
    5370              : 
    5371              :   /* Based on:
    5372              : 
    5373              :        [expr.new]
    5374              : 
    5375              :        If this lookup fails to find the name, or if the allocated type
    5376              :        is not a class type, the allocation function's name is looked
    5377              :        up in the global scope.
    5378              : 
    5379              :      we disregard block-scope declarations of "operator new".  */
    5380      1031723 :   fns = lookup_qualified_name (global_namespace, fnname);
    5381              : 
    5382      1031723 :   if (align_arg)
    5383              :     {
    5384         8960 :       vec<tree, va_gc>* align_args
    5385         8960 :         = vec_copy_and_insert (*args, align_arg, 1);
    5386         8960 :       cand = perform_overload_resolution (fns, align_args, &candidates,
    5387              :                                           &any_viable_p, tf_none);
    5388         8960 :       if (cand)
    5389         8937 :         *args = align_args;
    5390              :       /* If no aligned allocation function matches, try again without the
    5391              :          alignment.  */
    5392              :     }
    5393              : 
    5394              :   /* Figure out what function is being called.  */
    5395         8937 :   if (!cand)
    5396      1022786 :     cand = perform_overload_resolution (fns, *args, &candidates, &any_viable_p,
    5397              :                                         complain);
    5398              : 
    5399              :   /* If no suitable function could be found, issue an error message
    5400              :      and give up.  */
    5401      1031723 :   if (!cand)
    5402              :     {
    5403            9 :       if (complain & tf_error)
    5404            9 :         print_error_for_call_failure (fns, *args, candidates);
    5405            9 :       return error_mark_node;
    5406              :     }
    5407              : 
    5408              :    /* If a cookie is required, add some extra space.  Whether
    5409              :       or not a cookie is required cannot be determined until
    5410              :       after we know which function was called.  */
    5411      1031714 :    if (*cookie_size)
    5412              :      {
    5413          268 :        bool use_cookie = true;
    5414          268 :        tree arg_types;
    5415              : 
    5416          268 :        arg_types = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    5417              :        /* Skip the size_t parameter.  */
    5418          268 :        arg_types = TREE_CHAIN (arg_types);
    5419              :        /* Check the remaining parameters (if any).  */
    5420          268 :        if (arg_types
    5421          268 :            && TREE_CHAIN (arg_types) == void_list_node
    5422          331 :            && same_type_p (TREE_VALUE (arg_types),
    5423              :                            ptr_type_node))
    5424           48 :          use_cookie = false;
    5425              :        /* If we need a cookie, adjust the number of bytes allocated.  */
    5426          268 :        if (use_cookie)
    5427              :          {
    5428              :            /* Update the total size.  */
    5429          220 :            *size = size_binop (PLUS_EXPR, original_size, *cookie_size);
    5430          220 :            if (size_check)
    5431              :              {
    5432              :                /* Set to (size_t)-1 if the size check fails.  */
    5433           47 :                gcc_assert (size_check != NULL_TREE);
    5434           47 :                *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5435              :                                     *size, TYPE_MAX_VALUE (sizetype));
    5436              :             }
    5437              :            /* Update the argument list to reflect the adjusted size.  */
    5438          220 :            (**args)[0] = *size;
    5439              :          }
    5440              :        else
    5441           48 :          *cookie_size = NULL_TREE;
    5442              :      }
    5443              : 
    5444              :    /* Tell our caller which function we decided to call.  */
    5445      1031714 :    if (fn)
    5446      1030294 :      *fn = cand->fn;
    5447              : 
    5448              :    /* Build the CALL_EXPR.  */
    5449      1031714 :    tree ret = build_over_call (cand, LOOKUP_NORMAL, complain);
    5450              : 
    5451              :    /* Set this flag for all callers of this function.  In addition to
    5452              :       new-expressions, this is called for allocating coroutine state; treat
    5453              :       that as an implicit new-expression.  */
    5454      1031714 :    tree call = extract_call_expr (ret);
    5455      1031714 :    if (TREE_CODE (call) == CALL_EXPR)
    5456      1031714 :      CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    5457              : 
    5458              :    return ret;
    5459      1031723 : }
    5460              : 
    5461              : /* Evaluate side-effects from OBJ before evaluating call
    5462              :    to FN in RESULT expression.
    5463              :    This is for expressions of the form `obj->fn(...)'
    5464              :    where `fn' turns out to be a static member function and
    5465              :    `obj' needs to be evaluated.  `fn' could be also static operator[]
    5466              :    or static operator(), in which cases the source expression
    5467              :    would be `obj[...]' or `obj(...)'.  */
    5468              : 
    5469              : tree
    5470    102524286 : keep_unused_object_arg (tree result, tree obj, tree fn)
    5471              : {
    5472    102524286 :   if (result == NULL_TREE
    5473    102524286 :       || result == error_mark_node
    5474    101421605 :       || DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    5475    105514435 :       || !TREE_SIDE_EFFECTS (obj))
    5476              :     return result;
    5477              : 
    5478              :   /* But avoid the implicit lvalue-rvalue conversion when `obj' is
    5479              :      volatile.  */
    5480        82700 :   tree a = obj;
    5481        82700 :   if (TREE_THIS_VOLATILE (a))
    5482        55146 :     a = build_this (a);
    5483        82700 :   if (TREE_SIDE_EFFECTS (a))
    5484        27563 :     return cp_build_compound_expr (a, result, tf_error);
    5485              :   return result;
    5486              : }
    5487              : 
    5488              : /* Build a new call to operator().  This may change ARGS.  */
    5489              : 
    5490              : tree
    5491      4410278 : build_op_call (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
    5492              : {
    5493      4410278 :   struct z_candidate *candidates = 0, *cand;
    5494      4410278 :   tree fns, convs, first_mem_arg = NULL_TREE;
    5495      4410278 :   bool any_viable_p;
    5496      4410278 :   tree result = NULL_TREE;
    5497              : 
    5498      4410278 :   auto_cond_timevar tv (TV_OVERLOAD);
    5499              : 
    5500      4410278 :   obj = mark_lvalue_use (obj);
    5501              : 
    5502      4410278 :   if (error_operand_p (obj))
    5503            0 :     return error_mark_node;
    5504              : 
    5505      4410278 :   tree type = TREE_TYPE (obj);
    5506              : 
    5507      4410278 :   obj = prep_operand (obj);
    5508              : 
    5509      4410278 :   if (TYPE_PTRMEMFUNC_P (type))
    5510              :     {
    5511            0 :       if (complain & tf_error)
    5512              :         /* It's no good looking for an overloaded operator() on a
    5513              :            pointer-to-member-function.  */
    5514            0 :         error ("pointer-to-member function %qE cannot be called without "
    5515              :                "an object; consider using %<.*%> or %<->*%>", obj);
    5516            0 :       return error_mark_node;
    5517              :     }
    5518              : 
    5519      4410278 :   if (TYPE_BINFO (type))
    5520              :     {
    5521      4410260 :       fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1, complain);
    5522      4410260 :       if (fns == error_mark_node)
    5523              :         return error_mark_node;
    5524              :     }
    5525              :   else
    5526              :     fns = NULL_TREE;
    5527              : 
    5528      4410268 :   if (args != NULL && *args != NULL)
    5529              :     {
    5530      4410268 :       *args = resolve_args (*args, complain);
    5531      4410268 :       if (*args == NULL)
    5532          109 :         return error_mark_node;
    5533              :     }
    5534              : 
    5535      4410159 :   conversion_obstack_sentinel cos;
    5536              : 
    5537      4410159 :   if (fns)
    5538              :     {
    5539      4407247 :       first_mem_arg = obj;
    5540              : 
    5541      4407247 :       add_candidates (BASELINK_FUNCTIONS (fns),
    5542              :                       first_mem_arg, *args, NULL_TREE,
    5543              :                       NULL_TREE, false,
    5544      4407247 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    5545              :                       LOOKUP_NORMAL, &candidates, complain);
    5546              :     }
    5547              : 
    5548      4410159 :   bool any_call_ops = candidates != nullptr;
    5549              : 
    5550      4410159 :   convs = lookup_conversions (type);
    5551              : 
    5552      4574690 :   for (; convs; convs = TREE_CHAIN (convs))
    5553              :     {
    5554       164531 :       tree totype = TREE_TYPE (convs);
    5555              : 
    5556       145215 :       if (TYPE_PTRFN_P (totype)
    5557        19319 :           || TYPE_REFFN_P (totype)
    5558       183806 :           || (TYPE_REF_P (totype)
    5559          888 :               && TYPE_PTRFN_P (TREE_TYPE (totype))))
    5560       290810 :         for (tree fn : ovl_range (TREE_VALUE (convs)))
    5561              :           {
    5562       145405 :             if (DECL_NONCONVERTING_P (fn))
    5563            3 :               continue;
    5564              : 
    5565       145402 :             if (TREE_CODE (fn) == TEMPLATE_DECL)
    5566              :               {
    5567              :                 /* Making this work broke PR 71117 and 85118, so until the
    5568              :                    committee resolves core issue 2189, let's disable this
    5569              :                    candidate if there are any call operators.  */
    5570        34209 :                 if (any_call_ops)
    5571        34197 :                   continue;
    5572              : 
    5573           12 :                 add_template_conv_candidate
    5574           12 :                   (&candidates, fn, obj, *args, totype,
    5575              :                    /*access_path=*/NULL_TREE,
    5576              :                    /*conversion_path=*/NULL_TREE, complain);
    5577              :               }
    5578              :             else
    5579       111193 :               add_conv_candidate (&candidates, fn, obj,
    5580              :                                   *args, /*conversion_path=*/NULL_TREE,
    5581              :                                   /*access_path=*/NULL_TREE, complain);
    5582              :           }
    5583              :     }
    5584              : 
    5585              :   /* Be strict here because if we choose a bad conversion candidate, the
    5586              :      errors we get won't mention the call context.  */
    5587      4410159 :   candidates = splice_viable (candidates, true, &any_viable_p);
    5588      4410159 :   if (!any_viable_p)
    5589              :     {
    5590        27076 :       if (complain & tf_error)
    5591              :         {
    5592          277 :           auto_diagnostic_group d;
    5593          277 :           error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj),
    5594              :                  build_tree_list_vec (*args));
    5595          277 :           print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5596          277 :         }
    5597        27076 :       result = error_mark_node;
    5598              :     }
    5599              :   else
    5600              :     {
    5601      4383083 :       cand = tourney (candidates, complain);
    5602      4383083 :       if (cand == 0)
    5603              :         {
    5604           17 :           if (complain & tf_error)
    5605              :             {
    5606            6 :               auto_diagnostic_group d;
    5607           12 :               error ("call of %<(%T) (%A)%> is ambiguous",
    5608            6 :                      TREE_TYPE (obj), build_tree_list_vec (*args));
    5609            6 :               print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5610            6 :             }
    5611           17 :           result = error_mark_node;
    5612              :         }
    5613      4383066 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    5614      4382999 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    5615      8766065 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, CALL_EXPR))
    5616              :         {
    5617      4382999 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5618              :           /* In an expression of the form `a()' where cand->fn
    5619              :              which is operator() turns out to be a static member function,
    5620              :              `a' is none-the-less evaluated.  */
    5621      4382999 :           result = keep_unused_object_arg (result, obj, cand->fn);
    5622              :         }
    5623              :       else
    5624              :         {
    5625           67 :           if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    5626            0 :             obj = convert_like_with_context (cand->convs[0], obj, cand->fn,
    5627              :                                              -1, complain);
    5628              :           else
    5629              :             {
    5630           67 :               gcc_checking_assert (TYPE_P (cand->fn));
    5631           67 :               obj = convert_like (cand->convs[0], obj, complain);
    5632              :             }
    5633           67 :           obj = convert_from_reference (obj);
    5634           67 :           result = cp_build_function_call_vec (obj, args, complain);
    5635              :         }
    5636              :     }
    5637              : 
    5638      4410159 :   return result;
    5639      4410278 : }
    5640              : 
    5641              : /* Subroutine for preparing format strings suitable for the error
    5642              :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    5643              :    and SUFFIX.  */
    5644              : 
    5645              : static const char *
    5646         1462 : concat_op_error_string (bool match, const char *errmsg, const char *suffix)
    5647              : {
    5648         1462 :   return concat (match
    5649              :                  ? G_("ambiguous overload for ")
    5650              :                  : G_("no match for "),
    5651            0 :                  errmsg, suffix, nullptr);
    5652              : }
    5653              : 
    5654              : /* Called by op_error to prepare format strings suitable for the error
    5655              :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    5656              :    and a suffix (controlled by NTYPES).  */
    5657              : 
    5658              : static const char *
    5659         1441 : op_error_string (const char *errmsg, int ntypes, bool match)
    5660              : {
    5661         1441 :   const char *suffix;
    5662            0 :   if (ntypes == 3)
    5663              :     suffix = G_(" (operand types are %qT, %qT, and %qT)");
    5664            0 :   else if (ntypes == 2)
    5665              :     suffix = G_(" (operand types are %qT and %qT)");
    5666              :   else
    5667            0 :     suffix = G_(" (operand type is %qT)");
    5668            0 :   return concat_op_error_string (match, errmsg, suffix);
    5669              : }
    5670              : 
    5671              : /* Similar to op_error_string, but a special-case for binary ops that
    5672              :    use %e for the args, rather than %qT.  */
    5673              : 
    5674              : static const char *
    5675           21 : binop_error_string (const char *errmsg, bool match)
    5676              : {
    5677           21 :   return concat_op_error_string (match, errmsg,
    5678           21 :                                  G_(" (operand types are %e and %e)"));
    5679              : }
    5680              : 
    5681              : static void
    5682         1462 : op_error (const op_location_t &loc,
    5683              :           enum tree_code code, enum tree_code code2,
    5684              :           tree arg1, tree arg2, tree arg3, bool match)
    5685              : {
    5686         1462 :   bool assop = code == MODIFY_EXPR;
    5687         1462 :   const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
    5688              : 
    5689         1462 :   switch (code)
    5690              :     {
    5691            0 :     case COND_EXPR:
    5692            0 :       if (flag_diagnostics_show_caret)
    5693            0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%>"),
    5694              :                                         3, match),
    5695            0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    5696              :       else
    5697            0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%> "
    5698              :                                            "in %<%E ? %E : %E%>"), 3, match),
    5699              :                   arg1, arg2, arg3,
    5700            0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    5701              :       break;
    5702              : 
    5703            0 :     case POSTINCREMENT_EXPR:
    5704            0 :     case POSTDECREMENT_EXPR:
    5705            0 :       if (flag_diagnostics_show_caret)
    5706            0 :         error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    5707            0 :                   opname, TREE_TYPE (arg1));
    5708              :       else
    5709            0 :         error_at (loc, op_error_string (G_("%<operator%s%> in %<%E%s%>"),
    5710              :                                         1, match),
    5711            0 :                   opname, arg1, opname, TREE_TYPE (arg1));
    5712              :       break;
    5713              : 
    5714           13 :     case ARRAY_REF:
    5715           13 :       if (flag_diagnostics_show_caret)
    5716            0 :         error_at (loc, op_error_string (G_("%<operator[]%>"), 2, match),
    5717            0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2));
    5718              :       else
    5719           26 :         error_at (loc, op_error_string (G_("%<operator[]%> in %<%E[%E]%>"),
    5720              :                                         2, match),
    5721           13 :                   arg1, arg2, TREE_TYPE (arg1), TREE_TYPE (arg2));
    5722              :       break;
    5723              : 
    5724            6 :     case REALPART_EXPR:
    5725            6 :     case IMAGPART_EXPR:
    5726            6 :       if (flag_diagnostics_show_caret)
    5727            0 :         error_at (loc, op_error_string (G_("%qs"), 1, match),
    5728            0 :                   opname, TREE_TYPE (arg1));
    5729              :       else
    5730           12 :         error_at (loc, op_error_string (G_("%qs in %<%s %E%>"), 1, match),
    5731            6 :                   opname, opname, arg1, TREE_TYPE (arg1));
    5732              :       break;
    5733              : 
    5734            0 :     case CO_AWAIT_EXPR:
    5735            0 :       if (flag_diagnostics_show_caret)
    5736            0 :         error_at (loc, op_error_string (G_("%<operator %s%>"), 1, match),
    5737            0 :                   opname, TREE_TYPE (arg1));
    5738              :       else
    5739            0 :         error_at (loc, op_error_string (G_("%<operator %s%> in %<%s%E%>"),
    5740              :                                           1, match),
    5741            0 :                    opname, opname, arg1, TREE_TYPE (arg1));
    5742              :       break;
    5743              : 
    5744         1443 :     default:
    5745         1443 :       if (arg2)
    5746         1345 :         if (flag_diagnostics_show_caret)
    5747              :           {
    5748           21 :             binary_op_rich_location richloc (loc, arg1, arg2, true);
    5749           21 :             pp_markup::element_quoted_type element_0
    5750           21 :               (TREE_TYPE (arg1), highlight_colors::lhs);
    5751           21 :             pp_markup::element_quoted_type element_1
    5752           21 :               (TREE_TYPE (arg2), highlight_colors::rhs);
    5753           21 :             error_at (&richloc,
    5754              :                       binop_error_string (G_("%<operator%s%>"), match),
    5755              :                       opname, &element_0, &element_1);
    5756           21 :           }
    5757              :         else
    5758         2648 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%E %s %E%>"),
    5759              :                                           2, match),
    5760              :                     opname, arg1, opname, arg2,
    5761         1324 :                     TREE_TYPE (arg1), TREE_TYPE (arg2));
    5762              :       else
    5763           98 :         if (flag_diagnostics_show_caret)
    5764            0 :           error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    5765            0 :                     opname, TREE_TYPE (arg1));
    5766              :         else
    5767          196 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%s%E%>"),
    5768              :                                           1, match),
    5769           98 :                     opname, opname, arg1, TREE_TYPE (arg1));
    5770              :       break;
    5771              :     }
    5772         1462 : }
    5773              : 
    5774              : /* Return the implicit conversion sequence that could be used to
    5775              :    convert E1 to E2 in [expr.cond].  */
    5776              : 
    5777              : static conversion *
    5778       507490 : conditional_conversion (tree e1, tree e2, tsubst_flags_t complain)
    5779              : {
    5780       507490 :   tree t1 = non_reference (TREE_TYPE (e1));
    5781       507490 :   tree t2 = non_reference (TREE_TYPE (e2));
    5782       507490 :   conversion *conv;
    5783       507490 :   bool good_base;
    5784              : 
    5785              :   /* [expr.cond]
    5786              : 
    5787              :      If E2 is an lvalue: E1 can be converted to match E2 if E1 can be
    5788              :      implicitly converted (clause _conv_) to the type "lvalue reference to
    5789              :      T2", subject to the constraint that in the conversion the
    5790              :      reference must bind directly (_dcl.init.ref_) to an lvalue.
    5791              : 
    5792              :      If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
    5793              :      implicitly converted to the type "rvalue reference to T2", subject to
    5794              :      the constraint that the reference must bind directly.  */
    5795       507490 :   if (glvalue_p (e2))
    5796              :     {
    5797       479981 :       tree rtype = cp_build_reference_type (t2, !lvalue_p (e2));
    5798       479981 :       conv = implicit_conversion (rtype,
    5799              :                                   t1,
    5800              :                                   e1,
    5801              :                                   /*c_cast_p=*/false,
    5802              :                                   LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND
    5803              :                                   |LOOKUP_ONLYCONVERTING,
    5804              :                                   complain);
    5805       479981 :       if (conv && !conv->bad_p)
    5806              :         return conv;
    5807              :     }
    5808              : 
    5809              :   /* If E2 is a prvalue or if neither of the conversions above can be done
    5810              :      and at least one of the operands has (possibly cv-qualified) class
    5811              :      type: */
    5812       404974 :   if (!CLASS_TYPE_P (t1) && !CLASS_TYPE_P (t2))
    5813              :     return NULL;
    5814              : 
    5815              :   /* [expr.cond]
    5816              : 
    5817              :      If E1 and E2 have class type, and the underlying class types are
    5818              :      the same or one is a base class of the other: E1 can be converted
    5819              :      to match E2 if the class of T2 is the same type as, or a base
    5820              :      class of, the class of T1, and the cv-qualification of T2 is the
    5821              :      same cv-qualification as, or a greater cv-qualification than, the
    5822              :      cv-qualification of T1.  If the conversion is applied, E1 is
    5823              :      changed to an rvalue of type T2 that still refers to the original
    5824              :      source class object (or the appropriate subobject thereof).  */
    5825       180895 :   if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    5826       362697 :       && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
    5827              :     {
    5828        54639 :       if (good_base && at_least_as_qualified_p (t2, t1))
    5829              :         {
    5830        27238 :           conv = build_identity_conv (t1, e1);
    5831        27238 :           if (!same_type_p (TYPE_MAIN_VARIANT (t1),
    5832              :                             TYPE_MAIN_VARIANT (t2)))
    5833            6 :             conv = build_conv (ck_base, t2, conv);
    5834              :           else
    5835        27232 :             conv = build_conv (ck_rvalue, t2, conv);
    5836        27238 :           return conv;
    5837              :         }
    5838              :       else
    5839        27401 :         return NULL;
    5840              :     }
    5841              :   else
    5842              :     /* [expr.cond]
    5843              : 
    5844              :        Otherwise: E1 can be converted to match E2 if E1 can be implicitly
    5845              :        converted to the type that expression E2 would have if E2 were
    5846              :        converted to an rvalue (or the type it has, if E2 is an rvalue).  */
    5847       248912 :     return implicit_conversion (t2, t1, e1, /*c_cast_p=*/false,
    5848       248912 :                                 LOOKUP_IMPLICIT, complain);
    5849              : }
    5850              : 
    5851              : /* Implement [expr.cond].  ARG1, ARG2, and ARG3 are the three
    5852              :    arguments to the conditional expression.  */
    5853              : 
    5854              : tree
    5855      8595232 : build_conditional_expr (const op_location_t &loc,
    5856              :                         tree arg1, tree arg2, tree arg3,
    5857              :                         tsubst_flags_t complain)
    5858              : {
    5859      8595232 :   tree arg2_type;
    5860      8595232 :   tree arg3_type;
    5861      8595232 :   tree result = NULL_TREE;
    5862      8595232 :   tree result_type = NULL_TREE;
    5863      8595232 :   tree semantic_result_type = NULL_TREE;
    5864      8595232 :   bool is_glvalue = true;
    5865      8595232 :   struct z_candidate *candidates = 0;
    5866      8595232 :   struct z_candidate *cand;
    5867      8595232 :   tree orig_arg2, orig_arg3;
    5868              : 
    5869      8595232 :   auto_cond_timevar tv (TV_OVERLOAD);
    5870              : 
    5871              :   /* As a G++ extension, the second argument to the conditional can be
    5872              :      omitted.  (So that `a ? : c' is roughly equivalent to `a ? a :
    5873              :      c'.)  If the second operand is omitted, make sure it is
    5874              :      calculated only once.  */
    5875      8595232 :   if (!arg2)
    5876              :     {
    5877          380 :       if (complain & tf_error)
    5878          374 :         pedwarn (loc, OPT_Wpedantic,
    5879              :                  "ISO C++ forbids omitting the middle term of "
    5880              :                  "a %<?:%> expression");
    5881              : 
    5882          380 :       if ((complain & tf_warning) && !truth_value_p (TREE_CODE (arg1)))
    5883          332 :         warn_for_omitted_condop (loc, arg1);
    5884              : 
    5885              :       /* Make sure that lvalues remain lvalues.  See g++.oliva/ext1.C.  */
    5886          380 :       if (glvalue_p (arg1))
    5887              :         {
    5888           89 :           arg1 = cp_stabilize_reference (arg1);
    5889           89 :           arg2 = arg1 = prevent_lifetime_extension (arg1);
    5890              :         }
    5891          291 :       else if (TREE_CODE (arg1) == TARGET_EXPR)
    5892              :         /* arg1 can't be a prvalue result of the conditional
    5893              :            expression, since it needs to be materialized for the
    5894              :            conversion to bool, so treat it as an xvalue in arg2.  */
    5895            6 :         arg2 = move (TARGET_EXPR_SLOT (arg1));
    5896          285 :       else if (TREE_CODE (arg1) == EXCESS_PRECISION_EXPR)
    5897            3 :         arg2 = arg1 = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (arg1),
    5898            3 :                               cp_save_expr (TREE_OPERAND (arg1, 0)));
    5899              :       else
    5900          282 :         arg2 = arg1 = cp_save_expr (arg1);
    5901              :     }
    5902              : 
    5903              :   /* If something has already gone wrong, just pass that fact up the
    5904              :      tree.  */
    5905      8595232 :   if (error_operand_p (arg1)
    5906      8595154 :       || error_operand_p (arg2)
    5907     17190337 :       || error_operand_p (arg3))
    5908          169 :     return error_mark_node;
    5909              : 
    5910      8595063 :   conversion_obstack_sentinel cos;
    5911              : 
    5912      8595063 :   orig_arg2 = arg2;
    5913      8595063 :   orig_arg3 = arg3;
    5914              : 
    5915      8595063 :   if (gnu_vector_type_p (TREE_TYPE (arg1))
    5916      8595063 :       && (VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg1))
    5917            3 :           || VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (arg1))))
    5918              :     {
    5919         1400 :       tree arg1_type = TREE_TYPE (arg1);
    5920              : 
    5921              :       /* If arg1 is another cond_expr choosing between -1 and 0,
    5922              :          then we can use its comparison.  It may help to avoid
    5923              :          additional comparison, produce more accurate diagnostics
    5924              :          and enables folding.  */
    5925         1400 :       if (TREE_CODE (arg1) == VEC_COND_EXPR
    5926         1218 :           && integer_minus_onep (TREE_OPERAND (arg1, 1))
    5927         2618 :           && integer_zerop (TREE_OPERAND (arg1, 2)))
    5928         1218 :         arg1 = TREE_OPERAND (arg1, 0);
    5929              : 
    5930         1400 :       arg1 = force_rvalue (arg1, complain);
    5931         1400 :       arg2 = force_rvalue (arg2, complain);
    5932         1400 :       arg3 = force_rvalue (arg3, complain);
    5933              : 
    5934              :       /* force_rvalue can return error_mark on valid arguments.  */
    5935         1400 :       if (error_operand_p (arg1)
    5936         1400 :           || error_operand_p (arg2)
    5937         2800 :           || error_operand_p (arg3))
    5938            0 :         return error_mark_node;
    5939              : 
    5940         1400 :       arg2_type = TREE_TYPE (arg2);
    5941         1400 :       arg3_type = TREE_TYPE (arg3);
    5942              : 
    5943         1400 :       if (!VECTOR_TYPE_P (arg2_type)
    5944          295 :           && !VECTOR_TYPE_P (arg3_type))
    5945              :         {
    5946              :           /* Rely on the error messages of the scalar version.  */
    5947          277 :           tree scal = build_conditional_expr (loc, integer_one_node,
    5948              :                                               orig_arg2, orig_arg3, complain);
    5949          277 :           if (scal == error_mark_node)
    5950              :             return error_mark_node;
    5951          277 :           tree stype = TREE_TYPE (scal);
    5952          277 :           tree ctype = TREE_TYPE (arg1_type);
    5953          277 :           if (TYPE_SIZE (stype) != TYPE_SIZE (ctype)
    5954          277 :               || (!INTEGRAL_TYPE_P (stype) && !SCALAR_FLOAT_TYPE_P (stype)))
    5955              :             {
    5956            9 :               if (complain & tf_error)
    5957            9 :                 error_at (loc, "inferred scalar type %qT is not an integer or "
    5958              :                           "floating-point type of the same size as %qT", stype,
    5959            9 :                           COMPARISON_CLASS_P (arg1)
    5960            9 :                           ? TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg1, 0)))
    5961              :                           : ctype);
    5962            9 :               return error_mark_node;
    5963              :             }
    5964              : 
    5965          268 :           tree vtype = build_opaque_vector_type (stype,
    5966          268 :                          TYPE_VECTOR_SUBPARTS (arg1_type));
    5967              :           /* We could pass complain & tf_warning to unsafe_conversion_p,
    5968              :              but the warnings (like Wsign-conversion) have already been
    5969              :              given by the scalar build_conditional_expr_1. We still check
    5970              :              unsafe_conversion_p to forbid truncating long long -> float.  */
    5971          268 :           if (unsafe_conversion_p (stype, arg2, NULL_TREE, false))
    5972              :             {
    5973            0 :               if (complain & tf_error)
    5974            0 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5975              :                                "involves truncation", arg2_type, vtype);
    5976            0 :               return error_mark_node;
    5977              :             }
    5978          268 :           if (unsafe_conversion_p (stype, arg3, NULL_TREE, false))
    5979              :             {
    5980            3 :               if (complain & tf_error)
    5981            3 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5982              :                                "involves truncation", arg3_type, vtype);
    5983            3 :               return error_mark_node;
    5984              :             }
    5985              : 
    5986          265 :           arg2 = cp_convert (stype, arg2, complain);
    5987          265 :           arg2 = save_expr (arg2);
    5988          265 :           arg2 = build_vector_from_val (vtype, arg2);
    5989          265 :           arg2_type = vtype;
    5990          265 :           arg3 = cp_convert (stype, arg3, complain);
    5991          265 :           arg3 = save_expr (arg3);
    5992          265 :           arg3 = build_vector_from_val (vtype, arg3);
    5993          265 :           arg3_type = vtype;
    5994              :         }
    5995              : 
    5996         2758 :       if ((gnu_vector_type_p (arg2_type) && !VECTOR_TYPE_P (arg3_type))
    5997         2680 :           || (gnu_vector_type_p (arg3_type) && !VECTOR_TYPE_P (arg2_type)))
    5998              :         {
    5999           96 :           enum stv_conv convert_flag =
    6000           96 :             scalar_to_vector (loc, VEC_COND_EXPR, arg2, arg3,
    6001              :                               complain & tf_error);
    6002              : 
    6003           96 :           switch (convert_flag)
    6004              :             {
    6005            0 :               case stv_error:
    6006            0 :                 return error_mark_node;
    6007           15 :               case stv_firstarg:
    6008           15 :                 {
    6009           15 :                   arg2 = save_expr (arg2);
    6010           15 :                   arg2 = convert (TREE_TYPE (arg3_type), arg2);
    6011           15 :                   arg2 = build_vector_from_val (arg3_type, arg2);
    6012           15 :                   arg2_type = TREE_TYPE (arg2);
    6013           15 :                   break;
    6014              :                 }
    6015           72 :               case stv_secondarg:
    6016           72 :                 {
    6017           72 :                   arg3 = save_expr (arg3);
    6018           72 :                   arg3 = convert (TREE_TYPE (arg2_type), arg3);
    6019           72 :                   arg3 = build_vector_from_val (arg2_type, arg3);
    6020           72 :                   arg3_type = TREE_TYPE (arg3);
    6021           72 :                   break;
    6022              :                 }
    6023              :               default:
    6024              :                 break;
    6025              :             }
    6026              :         }
    6027              : 
    6028         1388 :       if (!gnu_vector_type_p (arg2_type)
    6029         1385 :           || !gnu_vector_type_p (arg3_type)
    6030         1379 :           || !same_type_p (arg2_type, arg3_type)
    6031         1379 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type),
    6032         1379 :                        TYPE_VECTOR_SUBPARTS (arg2_type))
    6033         2767 :           || TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type))
    6034              :         {
    6035            9 :           if (complain & tf_error)
    6036            6 :             error_at (loc,
    6037              :                       "incompatible vector types in conditional expression: "
    6038            6 :                       "%qT, %qT and %qT", TREE_TYPE (arg1),
    6039            6 :                       TREE_TYPE (orig_arg2), TREE_TYPE (orig_arg3));
    6040            9 :           return error_mark_node;
    6041              :         }
    6042              : 
    6043         1379 :       if (!COMPARISON_CLASS_P (arg1))
    6044              :         {
    6045          179 :           tree cmp_type = truth_type_for (arg1_type);
    6046          179 :           arg1 = build2 (NE_EXPR, cmp_type, arg1, build_zero_cst (arg1_type));
    6047              :         }
    6048         1379 :       return build3_loc (loc, VEC_COND_EXPR, arg2_type, arg1, arg2, arg3);
    6049              :     }
    6050              : 
    6051              :   /* [expr.cond]
    6052              : 
    6053              :      The first expression is implicitly converted to bool (clause
    6054              :      _conv_).  */
    6055      8593663 :   arg1 = perform_implicit_conversion_flags (boolean_type_node, arg1, complain,
    6056              :                                             LOOKUP_NORMAL);
    6057      8593663 :   if (error_operand_p (arg1))
    6058           25 :     return error_mark_node;
    6059              : 
    6060      8593638 :   arg2_type = unlowered_expr_type (arg2);
    6061      8593638 :   arg3_type = unlowered_expr_type (arg3);
    6062              : 
    6063      8593638 :   if ((TREE_CODE (arg2) == EXCESS_PRECISION_EXPR
    6064      8593620 :        || TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
    6065           45 :       && (TREE_CODE (arg2_type) == INTEGER_TYPE
    6066              :           || SCALAR_FLOAT_TYPE_P (arg2_type)
    6067              :           || TREE_CODE (arg2_type) == COMPLEX_TYPE)
    6068           45 :       && (TREE_CODE (arg3_type) == INTEGER_TYPE
    6069              :           || SCALAR_FLOAT_TYPE_P (arg3_type)
    6070              :           || TREE_CODE (arg3_type) == COMPLEX_TYPE))
    6071              :     {
    6072           45 :       semantic_result_type
    6073           45 :         = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6074           45 :       if (semantic_result_type == error_mark_node)
    6075              :         {
    6076            0 :           tree t1 = arg2_type;
    6077            0 :           tree t2 = arg3_type;
    6078            0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6079            0 :             t1 = TREE_TYPE (t1);
    6080            0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6081            0 :             t2 = TREE_TYPE (t2);
    6082            0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6083              :                                && SCALAR_FLOAT_TYPE_P (t2)
    6084              :                                && (extended_float_type_p (t1)
    6085              :                                    || extended_float_type_p (t2))
    6086              :                                && cp_compare_floating_point_conversion_ranks
    6087              :                                     (t1, t2) == 3);
    6088            0 :           if (complain & tf_error)
    6089            0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6090              :                            "have unordered conversion rank",
    6091              :                       arg2_type, arg3_type);
    6092            0 :           return error_mark_node;
    6093              :         }
    6094           45 :       if (TREE_CODE (arg2) == EXCESS_PRECISION_EXPR)
    6095              :         {
    6096           18 :           arg2 = TREE_OPERAND (arg2, 0);
    6097           18 :           arg2_type = TREE_TYPE (arg2);
    6098              :         }
    6099           45 :       if (TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
    6100              :         {
    6101           27 :           arg3 = TREE_OPERAND (arg3, 0);
    6102           27 :           arg3_type = TREE_TYPE (arg3);
    6103              :         }
    6104              :     }
    6105              : 
    6106              :   /* [expr.cond]
    6107              : 
    6108              :      If either the second or the third operand has type (possibly
    6109              :      cv-qualified) void, then the lvalue-to-rvalue (_conv.lval_),
    6110              :      array-to-pointer (_conv.array_), and function-to-pointer
    6111              :      (_conv.func_) standard conversions are performed on the second
    6112              :      and third operands.  */
    6113      8593638 :   if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type))
    6114              :     {
    6115              :       /* 'void' won't help in resolving an overloaded expression on the
    6116              :          other side, so require it to resolve by itself.  */
    6117       114815 :       if (arg2_type == unknown_type_node)
    6118              :         {
    6119            9 :           arg2 = resolve_nondeduced_context_or_error (arg2, complain);
    6120            9 :           arg2_type = TREE_TYPE (arg2);
    6121              :         }
    6122       114815 :       if (arg3_type == unknown_type_node)
    6123              :         {
    6124            0 :           arg3 = resolve_nondeduced_context_or_error (arg3, complain);
    6125            0 :           arg3_type = TREE_TYPE (arg3);
    6126              :         }
    6127              : 
    6128              :       /* [expr.cond]
    6129              : 
    6130              :          One of the following shall hold:
    6131              : 
    6132              :          --The second or the third operand (but not both) is a
    6133              :            throw-expression (_except.throw_); the result is of the type
    6134              :            and value category of the other.
    6135              : 
    6136              :          --Both the second and the third operands have type void; the
    6137              :            result is of type void and is a prvalue.  */
    6138       114815 :       if (TREE_CODE (arg2) == THROW_EXPR
    6139           80 :           && TREE_CODE (arg3) != THROW_EXPR)
    6140              :         {
    6141           68 :           result_type = arg3_type;
    6142           68 :           is_glvalue = glvalue_p (arg3);
    6143              :         }
    6144       114747 :       else if (TREE_CODE (arg2) != THROW_EXPR
    6145       114735 :                && TREE_CODE (arg3) == THROW_EXPR)
    6146              :         {
    6147          171 :           result_type = arg2_type;
    6148          171 :           is_glvalue = glvalue_p (arg2);
    6149              :         }
    6150       114576 :       else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
    6151              :         {
    6152       114547 :           result_type = void_type_node;
    6153       114547 :           is_glvalue = false;
    6154              :         }
    6155              :       else
    6156              :         {
    6157           29 :           if (complain & tf_error)
    6158              :             {
    6159           18 :               if (VOID_TYPE_P (arg2_type))
    6160            9 :                 error_at (cp_expr_loc_or_loc (arg3, loc),
    6161              :                           "second operand to the conditional operator "
    6162              :                           "is of type %<void%>, but the third operand is "
    6163              :                           "neither a throw-expression nor of type %<void%>");
    6164              :               else
    6165            9 :                 error_at (cp_expr_loc_or_loc (arg2, loc),
    6166              :                           "third operand to the conditional operator "
    6167              :                           "is of type %<void%>, but the second operand is "
    6168              :                           "neither a throw-expression nor of type %<void%>");
    6169              :             }
    6170           29 :           return error_mark_node;
    6171              :         }
    6172              : 
    6173       114786 :       goto valid_operands;
    6174              :     }
    6175              :   /* [expr.cond]
    6176              : 
    6177              :      Otherwise, if the second and third operand have different types,
    6178              :      and either has (possibly cv-qualified) class type, or if both are
    6179              :      glvalues of the same value category and the same type except for
    6180              :      cv-qualification, an attempt is made to convert each of those operands
    6181              :      to the type of the other.  */
    6182      8478823 :   else if (!same_type_p (arg2_type, arg3_type)
    6183      8478823 :             && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)
    6184      1593053 :                 || (same_type_ignoring_top_level_qualifiers_p (arg2_type,
    6185              :                                                                arg3_type)
    6186       419059 :                     && glvalue_p (arg2) && glvalue_p (arg3)
    6187       101493 :                     && lvalue_p (arg2) == lvalue_p (arg3))))
    6188              :     {
    6189       253745 :       conversion *conv2;
    6190       253745 :       conversion *conv3;
    6191       253745 :       bool converted = false;
    6192              : 
    6193       253745 :       conv2 = conditional_conversion (arg2, arg3, complain);
    6194       253745 :       conv3 = conditional_conversion (arg3, arg2, complain);
    6195              : 
    6196              :       /* [expr.cond]
    6197              : 
    6198              :          If both can be converted, or one can be converted but the
    6199              :          conversion is ambiguous, the program is ill-formed.  If
    6200              :          neither can be converted, the operands are left unchanged and
    6201              :          further checking is performed as described below.  If exactly
    6202              :          one conversion is possible, that conversion is applied to the
    6203              :          chosen operand and the converted operand is used in place of
    6204              :          the original operand for the remainder of this section.  */
    6205       253745 :       if ((conv2 && !conv2->bad_p
    6206        60592 :            && conv3 && !conv3->bad_p)
    6207        60575 :           || (conv2 && conv2->kind == ck_ambig)
    6208       253632 :           || (conv3 && conv3->kind == ck_ambig))
    6209              :         {
    6210          113 :           if (complain & tf_error)
    6211              :             {
    6212            6 :               error_at (loc, "operands to %<?:%> have different types "
    6213              :                         "%qT and %qT",
    6214              :                         arg2_type, arg3_type);
    6215            6 :               if (conv2 && !conv2->bad_p && conv3 && !conv3->bad_p)
    6216            3 :                 inform (loc, "  and each type can be converted to the other");
    6217            3 :               else if (conv2 && conv2->kind == ck_ambig)
    6218            3 :                 convert_like (conv2, arg2, complain);
    6219              :               else
    6220            0 :                 convert_like (conv3, arg3, complain);
    6221              :             }
    6222          113 :           result = error_mark_node;
    6223              :         }
    6224       253632 :       else if (conv2 && !conv2->bad_p)
    6225              :         {
    6226        60479 :           arg2 = convert_like (conv2, arg2, complain);
    6227        60479 :           arg2 = convert_from_reference (arg2);
    6228        60479 :           arg2_type = TREE_TYPE (arg2);
    6229              :           /* Even if CONV2 is a valid conversion, the result of the
    6230              :              conversion may be invalid.  For example, if ARG3 has type
    6231              :              "volatile X", and X does not have a copy constructor
    6232              :              accepting a "volatile X&", then even if ARG2 can be
    6233              :              converted to X, the conversion will fail.  */
    6234        60479 :           if (error_operand_p (arg2))
    6235            4 :             result = error_mark_node;
    6236            4 :           converted = true;
    6237              :         }
    6238       193153 :       else if (conv3 && !conv3->bad_p)
    6239              :         {
    6240       192468 :           arg3 = convert_like (conv3, arg3, complain);
    6241       192468 :           arg3 = convert_from_reference (arg3);
    6242       192468 :           arg3_type = TREE_TYPE (arg3);
    6243       192468 :           if (error_operand_p (arg3))
    6244            0 :             result = error_mark_node;
    6245            0 :           converted = true;
    6246              :         }
    6247              : 
    6248          117 :       if (result)
    6249              :         return result;
    6250              : 
    6251              :       /* If, after the conversion, both operands have class type,
    6252              :          treat the cv-qualification of both operands as if it were the
    6253              :          union of the cv-qualification of the operands.
    6254              : 
    6255              :          The standard is not clear about what to do in this
    6256              :          circumstance.  For example, if the first operand has type
    6257              :          "const X" and the second operand has a user-defined
    6258              :          conversion to "volatile X", what is the type of the second
    6259              :          operand after this step?  Making it be "const X" (matching
    6260              :          the first operand) seems wrong, as that discards the
    6261              :          qualification without actually performing a copy.  Leaving it
    6262              :          as "volatile X" seems wrong as that will result in the
    6263              :          conditional expression failing altogether, even though,
    6264              :          according to this step, the one operand could be converted to
    6265              :          the type of the other.  */
    6266       253628 :       if (converted
    6267       252943 :           && CLASS_TYPE_P (arg2_type)
    6268       282902 :           && cp_type_quals (arg2_type) != cp_type_quals (arg3_type))
    6269            0 :         arg2_type = arg3_type =
    6270            0 :           cp_build_qualified_type (arg2_type,
    6271            0 :                                    cp_type_quals (arg2_type)
    6272            0 :                                    | cp_type_quals (arg3_type));
    6273              :     }
    6274              : 
    6275              :   /* [expr.cond]
    6276              : 
    6277              :      If the second and third operands are glvalues of the same value
    6278              :      category and have the same type, the result is of that type and
    6279              :      value category.  */
    6280     12757405 :   if (((lvalue_p (arg2) && lvalue_p (arg3))
    6281      4790858 :        || (xvalue_p (arg2) && xvalue_p (arg3)))
    6282     12213166 :       && same_type_p (arg2_type, arg3_type))
    6283              :     {
    6284      3628504 :       result_type = arg2_type;
    6285      3628504 :       goto valid_operands;
    6286              :     }
    6287              : 
    6288              :   /* [expr.cond]
    6289              : 
    6290              :      Otherwise, the result is an rvalue.  If the second and third
    6291              :      operand do not have the same type, and either has (possibly
    6292              :      cv-qualified) class type, overload resolution is used to
    6293              :      determine the conversions (if any) to be applied to the operands
    6294              :      (_over.match.oper_, _over.built_).  */
    6295      4850202 :   is_glvalue = false;
    6296      4850202 :   if (!same_type_p (arg2_type, arg3_type)
    6297      4850202 :       && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
    6298              :     {
    6299          685 :       releasing_vec args;
    6300          685 :       conversion *conv;
    6301          685 :       bool any_viable_p;
    6302              : 
    6303              :       /* Rearrange the arguments so that add_builtin_candidate only has
    6304              :          to know about two args.  In build_builtin_candidate, the
    6305              :          arguments are unscrambled.  */
    6306          685 :       args->quick_push (arg2);
    6307          685 :       args->quick_push (arg3);
    6308          685 :       args->quick_push (arg1);
    6309          685 :       add_builtin_candidates (&candidates,
    6310              :                               COND_EXPR,
    6311              :                               NOP_EXPR,
    6312              :                               ovl_op_identifier (false, COND_EXPR),
    6313              :                               args,
    6314              :                               LOOKUP_NORMAL, complain);
    6315              : 
    6316              :       /* [expr.cond]
    6317              : 
    6318              :          If the overload resolution fails, the program is
    6319              :          ill-formed.  */
    6320          685 :       candidates = splice_viable (candidates, false, &any_viable_p);
    6321          685 :       if (!any_viable_p)
    6322              :         {
    6323          569 :           if (complain & tf_error)
    6324           22 :             error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6325              :                       arg2_type, arg3_type);
    6326          569 :           return error_mark_node;
    6327              :         }
    6328          116 :       cand = tourney (candidates, complain);
    6329          116 :       if (!cand)
    6330              :         {
    6331            0 :           if (complain & tf_error)
    6332              :             {
    6333            0 :               auto_diagnostic_group d;
    6334            0 :               op_error (loc, COND_EXPR, NOP_EXPR, arg1, arg2, arg3, false);
    6335            0 :               print_z_candidates (loc, candidates);
    6336            0 :             }
    6337            0 :           return error_mark_node;
    6338              :         }
    6339              : 
    6340              :       /* [expr.cond]
    6341              : 
    6342              :          Otherwise, the conversions thus determined are applied, and
    6343              :          the converted operands are used in place of the original
    6344              :          operands for the remainder of this section.  */
    6345          116 :       conv = cand->convs[0];
    6346          116 :       arg1 = convert_like (conv, arg1, complain);
    6347          116 :       conv = cand->convs[1];
    6348          116 :       arg2 = convert_like (conv, arg2, complain);
    6349          116 :       arg2_type = TREE_TYPE (arg2);
    6350          116 :       conv = cand->convs[2];
    6351          116 :       arg3 = convert_like (conv, arg3, complain);
    6352          116 :       arg3_type = TREE_TYPE (arg3);
    6353          685 :     }
    6354              : 
    6355              :   /* [expr.cond]
    6356              : 
    6357              :      Lvalue-to-rvalue (_conv.lval_), array-to-pointer (_conv.array_),
    6358              :      and function-to-pointer (_conv.func_) standard conversions are
    6359              :      performed on the second and third operands.
    6360              : 
    6361              :      We need to force the lvalue-to-rvalue conversion here for class types,
    6362              :      so we get TARGET_EXPRs; trying to deal with a COND_EXPR of class rvalues
    6363              :      that isn't wrapped with a TARGET_EXPR plays havoc with exception
    6364              :      regions.  */
    6365              : 
    6366      4849633 :   arg2 = force_rvalue (arg2, complain);
    6367      4849633 :   if (!CLASS_TYPE_P (arg2_type))
    6368      4728307 :     arg2_type = TREE_TYPE (arg2);
    6369              : 
    6370      4849633 :   arg3 = force_rvalue (arg3, complain);
    6371      4849633 :   if (!CLASS_TYPE_P (arg3_type))
    6372      4728307 :     arg3_type = TREE_TYPE (arg3);
    6373              : 
    6374      4849633 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6375              :     return error_mark_node;
    6376              : 
    6377              :   /* [expr.cond]
    6378              : 
    6379              :      After those conversions, one of the following shall hold:
    6380              : 
    6381              :      --The second and third operands have the same type; the result  is  of
    6382              :        that type.  */
    6383      4849585 :   if (same_type_p (arg2_type, arg3_type))
    6384              :     result_type = arg2_type;
    6385              :   /* [expr.cond]
    6386              : 
    6387              :      --The second and third operands have arithmetic or enumeration
    6388              :        type; the usual arithmetic conversions are performed to bring
    6389              :        them to a common type, and the result is of that type.  */
    6390        22515 :   else if ((ARITHMETIC_TYPE_P (arg2_type)
    6391        21805 :             || UNSCOPED_ENUM_P (arg2_type))
    6392      1071421 :            && (ARITHMETIC_TYPE_P (arg3_type)
    6393          183 :                || UNSCOPED_ENUM_P (arg3_type)))
    6394              :     {
    6395              :       /* A conditional expression between a floating-point
    6396              :          type and an integer type should convert the integer type to
    6397              :          the evaluation format of the floating-point type, with
    6398              :          possible excess precision.  */
    6399      1048792 :       tree eptype2 = arg2_type;
    6400      1048792 :       tree eptype3 = arg3_type;
    6401      1048792 :       tree eptype;
    6402          710 :       if (ANY_INTEGRAL_TYPE_P (arg2_type)
    6403      1048795 :           && (eptype = excess_precision_type (arg3_type)) != NULL_TREE)
    6404              :         {
    6405            5 :           eptype3 = eptype;
    6406            5 :           if (!semantic_result_type)
    6407            5 :             semantic_result_type
    6408            5 :               = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6409              :         }
    6410          414 :       else if (ANY_INTEGRAL_TYPE_P (arg3_type)
    6411      1048787 :                && (eptype = excess_precision_type (arg2_type)) != NULL_TREE)
    6412              :         {
    6413           23 :           eptype2 = eptype;
    6414           23 :           if (!semantic_result_type)
    6415           23 :             semantic_result_type
    6416           23 :               = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6417              :         }
    6418      1048792 :       result_type = type_after_usual_arithmetic_conversions (eptype2,
    6419              :                                                              eptype3);
    6420      1048792 :       if (result_type == error_mark_node)
    6421              :         {
    6422            0 :           tree t1 = eptype2;
    6423            0 :           tree t2 = eptype3;
    6424            0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6425            0 :             t1 = TREE_TYPE (t1);
    6426            0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6427            0 :             t2 = TREE_TYPE (t2);
    6428            0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6429              :                                && SCALAR_FLOAT_TYPE_P (t2)
    6430              :                                && (extended_float_type_p (t1)
    6431              :                                    || extended_float_type_p (t2))
    6432              :                                && cp_compare_floating_point_conversion_ranks
    6433              :                                     (t1, t2) == 3);
    6434            0 :           if (complain & tf_error)
    6435            0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6436              :                            "have unordered conversion rank",
    6437              :                       eptype2, eptype3);
    6438            0 :           return error_mark_node;
    6439              :         }
    6440      1048792 :       if (semantic_result_type == error_mark_node)
    6441              :         {
    6442            0 :           tree t1 = arg2_type;
    6443            0 :           tree t2 = arg3_type;
    6444            0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6445            0 :             t1 = TREE_TYPE (t1);
    6446            0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6447            0 :             t2 = TREE_TYPE (t2);
    6448            0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6449              :                                && SCALAR_FLOAT_TYPE_P (t2)
    6450              :                                && (extended_float_type_p (t1)
    6451              :                                    || extended_float_type_p (t2))
    6452              :                                && cp_compare_floating_point_conversion_ranks
    6453              :                                     (t1, t2) == 3);
    6454            0 :           if (complain & tf_error)
    6455            0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6456              :                            "have unordered conversion rank",
    6457              :                       arg2_type, arg3_type);
    6458            0 :           return error_mark_node;
    6459              :         }
    6460              : 
    6461      1048792 :       if (complain & tf_warning)
    6462       982138 :         do_warn_double_promotion (result_type, arg2_type, arg3_type,
    6463              :                                   "implicit conversion from %qH to %qI to "
    6464              :                                   "match other result of conditional",
    6465              :                                   loc);
    6466              : 
    6467      1048792 :       if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6468           98 :           && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
    6469              :         {
    6470           34 :           tree stripped_orig_arg2 = tree_strip_any_location_wrapper (orig_arg2);
    6471           34 :           tree stripped_orig_arg3 = tree_strip_any_location_wrapper (orig_arg3);
    6472           34 :           if (TREE_CODE (stripped_orig_arg2) == CONST_DECL
    6473           23 :               && TREE_CODE (stripped_orig_arg3) == CONST_DECL
    6474           57 :               && (DECL_CONTEXT (stripped_orig_arg2)
    6475           23 :                   == DECL_CONTEXT (stripped_orig_arg3)))
    6476              :             /* Two enumerators from the same enumeration can have different
    6477              :                types when the enumeration is still being defined.  */;
    6478           28 :           else if (complain & (cxx_dialect >= cxx26
    6479           28 :                                ? tf_warning_or_error : tf_warning))
    6480           43 :             emit_diagnostic ((cxx_dialect >= cxx26
    6481              :                               ? diagnostics::kind::pedwarn
    6482              :                               : diagnostics::kind::warning),
    6483           25 :                              loc, OPT_Wenum_compare, "enumerated mismatch "
    6484              :                              "in conditional expression: %qT vs %qT",
    6485              :                              arg2_type, arg3_type);
    6486            3 :           else if (cxx_dialect >= cxx26)
    6487            1 :             return error_mark_node;
    6488              :         }
    6489      1048758 :       else if ((((complain & (cxx_dialect >= cxx26
    6490      1048758 :                               ? tf_warning_or_error : tf_warning))
    6491       984955 :                  && warn_deprecated_enum_float_conv)
    6492        78766 :                 || (cxx_dialect >= cxx26
    6493         1393 :                     && (complain & tf_warning_or_error) == 0))
    6494       971286 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6495           36 :                     && SCALAR_FLOAT_TYPE_P (arg3_type))
    6496       971275 :                    || (SCALAR_FLOAT_TYPE_P (arg2_type)
    6497          232 :                        && TREE_CODE (arg3_type) == ENUMERAL_TYPE)))
    6498              :         {
    6499           19 :           if (cxx_dialect >= cxx26 && (complain & tf_warning_or_error) == 0)
    6500            2 :             return error_mark_node;
    6501           17 :           if (cxx_dialect >= cxx26 && TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6502            4 :             pedwarn (loc, OPT_Wdeprecated_enum_float_conversion,
    6503              :                      "conditional expression between enumeration type "
    6504              :                      "%qT and floating-point type %qT", arg2_type, arg3_type);
    6505           13 :           else if (cxx_dialect >= cxx26)
    6506            3 :             pedwarn (loc, OPT_Wdeprecated_enum_float_conversion,
    6507              :                      "conditional expression between floating-point type "
    6508              :                      "%qT and enumeration type %qT", arg2_type, arg3_type);
    6509           10 :           else if (TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6510            6 :             warning_at (loc, OPT_Wdeprecated_enum_float_conversion,
    6511              :                         "conditional expression between enumeration type "
    6512              :                         "%qT and floating-point type %qT is deprecated",
    6513              :                         arg2_type, arg3_type);
    6514              :           else
    6515            4 :             warning_at (loc, OPT_Wdeprecated_enum_float_conversion,
    6516              :                         "conditional expression between floating-point "
    6517              :                         "type %qT and enumeration type %qT is deprecated",
    6518              :                         arg2_type, arg3_type);
    6519              :         }
    6520      1039375 :       else if ((extra_warnings || warn_enum_conversion)
    6521      1048744 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6522           15 :                     && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
    6523         9357 :                    || (TREE_CODE (arg3_type) == ENUMERAL_TYPE
    6524            8 :                        && !same_type_p (arg2_type,
    6525              :                                         type_promotes_to (arg3_type)))))
    6526              :         {
    6527           17 :           if (complain & tf_warning)
    6528              :             {
    6529           12 :               enum opt_code opt = (warn_enum_conversion
    6530           17 :                                    ? OPT_Wenum_conversion
    6531              :                                    : OPT_Wextra);
    6532           17 :               warning_at (loc, opt, "enumerated and "
    6533              :                           "non-enumerated type in conditional expression");
    6534              :             }
    6535              :         }
    6536              : 
    6537      1048789 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6538      1048789 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6539              :     }
    6540              :   /* [expr.cond]
    6541              : 
    6542              :      --The second and third operands have pointer type, or one has
    6543              :        pointer type and the other is a null pointer constant; pointer
    6544              :        conversions (_conv.ptr_) and qualification conversions
    6545              :        (_conv.qual_) are performed to bring them to their composite
    6546              :        pointer type (_expr.rel_).  The result is of the composite
    6547              :        pointer type.
    6548              : 
    6549              :      --The second and third operands have pointer to member type, or
    6550              :        one has pointer to member type and the other is a null pointer
    6551              :        constant; pointer to member conversions (_conv.mem_) and
    6552              :        qualification conversions (_conv.qual_) are performed to bring
    6553              :        them to a common type, whose cv-qualification shall match the
    6554              :        cv-qualification of either the second or the third operand.
    6555              :        The result is of the common type.  */
    6556        21821 :   else if ((null_ptr_cst_p (arg2)
    6557          163 :             && TYPE_PTR_OR_PTRMEM_P (arg3_type))
    6558        21658 :            || (null_ptr_cst_p (arg3)
    6559        20713 :                && TYPE_PTR_OR_PTRMEM_P (arg2_type))
    6560          945 :            || (TYPE_PTR_P (arg2_type) && TYPE_PTR_P (arg3_type))
    6561           89 :            || (TYPE_PTRDATAMEM_P (arg2_type) && TYPE_PTRDATAMEM_P (arg3_type))
    6562        21893 :            || (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
    6563              :     {
    6564        21767 :       result_type = composite_pointer_type (loc,
    6565              :                                             arg2_type, arg3_type, arg2,
    6566              :                                             arg3, CPO_CONDITIONAL_EXPR,
    6567              :                                             complain);
    6568        21767 :       if (result_type == error_mark_node)
    6569              :         return error_mark_node;
    6570        21741 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6571        21741 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6572              :     }
    6573              : 
    6574      4849502 :   if (!result_type)
    6575              :     {
    6576           54 :       if (complain & tf_error)
    6577            3 :         error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6578              :                   arg2_type, arg3_type);
    6579           54 :       return error_mark_node;
    6580              :     }
    6581              : 
    6582      4849502 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6583              :     return error_mark_node;
    6584              : 
    6585      4849499 :  valid_operands:
    6586      8592789 :   if (processing_template_decl && is_glvalue)
    6587              :     {
    6588              :       /* Let lvalue_kind know this was a glvalue.  */
    6589       107677 :       tree arg = (result_type == arg2_type ? arg2 : arg3);
    6590       107677 :       result_type = cp_build_reference_type (result_type, xvalue_p (arg));
    6591              :     }
    6592              : 
    6593      8592789 :   result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3);
    6594              : 
    6595              :   /* If the ARG2 and ARG3 are the same and don't have side-effects,
    6596              :      warn here, because the COND_EXPR will be turned into ARG2.  */
    6597      8592789 :   if (warn_duplicated_branches
    6598          153 :       && (complain & tf_warning)
    6599      8592942 :       && (arg2 == arg3 || operand_equal_p (arg2, arg3,
    6600              :                                            OEP_ADDRESS_OF_SAME_FIELD)))
    6601           57 :     warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches,
    6602              :                 "this condition has identical branches");
    6603              : 
    6604              :   /* We can't use result_type below, as fold might have returned a
    6605              :      throw_expr.  */
    6606              : 
    6607      8592789 :   if (!is_glvalue)
    6608              :     {
    6609              :       /* Expand both sides into the same slot, hopefully the target of
    6610              :          the ?: expression.  We used to check for TARGET_EXPRs here,
    6611              :          but now we sometimes wrap them in NOP_EXPRs so the test would
    6612              :          fail.  */
    6613      4964225 :       if (CLASS_TYPE_P (TREE_TYPE (result)))
    6614              :         {
    6615       121363 :           result = get_target_expr (result, complain);
    6616              :           /* Tell gimplify_modify_expr_rhs not to strip this in
    6617              :              assignment context: we want both arms to initialize
    6618              :              the same temporary.  */
    6619       121363 :           TARGET_EXPR_NO_ELIDE (result) = true;
    6620              :         }
    6621              :       /* If this expression is an rvalue, but might be mistaken for an
    6622              :          lvalue, we must add a NON_LVALUE_EXPR.  */
    6623      4964225 :       result = rvalue (result);
    6624      4964225 :       if (semantic_result_type)
    6625           73 :         result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6626              :                          result);
    6627              :     }
    6628              :   else
    6629              :     {
    6630      3628564 :       result = force_paren_expr (result);
    6631      3628564 :       gcc_assert (semantic_result_type == NULL_TREE);
    6632              :     }
    6633              : 
    6634              :   return result;
    6635      8595232 : }
    6636              : 
    6637              : /* OPERAND is an operand to an expression.  Perform necessary steps
    6638              :    required before using it.  If OPERAND is NULL_TREE, NULL_TREE is
    6639              :    returned.  */
    6640              : 
    6641              : static tree
    6642    725464463 : prep_operand (tree operand)
    6643              : {
    6644    725464463 :   if (operand)
    6645              :     {
    6646    825763960 :       if (CLASS_TYPE_P (TREE_TYPE (operand))
    6647    450396536 :           && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
    6648              :         /* Make sure the template type is instantiated now.  */
    6649     18700873 :         instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (operand)));
    6650              :     }
    6651              : 
    6652    725464463 :   return operand;
    6653              : }
    6654              : 
    6655              : /* True iff CONV represents a conversion sequence which no other can be better
    6656              :    than under [over.ics.rank]: in other words, a "conversion" to the exact same
    6657              :    type (including binding to a reference to the same type).  This is stronger
    6658              :    than the standard's "identity" category, which also includes reference
    6659              :    bindings that add cv-qualifiers or change rvalueness.  */
    6660              : 
    6661              : static bool
    6662    298026267 : perfect_conversion_p (conversion *conv)
    6663              : {
    6664    298026267 :   if (CONVERSION_RANK (conv) != cr_identity)
    6665              :     return false;
    6666    211814628 :   if (conv->kind == ck_ref_bind)
    6667              :     {
    6668     52953339 :       if (!conv->rvaluedness_matches_p)
    6669              :         return false;
    6670     36045414 :       if (!same_type_p (TREE_TYPE (conv->type),
    6671              :                         next_conversion (conv)->type))
    6672              :         return false;
    6673              :     }
    6674    188539305 :   if (conv->check_narrowing)
    6675              :     /* Brace elision is imperfect.  */
    6676              :     return false;
    6677              :   return true;
    6678              : }
    6679              : 
    6680              : /* True if CAND represents a perfect match, i.e. all perfect conversions, so no
    6681              :    other candidate can be a better match.  Since the template/non-template
    6682              :    tiebreaker comes immediately after the conversion comparison in
    6683              :    [over.match.best], a perfect non-template candidate is better than all
    6684              :    templates.  */
    6685              : 
    6686              : static bool
    6687    707307434 : perfect_candidate_p (z_candidate *cand)
    6688              : {
    6689    707307434 :   if (cand->viable < 1)
    6690              :     return false;
    6691              :   /* CWG1402 makes an implicitly deleted move op worse than other
    6692              :      candidates.  */
    6693    255350265 :   if (DECL_DELETED_FN (cand->fn) && DECL_DEFAULTED_FN (cand->fn)
    6694    253735982 :       && move_fn_p (cand->fn))
    6695              :     return false;
    6696    251920882 :   int len = cand->num_convs;
    6697    440460140 :   for (int i = 0; i < len; ++i)
    6698    298026267 :     if (!perfect_conversion_p (cand->convs[i]))
    6699              :       return false;
    6700    142433873 :   if (conversion *conv = cand->second_conv)
    6701            0 :     if (!perfect_conversion_p (conv))
    6702              :       return false;
    6703              :   return true;
    6704              : }
    6705              : 
    6706              : /* True iff one of CAND's argument conversions is missing.  */
    6707              : 
    6708              : static bool
    6709     25531234 : missing_conversion_p (const z_candidate *cand)
    6710              : {
    6711     47474392 :   for (unsigned i = 0; i < cand->num_convs; ++i)
    6712              :     {
    6713     30526915 :       conversion *conv = cand->convs[i];
    6714     30526915 :       if (!conv)
    6715              :         return true;
    6716     29608233 :       if (conv->kind == ck_deferred_bad)
    6717              :         {
    6718              :           /* We don't know whether this conversion is outright invalid or
    6719              :              just bad, so conservatively assume it's missing.  */
    6720      7665075 :           gcc_checking_assert (conv->bad_p);
    6721              :           return true;
    6722              :         }
    6723              :     }
    6724              :   return false;
    6725              : }
    6726              : 
    6727              : /* Add each of the viable functions in FNS (a FUNCTION_DECL or
    6728              :    OVERLOAD) to the CANDIDATES, returning an updated list of
    6729              :    CANDIDATES.  The ARGS are the arguments provided to the call;
    6730              :    if FIRST_ARG is non-null it is the implicit object argument,
    6731              :    otherwise the first element of ARGS is used if needed.  The
    6732              :    EXPLICIT_TARGS are explicit template arguments provided.
    6733              :    TEMPLATE_ONLY is true if only template functions should be
    6734              :    considered.  CONVERSION_PATH, ACCESS_PATH, and FLAGS are as for
    6735              :    add_function_candidate.  */
    6736              : 
    6737              : static void
    6738    405019873 : add_candidates (tree fns, tree first_arg, const vec<tree, va_gc> *args,
    6739              :                 tree return_type,
    6740              :                 tree explicit_targs, bool template_only,
    6741              :                 tree conversion_path, tree access_path,
    6742              :                 int flags,
    6743              :                 struct z_candidate **candidates,
    6744              :                 tsubst_flags_t complain)
    6745              : {
    6746    405019873 :   tree ctype;
    6747    405019873 :   const vec<tree, va_gc> *non_static_args;
    6748    405019873 :   bool check_list_ctor = false;
    6749    405019873 :   bool check_converting = false;
    6750    405019873 :   unification_kind_t strict;
    6751    405019873 :   tree ne_context = NULL_TREE;
    6752    405019873 :   tree ne_fns = NULL_TREE;
    6753              : 
    6754    405019873 :   if (!fns)
    6755      4207745 :     return;
    6756              : 
    6757              :   /* Precalculate special handling of constructors and conversion ops.  */
    6758    400812128 :   tree fn = OVL_FIRST (fns);
    6759    400812128 :   if (DECL_CONV_FN_P (fn))
    6760              :     {
    6761     19059425 :       check_list_ctor = false;
    6762     19059425 :       check_converting = (flags & LOOKUP_ONLYCONVERTING) != 0;
    6763     19059425 :       if (flags & LOOKUP_NO_CONVERSION)
    6764              :         /* We're doing return_type(x).  */
    6765              :         strict = DEDUCE_CONV;
    6766              :       else
    6767              :         /* We're doing x.operator return_type().  */
    6768         1383 :         strict = DEDUCE_EXACT;
    6769              :       /* [over.match.funcs] For conversion functions, the function
    6770              :          is considered to be a member of the class of the implicit
    6771              :          object argument for the purpose of defining the type of
    6772              :          the implicit object parameter.  */
    6773     19059425 :       ctype = TYPE_MAIN_VARIANT (TREE_TYPE (first_arg));
    6774              :     }
    6775              :   else
    6776              :     {
    6777    763505406 :       if (DECL_CONSTRUCTOR_P (fn))
    6778              :         {
    6779    107596903 :           check_list_ctor = (flags & LOOKUP_LIST_ONLY) != 0;
    6780              :           /* For list-initialization we consider explicit constructors
    6781              :              and complain if one is chosen.  */
    6782    107596903 :           check_converting
    6783    107596903 :             = ((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    6784              :                == LOOKUP_ONLYCONVERTING);
    6785              :         }
    6786    381752703 :       strict = DEDUCE_CALL;
    6787    596933260 :       ctype = conversion_path ? BINFO_TYPE (conversion_path) : NULL_TREE;
    6788              :     }
    6789              : 
    6790              :   /* P2468: Check if operator== is a rewrite target with first operand
    6791              :      (*args)[0]; for now just do the lookups.  */
    6792    400812128 :   if ((flags & (LOOKUP_REWRITTEN | LOOKUP_REVERSED))
    6793    400812128 :       && DECL_OVERLOADED_OPERATOR_IS (fn, EQ_EXPR))
    6794              :     {
    6795     10414557 :       tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6796     10414557 :       if (DECL_CLASS_SCOPE_P (fn))
    6797              :         {
    6798       208845 :           ne_context = DECL_CONTEXT (fn);
    6799       208845 :           ne_fns = lookup_fnfields (TREE_TYPE ((*args)[0]), ne_name,
    6800              :                                     1, tf_none);
    6801       208845 :           if (ne_fns == error_mark_node || ne_fns == NULL_TREE)
    6802              :             ne_fns = NULL_TREE;
    6803              :           else
    6804        17339 :             ne_fns = BASELINK_FUNCTIONS (ne_fns);
    6805              :         }
    6806              :       else
    6807              :         {
    6808     10205712 :           ne_context = decl_namespace_context (fn);
    6809     10205712 :           ne_fns = lookup_qualified_name (ne_context, ne_name,
    6810              :                                           LOOK_want::NORMAL,
    6811              :                                           /*complain*/false);
    6812     10205712 :           if (ne_fns == error_mark_node
    6813      2730453 :               || !is_overloaded_fn (ne_fns))
    6814      7475259 :             ne_fns = NULL_TREE;
    6815              :         }
    6816              :     }
    6817              : 
    6818    400812128 :   if (first_arg)
    6819              :     non_static_args = args;
    6820              :   else
    6821              :     /* Delay creating the implicit this parameter until it is needed.  */
    6822    179332178 :     non_static_args = NULL;
    6823              : 
    6824    400812128 :   bool seen_strictly_viable = any_strictly_viable (*candidates);
    6825              :   /* If there's a non-template perfect match, we don't need to consider
    6826              :      templates.  So check non-templates first.  This optimization is only
    6827              :      really needed for the defaulted copy constructor of tuple and the like
    6828              :      (96926), but it seems like we might as well enable it more generally.  */
    6829    400812128 :   bool seen_perfect = false;
    6830    400812128 :   enum { templates, non_templates, either } which = either;
    6831    400812128 :   if (template_only)
    6832              :     which = templates;
    6833              :   else /*if (flags & LOOKUP_DEFAULTED)*/
    6834    347470959 :     which = non_templates;
    6835              : 
    6836              :   /* Template candidates that we'll potentially ignore if the
    6837              :      perfect candidate optimization succeeds.  */
    6838    400812128 :   z_candidate *ignored_template_cands = nullptr;
    6839              : 
    6840              :   /* During overload resolution, we first consider each function under the
    6841              :      assumption that we'll eventually find a strictly viable candidate.
    6842              :      This allows us to circumvent our defacto behavior when checking
    6843              :      argument conversions and shortcut consideration of the candidate
    6844              :      upon encountering the first bad conversion.  If this assumption
    6845              :      turns out to be false, and all candidates end up being non-strictly
    6846              :      viable, then we reconsider such candidates under the defacto behavior.
    6847              :      This trick is important for pruning member function overloads according
    6848              :      to their const/ref-qualifiers (since all 'this' conversions are at
    6849              :      worst bad) without breaking -fpermissive.  */
    6850    400812128 :   z_candidate *bad_cands = nullptr;
    6851    400812128 :   bool shortcut_bad_convs = true;
    6852              : 
    6853    605962116 :  again:
    6854   3817345990 :   for (tree fn : lkp_range (fns))
    6855              :     {
    6856   3211397425 :       if (which == templates && TREE_CODE (fn) != TEMPLATE_DECL)
    6857              :         {
    6858    453401645 :           if (template_only)
    6859       813964 :             add_ignored_candidate (candidates, fn);
    6860    453401645 :           continue;
    6861              :         }
    6862   2757995780 :       if (which == non_templates && TREE_CODE (fn) == TEMPLATE_DECL)
    6863              :         {
    6864   1005300567 :           add_ignored_candidate (&ignored_template_cands, fn);
    6865   1005300567 :           continue;
    6866              :         }
    6867    330321406 :       if ((check_converting && DECL_NONCONVERTING_P (fn))
    6868   2054413670 :           || (check_list_ctor && !is_list_ctor (fn)))
    6869              :         {
    6870     29932683 :           add_ignored_candidate (candidates, fn);
    6871     29932683 :           continue;
    6872              :         }
    6873              : 
    6874   1722762530 :       tree fn_first_arg = NULL_TREE;
    6875   1722762530 :       const vec<tree, va_gc> *fn_args = args;
    6876              : 
    6877   1722762530 :       if (DECL_OBJECT_MEMBER_FUNCTION_P (fn))
    6878              :         {
    6879              :           /* Figure out where the object arg comes from.  If this
    6880              :              function is a non-static member and we didn't get an
    6881              :              implicit object argument, move it out of args.  */
    6882    572658280 :           if (first_arg == NULL_TREE)
    6883              :             {
    6884     12760032 :               unsigned int ix;
    6885     12760032 :               tree arg;
    6886     12760032 :               vec<tree, va_gc> *tempvec;
    6887     12760032 :               vec_alloc (tempvec, args->length () - 1);
    6888     34670438 :               for (ix = 1; args->iterate (ix, &arg); ++ix)
    6889      9150374 :                 tempvec->quick_push (arg);
    6890     12760032 :               non_static_args = tempvec;
    6891     12760032 :               first_arg = (*args)[0];
    6892              :             }
    6893              : 
    6894              :           fn_first_arg = first_arg;
    6895              :           fn_args = non_static_args;
    6896              :         }
    6897              : 
    6898              :       /* Don't bother reversing an operator with two identical parameters.  */
    6899   1150104250 :       else if (vec_safe_length (args) == 2 && (flags & LOOKUP_REVERSED))
    6900              :         {
    6901    371296307 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6902    371296307 :           if (same_type_p (TREE_VALUE (parmlist),
    6903              :                            TREE_VALUE (TREE_CHAIN (parmlist))))
    6904    177377588 :             continue;
    6905              :         }
    6906              : 
    6907              :       /* When considering reversed operator==, if there's a corresponding
    6908              :          operator!= in the same scope, it's not a rewrite target.  */
    6909   1545384942 :       if (ne_context)
    6910              :         {
    6911    250811234 :           if (TREE_CODE (ne_context) == NAMESPACE_DECL)
    6912              :             {
    6913              :               /* With argument-dependent lookup, fns can span multiple
    6914              :                  namespaces; make sure we look in the fn's namespace for a
    6915              :                  corresponding operator!=.  */
    6916    250565441 :               tree fn_ns = decl_namespace_context (fn);
    6917    250565441 :               if (fn_ns != ne_context)
    6918              :                 {
    6919     15226555 :                   ne_context = fn_ns;
    6920     15226555 :                   tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6921     15226555 :                   ne_fns = lookup_qualified_name (ne_context, ne_name,
    6922              :                                                   LOOK_want::NORMAL,
    6923              :                                                   /*complain*/false);
    6924     15226555 :                   if (ne_fns == error_mark_node
    6925      9220095 :                       || !is_overloaded_fn (ne_fns))
    6926      6006460 :                     ne_fns = NULL_TREE;
    6927              :                 }
    6928              :             }
    6929    250811234 :           bool found = false;
    6930   2913788163 :           for (lkp_iterator ne (ne_fns); !found && ne; ++ne)
    6931   2729640768 :             if (0 && !ne.using_p ()
    6932              :                 && DECL_NAMESPACE_SCOPE_P (fn)
    6933              :                 && DECL_CONTEXT (*ne) != DECL_CONTEXT (fn))
    6934              :               /* ??? This kludge excludes inline namespace members for the H
    6935              :                  test in spaceship-eq15.C, but I don't see why we would want
    6936              :                  that behavior.  Asked Core 2022-11-04.  Disabling for now.  */;
    6937   2729640768 :             else if (fns_correspond (fn, *ne))
    6938              :               {
    6939              :                 found = true;
    6940              :                 break;
    6941              :               }
    6942    250811234 :           if (found)
    6943     66663839 :             continue;
    6944              :         }
    6945              : 
    6946              :       /* Do not resolve any non-default function.  Only the default version
    6947              :          is resolvable (for the target_version attribute semantics.)  */
    6948   1478721103 :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    6949              :           && TREE_CODE (fn) == FUNCTION_DECL
    6950              :           && !is_function_default_version (fn))
    6951              :         {
    6952              :           add_ignored_candidate (candidates, fn);
    6953              :           continue;
    6954              :         }
    6955              : 
    6956   1478721103 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    6957    771413669 :         add_template_candidate (candidates,
    6958              :                                 fn,
    6959              :                                 ctype,
    6960              :                                 explicit_targs,
    6961              :                                 fn_first_arg,
    6962              :                                 fn_args,
    6963              :                                 return_type,
    6964              :                                 access_path,
    6965              :                                 conversion_path,
    6966              :                                 flags,
    6967              :                                 strict,
    6968              :                                 shortcut_bad_convs,
    6969              :                                 complain);
    6970              :       else
    6971              :         {
    6972    707307434 :           add_function_candidate (candidates,
    6973              :                                   fn,
    6974              :                                   ctype,
    6975              :                                   fn_first_arg,
    6976              :                                   fn_args,
    6977              :                                   access_path,
    6978              :                                   conversion_path,
    6979              :                                   flags,
    6980              :                                   NULL,
    6981              :                                   shortcut_bad_convs,
    6982              :                                   complain);
    6983    707307434 :           if (perfect_candidate_p (*candidates))
    6984   1478707552 :             seen_perfect = true;
    6985              :         }
    6986              : 
    6987   1478707552 :       z_candidate *cand = *candidates;
    6988   1478707552 :       if (cand->viable == 1)
    6989    373777736 :         seen_strictly_viable = true;
    6990              : 
    6991   1478707552 :       if (cand->viable == -1
    6992     25531727 :           && shortcut_bad_convs
    6993   1504238786 :           && (missing_conversion_p (cand)
    6994     16947477 :               || TREE_CODE (cand->fn) == TEMPLATE_DECL))
    6995              :         {
    6996              :           /* This candidate has been tentatively marked non-strictly viable,
    6997              :              and we didn't compute all argument conversions for it (having
    6998              :              stopped at the first bad conversion).  Move it to BAD_CANDS to
    6999              :              to fully reconsider later if we don't find any strictly viable
    7000              :              candidates.  */
    7001      8609109 :           if (complain & (tf_error | tf_conv))
    7002              :             {
    7003      8090403 :               *candidates = cand->next;
    7004      8090403 :               cand->next = bad_cands;
    7005      8090403 :               bad_cands = cand;
    7006              :             }
    7007              :           else
    7008              :             /* But if we're in a SFINAE context, just mark this candidate as
    7009              :                unviable outright and avoid potentially reconsidering it.
    7010              :                This is safe to do because in a SFINAE context, performing a bad
    7011              :                conversion is always an error (even with -fpermissive), so a
    7012              :                non-strictly viable candidate is effectively unviable anyway.  */
    7013       518706 :             cand->viable = 0;
    7014              :         }
    7015              :     }
    7016    605948565 :   if (which == non_templates && !seen_perfect)
    7017              :     {
    7018    205041971 :       which = templates;
    7019    205041971 :       ignored_template_cands = nullptr;
    7020    205041971 :       goto again;
    7021              :     }
    7022    400906594 :   else if (which == templates
    7023    400906594 :            && !seen_strictly_viable
    7024              :            && shortcut_bad_convs
    7025     79803979 :            && bad_cands)
    7026              :     {
    7027              :       /* None of the candidates are strictly viable, so consider again those
    7028              :          functions in BAD_CANDS, this time without shortcutting bad conversions
    7029              :          so that all their argument conversions are computed.  */
    7030       239626 :       which = either;
    7031              :       fns = NULL_TREE;
    7032       239626 :       for (z_candidate *cand = bad_cands; cand; cand = cand->next)
    7033              :         {
    7034       131609 :           tree fn = cand->fn;
    7035       131609 :           if (tree ti = cand->template_decl)
    7036          117 :             fn = TI_TEMPLATE (ti);
    7037       131609 :           fns = ovl_make (fn, fns);
    7038              :         }
    7039       108017 :       shortcut_bad_convs = false;
    7040       108017 :       bad_cands = nullptr;
    7041       108017 :       goto again;
    7042              :     }
    7043              : 
    7044    400798577 :   if (complain & tf_error)
    7045              :     {
    7046              :       /* Remember any omitted candidates; we may want to print all candidates
    7047              :          as part of overload resolution failure diagnostics.  */
    7048    574087737 :       for (z_candidate *omitted_cands : { ignored_template_cands, bad_cands })
    7049              :         {
    7050    382725158 :           z_candidate **omitted_cands_tail = &omitted_cands;
    7051    439509509 :           while (*omitted_cands_tail)
    7052     56784351 :             omitted_cands_tail = &(*omitted_cands_tail)->next;
    7053    382725158 :           *omitted_cands_tail = *candidates;
    7054    382725158 :           *candidates = omitted_cands;
    7055              :         }
    7056              :     }
    7057              : }
    7058              : 
    7059              : /* Returns 1 if P0145R2 says that the LHS of operator CODE is evaluated first,
    7060              :    -1 if the RHS is evaluated first, or 0 if the order is unspecified.  */
    7061              : 
    7062              : static int
    7063     20068609 : op_is_ordered (tree_code code)
    7064              : {
    7065     20068381 :   switch (code)
    7066              :     {
    7067              :       // 5. b @= a
    7068      3988995 :     case MODIFY_EXPR:
    7069      3988995 :       return (flag_strong_eval_order > 1 ? -1 : 0);
    7070              : 
    7071              :       // 6. a[b]
    7072      1126451 :     case ARRAY_REF:
    7073      1126223 :       return (flag_strong_eval_order > 1 ? 1 : 0);
    7074              : 
    7075              :       // 1. a.b
    7076              :       // Not overloadable (yet).
    7077              :       // 2. a->b
    7078              :       // Only one argument.
    7079              :       // 3. a->*b
    7080        52125 :     case MEMBER_REF:
    7081              :       // 7. a << b
    7082        52125 :     case LSHIFT_EXPR:
    7083              :       // 8. a >> b
    7084        52125 :     case RSHIFT_EXPR:
    7085              :       // a && b
    7086              :       // Predates P0145R3.
    7087        52125 :     case TRUTH_ANDIF_EXPR:
    7088              :       // a || b
    7089              :       // Predates P0145R3.
    7090        52125 :     case TRUTH_ORIF_EXPR:
    7091              :       // a , b
    7092              :       // Predates P0145R3.
    7093        52125 :     case COMPOUND_EXPR:
    7094        52125 :       return (flag_strong_eval_order ? 1 : 0);
    7095              : 
    7096              :     default:
    7097              :       return 0;
    7098              :     }
    7099              : }
    7100              : 
    7101              : /* Subroutine of build_new_op: Add to CANDIDATES all candidates for the
    7102              :    operator indicated by CODE/CODE2.  This function calls itself recursively to
    7103              :    handle C++20 rewritten comparison operator candidates.  Returns NULL_TREE
    7104              :    upon success, and error_mark_node if something went wrong that prevented
    7105              :    us from performing overload resolution (e.g. ambiguous member name lookup).
    7106              : 
    7107              :    LOOKUPS, if non-NULL, is the set of pertinent namespace-scope operator
    7108              :    overloads to consider.  This parameter is used when instantiating a
    7109              :    dependent operator expression and has the same structure as
    7110              :    DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS.  */
    7111              : 
    7112              : static tree
    7113     46784566 : add_operator_candidates (z_candidate **candidates,
    7114              :                          tree_code code, tree_code code2,
    7115              :                          vec<tree, va_gc> *arglist, tree lookups,
    7116              :                          int flags, tsubst_flags_t complain)
    7117              : {
    7118     46784566 :   z_candidate *start_candidates = *candidates;
    7119     46784566 :   bool ismodop = code2 != ERROR_MARK;
    7120     46784566 :   tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    7121              : 
    7122              :   /* LOOKUP_REWRITTEN is set when we're looking for the == or <=> operator to
    7123              :      rewrite from, and also when we're looking for the e.g. < operator to use
    7124              :      on the result of <=>.  In the latter case, we don't want the flag set in
    7125              :      the candidate, we just want to suppress looking for rewrites.  */
    7126     46784566 :   bool rewritten = (flags & LOOKUP_REWRITTEN);
    7127     46784566 :   if (rewritten && code != EQ_EXPR && code != SPACESHIP_EXPR)
    7128      1279079 :     flags &= ~LOOKUP_REWRITTEN;
    7129              : 
    7130     43506835 :   bool memonly = false;
    7131     43506835 :   switch (code)
    7132              :     {
    7133              :       /* =, ->, [], () must be non-static member functions.  */
    7134      9094857 :     case MODIFY_EXPR:
    7135      9094857 :       if (code2 != NOP_EXPR)
    7136              :         break;
    7137              :       /* FALLTHRU */
    7138              :     case COMPONENT_REF:
    7139              :     case ARRAY_REF:
    7140              :       memonly = true;
    7141              :       break;
    7142              : 
    7143              :     default:
    7144              :       break;
    7145              :     }
    7146              : 
    7147              :   /* Add namespace-scope operators to the list of functions to
    7148              :      consider.  */
    7149              :   if (!memonly)
    7150              :     {
    7151     39177011 :       tree fns;
    7152     39177011 :       if (!lookups)
    7153     23841959 :         fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    7154              :       /* If LOOKUPS is non-NULL, then we're instantiating a dependent operator
    7155              :          expression, and LOOKUPS is the result of stage 1 name lookup.  */
    7156     15335052 :       else if (tree found = purpose_member (fnname, lookups))
    7157      5288524 :         fns = TREE_VALUE (found);
    7158              :       else
    7159              :         fns = NULL_TREE;
    7160     39177011 :       fns = lookup_arg_dependent (fnname, fns, arglist);
    7161     39177011 :       add_candidates (fns, NULL_TREE, arglist, NULL_TREE,
    7162              :                       NULL_TREE, false, NULL_TREE, NULL_TREE,
    7163              :                       flags, candidates, complain);
    7164              :     }
    7165              : 
    7166              :   /* Add class-member operators to the candidate set.  */
    7167     46784533 :   tree arg1_type = TREE_TYPE ((*arglist)[0]);
    7168     46784533 :   unsigned nargs = arglist->length () > 1 ? 2 : 1;
    7169     40785895 :   tree arg2_type = nargs > 1 ? TREE_TYPE ((*arglist)[1]) : NULL_TREE;
    7170     46784533 :   if (CLASS_TYPE_P (arg1_type))
    7171              :     {
    7172     27845310 :       tree fns = lookup_fnfields (arg1_type, fnname, 1, complain);
    7173     27845310 :       if (fns == error_mark_node)
    7174              :         return error_mark_node;
    7175     27845298 :       if (fns)
    7176              :         {
    7177     13888505 :           if (code == ARRAY_REF)
    7178              :             {
    7179      1128473 :               vec<tree,va_gc> *restlist = make_tree_vector ();
    7180      2256946 :               for (unsigned i = 1; i < nargs; ++i)
    7181      1128473 :                 vec_safe_push (restlist, (*arglist)[i]);
    7182      1128473 :               z_candidate *save_cand = *candidates;
    7183      2256946 :               add_candidates (BASELINK_FUNCTIONS (fns),
    7184      1128473 :                               (*arglist)[0], restlist, NULL_TREE,
    7185              :                               NULL_TREE, false,
    7186      1128473 :                               BASELINK_BINFO (fns),
    7187      1128473 :                               BASELINK_ACCESS_BINFO (fns),
    7188              :                               flags, candidates, complain);
    7189              :               /* Release the vec if we didn't add a candidate that uses it.  */
    7190      1129069 :               for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7191      1129069 :                 if (c->args == restlist)
    7192              :                   {
    7193      1128473 :                     restlist = NULL;
    7194      1128473 :                     break;
    7195              :                   }
    7196      1128473 :               release_tree_vector (restlist);
    7197              :             }
    7198              :           else
    7199     12760032 :             add_candidates (BASELINK_FUNCTIONS (fns),
    7200              :                             NULL_TREE, arglist, NULL_TREE,
    7201              :                             NULL_TREE, false,
    7202     12760032 :                             BASELINK_BINFO (fns),
    7203     12760032 :                             BASELINK_ACCESS_BINFO (fns),
    7204              :                             flags, candidates, complain);
    7205              :         }
    7206              :     }
    7207              :   /* Per [over.match.oper]3.2, if no operand has a class type, then
    7208              :      only non-member functions that have type T1 or reference to
    7209              :      cv-qualified-opt T1 for the first argument, if the first argument
    7210              :      has an enumeration type, or T2 or reference to cv-qualified-opt
    7211              :      T2 for the second argument, if the second argument has an
    7212              :      enumeration type.  Filter out those that don't match.  */
    7213     18939223 :   else if (! arg2_type || ! CLASS_TYPE_P (arg2_type))
    7214              :     {
    7215              :       struct z_candidate **candp, **next;
    7216              : 
    7217    385542521 :       for (candp = candidates; *candp != start_candidates; candp = next)
    7218              :         {
    7219    367289101 :           unsigned i;
    7220    367289101 :           z_candidate *cand = *candp;
    7221    367289101 :           next = &cand->next;
    7222              : 
    7223    367289101 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    7224              : 
    7225   1091345818 :           for (i = 0; i < nargs; ++i)
    7226              :             {
    7227    728934088 :               tree parmtype = TREE_VALUE (parmlist);
    7228    728934088 :               tree argtype = unlowered_expr_type ((*arglist)[i]);
    7229              : 
    7230    728934088 :               if (TYPE_REF_P (parmtype))
    7231    591224787 :                 parmtype = TREE_TYPE (parmtype);
    7232    728934088 :               if (TREE_CODE (argtype) == ENUMERAL_TYPE
    7233   1438120446 :                   && (same_type_ignoring_top_level_qualifiers_p
    7234    709186358 :                       (argtype, parmtype)))
    7235              :                 break;
    7236              : 
    7237    724056717 :               parmlist = TREE_CHAIN (parmlist);
    7238              :             }
    7239              : 
    7240              :           /* No argument has an appropriate type, so remove this
    7241              :              candidate function from the list.  */
    7242    367289101 :           if (i == nargs)
    7243              :             {
    7244    362411730 :               *candp = cand->next;
    7245    362411730 :               next = candp;
    7246              :             }
    7247              :         }
    7248              :     }
    7249              : 
    7250     46784521 :   if (!rewritten)
    7251              :     {
    7252              :       /* The standard says to rewrite built-in candidates, too,
    7253              :          but there's no point.  */
    7254     31988798 :       add_builtin_candidates (candidates, code, code2, fnname, arglist,
    7255              :                               flags, complain);
    7256              : 
    7257              :       /* Maybe add C++20 rewritten comparison candidates.  */
    7258     31988798 :       tree_code rewrite_code = ERROR_MARK;
    7259     31988798 :       if (cxx_dialect >= cxx20
    7260     31700125 :           && nargs == 2
    7261     57811004 :           && (OVERLOAD_TYPE_P (arg1_type) || OVERLOAD_TYPE_P (arg2_type)))
    7262     25814586 :         switch (code)
    7263              :           {
    7264      1716509 :           case LT_EXPR:
    7265      1716509 :           case LE_EXPR:
    7266      1716509 :           case GT_EXPR:
    7267      1716509 :           case GE_EXPR:
    7268      1716509 :           case SPACESHIP_EXPR:
    7269      1716509 :             rewrite_code = SPACESHIP_EXPR;
    7270      1716509 :             break;
    7271              : 
    7272              :           case NE_EXPR:
    7273              :           case EQ_EXPR:
    7274              :             rewrite_code = EQ_EXPR;
    7275              :             break;
    7276              : 
    7277              :           default:;
    7278              :           }
    7279              : 
    7280      1716509 :       if (rewrite_code)
    7281              :         {
    7282      9385907 :           tree r;
    7283      9385907 :           flags |= LOOKUP_REWRITTEN;
    7284      9385907 :           if (rewrite_code != code)
    7285              :             {
    7286              :               /* Add rewritten candidates in same order.  */
    7287      4130459 :               r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7288              :                                            arglist, lookups, flags, complain);
    7289      4130459 :               if (r == error_mark_node)
    7290              :                 return error_mark_node;
    7291              :             }
    7292              : 
    7293      9385901 :           z_candidate *save_cand = *candidates;
    7294              : 
    7295              :           /* Add rewritten candidates in reverse order.  */
    7296      9385901 :           flags |= LOOKUP_REVERSED;
    7297      9385901 :           vec<tree,va_gc> *revlist = make_tree_vector ();
    7298      9385901 :           revlist->quick_push ((*arglist)[1]);
    7299      9385901 :           revlist->quick_push ((*arglist)[0]);
    7300      9385901 :           r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7301              :                                        revlist, lookups, flags, complain);
    7302      9385901 :           if (r == error_mark_node)
    7303              :             return error_mark_node;
    7304              : 
    7305              :           /* Release the vec if we didn't add a candidate that uses it.  */
    7306      9537055 :           for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7307      3956365 :             if (c->args == revlist)
    7308              :               {
    7309              :                 revlist = NULL;
    7310              :                 break;
    7311              :               }
    7312      9385901 :           release_tree_vector (revlist);
    7313              :         }
    7314              :     }
    7315              : 
    7316              :   return NULL_TREE;
    7317              : }
    7318              : 
    7319              : tree
    7320    240360943 : build_new_op (const op_location_t &loc, enum tree_code code, int flags,
    7321              :               tree arg1, tree arg2, tree arg3, tree lookups,
    7322              :               tree *overload, tsubst_flags_t complain)
    7323              : {
    7324    240360943 :   struct z_candidate *candidates = 0, *cand;
    7325    240360943 :   releasing_vec arglist;
    7326    240360943 :   tree result = NULL_TREE;
    7327    240360943 :   bool result_valid_p = false;
    7328    240360943 :   enum tree_code code2 = ERROR_MARK;
    7329    240360943 :   enum tree_code code_orig_arg1 = ERROR_MARK;
    7330    240360943 :   enum tree_code code_orig_arg2 = ERROR_MARK;
    7331    240360943 :   bool strict_p;
    7332    240360943 :   bool any_viable_p;
    7333              : 
    7334    240360943 :   auto_cond_timevar tv (TV_OVERLOAD);
    7335              : 
    7336    240360943 :   if (error_operand_p (arg1)
    7337    240357298 :       || error_operand_p (arg2)
    7338    480712249 :       || error_operand_p (arg3))
    7339         9637 :     return error_mark_node;
    7340              : 
    7341    240351306 :   conversion_obstack_sentinel cos;
    7342              : 
    7343    240351306 :   bool ismodop = code == MODIFY_EXPR;
    7344    240351306 :   if (ismodop)
    7345              :     {
    7346     13785016 :       code2 = TREE_CODE (arg3);
    7347     13785016 :       arg3 = NULL_TREE;
    7348              :     }
    7349              : 
    7350    240351306 :   tree arg1_type = unlowered_expr_type (arg1);
    7351    240351306 :   tree arg2_type = arg2 ? unlowered_expr_type (arg2) : NULL_TREE;
    7352              : 
    7353    240351306 :   arg1 = prep_operand (arg1);
    7354              : 
    7355    240351306 :   switch (code)
    7356              :     {
    7357            0 :     case NEW_EXPR:
    7358            0 :     case VEC_NEW_EXPR:
    7359            0 :     case VEC_DELETE_EXPR:
    7360            0 :     case DELETE_EXPR:
    7361              :       /* Use build_operator_new_call and build_op_delete_call instead.  */
    7362            0 :       gcc_unreachable ();
    7363              : 
    7364            0 :     case CALL_EXPR:
    7365              :       /* Use build_op_call instead.  */
    7366            0 :       gcc_unreachable ();
    7367              : 
    7368     17815901 :     case TRUTH_ORIF_EXPR:
    7369     17815901 :     case TRUTH_ANDIF_EXPR:
    7370     17815901 :     case TRUTH_AND_EXPR:
    7371     17815901 :     case TRUTH_OR_EXPR:
    7372              :       /* These are saved for the sake of warn_logical_operator.  */
    7373     17815901 :       code_orig_arg1 = TREE_CODE (arg1);
    7374     17815901 :       code_orig_arg2 = TREE_CODE (arg2);
    7375     17815901 :       break;
    7376     56695963 :     case GT_EXPR:
    7377     56695963 :     case LT_EXPR:
    7378     56695963 :     case GE_EXPR:
    7379     56695963 :     case LE_EXPR:
    7380     56695963 :     case EQ_EXPR:
    7381     56695963 :     case NE_EXPR:
    7382              :       /* These are saved for the sake of maybe_warn_bool_compare.  */
    7383     56695963 :       code_orig_arg1 = TREE_CODE (arg1_type);
    7384     56695963 :       code_orig_arg2 = TREE_CODE (arg2_type);
    7385     56695963 :       break;
    7386              : 
    7387              :     default:
    7388              :       break;
    7389              :     }
    7390              : 
    7391    240351306 :   arg2 = prep_operand (arg2);
    7392    240351306 :   arg3 = prep_operand (arg3);
    7393              : 
    7394    240351306 :   if (code == COND_EXPR)
    7395              :     /* Use build_conditional_expr instead.  */
    7396            0 :     gcc_unreachable ();
    7397    240351306 :   else if (! OVERLOAD_TYPE_P (arg1_type)
    7398    447865673 :            && (! arg2 || ! OVERLOAD_TYPE_P (arg2_type)))
    7399    207083100 :     goto builtin;
    7400              : 
    7401     33268206 :   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    7402              :     {
    7403       601670 :       arg2 = integer_zero_node;
    7404       601670 :       arg2_type = integer_type_node;
    7405              :     }
    7406              : 
    7407     33268206 :   arglist->quick_push (arg1);
    7408     33268206 :   if (arg2 != NULL_TREE)
    7409     27269568 :     arglist->quick_push (arg2);
    7410     33268206 :   if (arg3 != NULL_TREE)
    7411            0 :     arglist->quick_push (arg3);
    7412              : 
    7413     33268206 :   result = add_operator_candidates (&candidates, code, code2, arglist,
    7414              :                                     lookups, flags, complain);
    7415     33268173 :   if (result == error_mark_node)
    7416              :     return error_mark_node;
    7417              : 
    7418     33268161 :   switch (code)
    7419              :     {
    7420              :     case COMPOUND_EXPR:
    7421              :     case ADDR_EXPR:
    7422              :       /* For these, the built-in candidates set is empty
    7423              :          [over.match.oper]/3.  We don't want non-strict matches
    7424              :          because exact matches are always possible with built-in
    7425              :          operators.  The built-in candidate set for COMPONENT_REF
    7426              :          would be empty too, but since there are no such built-in
    7427              :          operators, we accept non-strict matches for them.  */
    7428              :       strict_p = true;
    7429              :       break;
    7430              : 
    7431     31449998 :     default:
    7432     31449998 :       strict_p = false;
    7433     31449998 :       break;
    7434              :     }
    7435              : 
    7436     33268161 :   candidates = splice_viable (candidates, strict_p, &any_viable_p);
    7437     33268161 :   if (!any_viable_p)
    7438              :     {
    7439      1857464 :       switch (code)
    7440              :         {
    7441          225 :         case POSTINCREMENT_EXPR:
    7442          225 :         case POSTDECREMENT_EXPR:
    7443              :           /* Don't try anything fancy if we're not allowed to produce
    7444              :              errors.  */
    7445          225 :           if (!(complain & tf_error))
    7446              :             return error_mark_node;
    7447              : 
    7448              :           /* Look for an `operator++ (int)'. Pre-1985 C++ didn't
    7449              :              distinguish between prefix and postfix ++ and
    7450              :              operator++() was used for both, so we allow this with
    7451              :              -fpermissive.  */
    7452              :           else
    7453              :             {
    7454           42 :               tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    7455           30 :               const char *msg = (flag_permissive)
    7456           42 :                 ? G_("no %<%D(int)%> declared for postfix %qs,"
    7457              :                      " trying prefix operator instead")
    7458              :                 : G_("no %<%D(int)%> declared for postfix %qs");
    7459           42 :               permerror (loc, msg, fnname, OVL_OP_INFO (false, code)->name);
    7460              :             }
    7461              : 
    7462           42 :           if (!flag_permissive)
    7463           30 :             return error_mark_node;
    7464              : 
    7465           12 :           if (code == POSTINCREMENT_EXPR)
    7466              :             code = PREINCREMENT_EXPR;
    7467              :           else
    7468            0 :             code = PREDECREMENT_EXPR;
    7469           12 :           result = build_new_op (loc, code, flags, arg1, NULL_TREE,
    7470              :                                  NULL_TREE, lookups, overload, complain);
    7471           12 :           break;
    7472              : 
    7473              :           /* The caller will deal with these.  */
    7474              :         case ADDR_EXPR:
    7475              :         case COMPOUND_EXPR:
    7476              :         case COMPONENT_REF:
    7477              :         case CO_AWAIT_EXPR:
    7478              :           result = NULL_TREE;
    7479              :           result_valid_p = true;
    7480              :           break;
    7481              : 
    7482        36332 :         default:
    7483        36332 :           if (complain & tf_error)
    7484              :             {
    7485              :                 /* If one of the arguments of the operator represents
    7486              :                    an invalid use of member function pointer, try to report
    7487              :                    a meaningful error ...  */
    7488         1342 :               if (invalid_nonstatic_memfn_p (loc, arg1, tf_error)
    7489         1339 :                     || invalid_nonstatic_memfn_p (loc, arg2, tf_error)
    7490         2675 :                     || invalid_nonstatic_memfn_p (loc, arg3, tf_error))
    7491              :                   /* We displayed the error message.  */;
    7492              :                 else
    7493              :                   {
    7494              :                     /* ... Otherwise, report the more generic
    7495              :                        "no matching operator found" error */
    7496         1333 :                     auto_diagnostic_group d;
    7497         1333 :                     op_error (loc, code, code2, arg1, arg2, arg3, false);
    7498         1333 :                     print_z_candidates (loc, candidates);
    7499         1333 :                   }
    7500              :             }
    7501        36332 :           result = error_mark_node;
    7502        36332 :           break;
    7503              :         }
    7504              :     }
    7505              :   else
    7506              :     {
    7507     31410697 :       cand = tourney (candidates, complain);
    7508     31410697 :       if (cand == 0)
    7509              :         {
    7510          186 :           if (complain & tf_error)
    7511              :             {
    7512          129 :               auto_diagnostic_group d;
    7513          129 :               op_error (loc, code, code2, arg1, arg2, arg3, true);
    7514          129 :               print_z_candidates (loc, candidates);
    7515          129 :             }
    7516          186 :           result = error_mark_node;
    7517          186 :           if (overload)
    7518          167 :             *overload = error_mark_node;
    7519              :         }
    7520     31410511 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    7521              :         {
    7522     25171776 :           if (overload)
    7523              :             {
    7524     17689115 :               if (cand->rewritten ())
    7525              :                 /* build_min_non_dep_op_overload needs to know whether the
    7526              :                    candidate is rewritten/reversed.  */
    7527      2552879 :                 *overload = build_tree_list (build_int_cst (integer_type_node,
    7528      2552879 :                                                             cand->flags),
    7529              :                                              cand->fn);
    7530              :               else
    7531     15136236 :                 *overload = cand->fn;
    7532              :             }
    7533              : 
    7534     25171776 :           if (resolve_args (arglist, complain) == NULL)
    7535            4 :             result = error_mark_node;
    7536              :           else
    7537              :             {
    7538     25171772 :               tsubst_flags_t ocomplain = complain;
    7539     25171772 :               if (cand->rewritten ())
    7540              :                 /* We'll wrap this call in another one.  */
    7541      2553281 :                 ocomplain &= ~tf_decltype;
    7542     25171772 :               if (cand->reversed ())
    7543              :                 {
    7544              :                   /* We swapped these in add_candidate, swap them back now.  */
    7545        16199 :                   std::swap (cand->convs[0], cand->convs[1]);
    7546        16199 :                   if (cand->fn == current_function_decl)
    7547            1 :                     warning_at (loc, 0, "in C++20 this comparison calls the "
    7548              :                                 "current function recursively with reversed "
    7549              :                                 "arguments");
    7550              :                 }
    7551     25171772 :               result = build_over_call (cand, LOOKUP_NORMAL, ocomplain);
    7552              :             }
    7553              : 
    7554     45245940 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7555              :             /* There won't be a CALL_EXPR.  */;
    7556     20070795 :           else if (result && result != error_mark_node)
    7557              :             {
    7558     20068381 :               tree call = extract_call_expr (result);
    7559     20068381 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7560              : 
    7561              :               /* Specify evaluation order as per P0145R2.  */
    7562     20068381 :               CALL_EXPR_ORDERED_ARGS (call) = false;
    7563     20068381 :               switch (op_is_ordered (code))
    7564              :                 {
    7565      3964469 :                 case -1:
    7566      3964469 :                   CALL_EXPR_REVERSE_ARGS (call) = true;
    7567      3964469 :                   break;
    7568              : 
    7569      1177311 :                 case 1:
    7570      1177311 :                   CALL_EXPR_ORDERED_ARGS (call) = true;
    7571      1177311 :                   break;
    7572              : 
    7573              :                 default:
    7574              :                   break;
    7575              :                 }
    7576              :             }
    7577              : 
    7578              :           /* If this was a C++20 rewritten comparison, adjust the result.  */
    7579     25171773 :           if (cand->rewritten ())
    7580              :             {
    7581      2553281 :               switch (code)
    7582              :                 {
    7583         7176 :                 case EQ_EXPR:
    7584         7176 :                   gcc_checking_assert (cand->reversed ());
    7585      1272965 :                   gcc_fallthrough ();
    7586      1272965 :                 case NE_EXPR:
    7587      1272965 :                   if (result == error_mark_node)
    7588              :                     ;
    7589              :                   /* If a rewritten operator== candidate is selected by
    7590              :                      overload resolution for an operator @, its return type
    7591              :                      shall be cv bool.... */
    7592      1272963 :                   else if (TREE_CODE (TREE_TYPE (result)) != BOOLEAN_TYPE)
    7593              :                     {
    7594           38 :                       if (complain & tf_error)
    7595              :                         {
    7596            6 :                           auto_diagnostic_group d;
    7597            6 :                           error_at (loc, "return type of %qD is not %qs",
    7598              :                                     cand->fn, "bool");
    7599            6 :                           inform (loc, "used as rewritten candidate for "
    7600              :                                   "comparison of %qT and %qT",
    7601              :                                   arg1_type, arg2_type);
    7602            6 :                         }
    7603           38 :                       result = error_mark_node;
    7604              :                     }
    7605      1272925 :                   else if (code == NE_EXPR)
    7606              :                     /* !(y == x) or !(x == y)  */
    7607      1265770 :                     result = build1_loc (loc, TRUTH_NOT_EXPR,
    7608              :                                          boolean_type_node, result);
    7609              :                   break;
    7610              : 
    7611              :                   /* If a rewritten operator<=> candidate is selected by
    7612              :                      overload resolution for an operator @, x @ y is
    7613              :                      interpreted as 0 @ (y <=> x) if the selected candidate is
    7614              :                      a synthesized candidate with reversed order of parameters,
    7615              :                      or (x <=> y) @ 0 otherwise, using the selected rewritten
    7616              :                      operator<=> candidate.  */
    7617          583 :                 case SPACESHIP_EXPR:
    7618          583 :                   if (!cand->reversed ())
    7619              :                     /* We're in the build_new_op call below for an outer
    7620              :                        reversed call; we don't need to do anything more.  */
    7621              :                     break;
    7622      1280026 :                   gcc_fallthrough ();
    7623      1280026 :                 case LT_EXPR:
    7624      1280026 :                 case LE_EXPR:
    7625      1280026 :                 case GT_EXPR:
    7626      1280026 :                 case GE_EXPR:
    7627      1280026 :                   {
    7628      1280026 :                     tree lhs = result;
    7629      1280026 :                     tree rhs = integer_zero_node;
    7630      1280026 :                     if (cand->reversed ())
    7631         1980 :                       std::swap (lhs, rhs);
    7632      1280026 :                     warning_sentinel ws (warn_zero_as_null_pointer_constant);
    7633      1280026 :                     result = build_new_op (loc, code,
    7634              :                                            LOOKUP_NORMAL|LOOKUP_REWRITTEN,
    7635              :                                            lhs, rhs, NULL_TREE, lookups,
    7636              :                                            NULL, complain);
    7637      1280026 :                   }
    7638      1280026 :                   break;
    7639              : 
    7640            0 :                 default:
    7641            0 :                   gcc_unreachable ();
    7642              :                 }
    7643              :             }
    7644              : 
    7645              :           /* In an expression of the form `a[]' where cand->fn
    7646              :              which is operator[] turns out to be a static member function,
    7647              :              `a' is none-the-less evaluated.  */
    7648     25171773 :           if (code == ARRAY_REF)
    7649      1128451 :             result = keep_unused_object_arg (result, arg1, cand->fn);
    7650              :         }
    7651              :       else
    7652              :         {
    7653              :           /* Give any warnings we noticed during overload resolution.  */
    7654      6238735 :           if (cand->warnings && (complain & tf_warning))
    7655              :             {
    7656              :               struct candidate_warning *w;
    7657            0 :               for (w = cand->warnings; w; w = w->next)
    7658            0 :                 joust (cand, w->loser, 1, complain);
    7659              :             }
    7660              : 
    7661              :           /* Check for comparison of different enum types.  */
    7662      6238735 :           switch (code)
    7663              :             {
    7664      5401873 :             case GT_EXPR:
    7665      5401873 :             case LT_EXPR:
    7666      5401873 :             case GE_EXPR:
    7667      5401873 :             case LE_EXPR:
    7668      5401873 :             case EQ_EXPR:
    7669      5401873 :             case NE_EXPR:
    7670      5401873 :               if (TREE_CODE (arg1_type) == ENUMERAL_TYPE
    7671      5212063 :                   && TREE_CODE (arg2_type) == ENUMERAL_TYPE
    7672     10541106 :                   && (TYPE_MAIN_VARIANT (arg1_type)
    7673      5139233 :                       != TYPE_MAIN_VARIANT (arg2_type)))
    7674              :                 {
    7675           79 :                   if (cxx_dialect >= cxx26
    7676           24 :                       && (complain & tf_warning_or_error) == 0)
    7677            1 :                     result = error_mark_node;
    7678           78 :                   else if (cxx_dialect >= cxx26 || (complain & tf_warning))
    7679          129 :                     emit_diagnostic ((cxx_dialect >= cxx26
    7680              :                                       ? diagnostics::kind::pedwarn
    7681              :                                       : diagnostics::kind::warning),
    7682           76 :                                      loc, OPT_Wenum_compare,
    7683              :                                      "comparison between %q#T and %q#T",
    7684              :                                      arg1_type, arg2_type);
    7685              :                 }
    7686              :               break;
    7687              :             default:
    7688              :               break;
    7689              :             }
    7690              : 
    7691              :           /* "If a built-in candidate is selected by overload resolution, the
    7692              :              operands of class type are converted to the types of the
    7693              :              corresponding parameters of the selected operation function,
    7694              :              except that the second standard conversion sequence of a
    7695              :              user-defined conversion sequence (12.3.3.1.2) is not applied."  */
    7696      6238735 :           conversion *conv = cand->convs[0];
    7697      6238735 :           if (conv->user_conv_p)
    7698              :             {
    7699        47521 :               conv = strip_standard_conversion (conv);
    7700        47521 :               arg1 = convert_like (conv, arg1, complain);
    7701              :             }
    7702              : 
    7703      6238735 :           if (arg2)
    7704              :             {
    7705      5768352 :               conv = cand->convs[1];
    7706      5768352 :               if (conv->user_conv_p)
    7707              :                 {
    7708         8944 :                   conv = strip_standard_conversion (conv);
    7709         8944 :                   arg2 = convert_like (conv, arg2, complain);
    7710              :                 }
    7711              :             }
    7712              : 
    7713      6238735 :           if (arg3)
    7714              :             {
    7715            0 :               conv = cand->convs[2];
    7716            0 :               if (conv->user_conv_p)
    7717              :                 {
    7718            0 :                   conv = strip_standard_conversion (conv);
    7719            0 :                   arg3 = convert_like (conv, arg3, complain);
    7720              :                 }
    7721              :             }
    7722              :         }
    7723              :     }
    7724              : 
    7725     33267945 :   if (result || result_valid_p)
    7726              :     return result;
    7727              : 
    7728      6238734 :  builtin:
    7729    213321834 :   switch (code)
    7730              :     {
    7731      4690590 :     case MODIFY_EXPR:
    7732      4690590 :       return cp_build_modify_expr (loc, arg1, code2, arg2, complain);
    7733              : 
    7734     31438285 :     case INDIRECT_REF:
    7735     31438285 :       return cp_build_indirect_ref (loc, arg1, RO_UNARY_STAR, complain);
    7736              : 
    7737     17814773 :     case TRUTH_ANDIF_EXPR:
    7738     17814773 :     case TRUTH_ORIF_EXPR:
    7739     17814773 :     case TRUTH_AND_EXPR:
    7740     17814773 :     case TRUTH_OR_EXPR:
    7741     17814773 :       if ((complain & tf_warning) && !processing_template_decl)
    7742      9049382 :         warn_logical_operator (loc, code, boolean_type_node,
    7743              :                                code_orig_arg1, arg1,
    7744              :                                code_orig_arg2, arg2);
    7745              :       /* Fall through.  */
    7746     68630166 :     case GT_EXPR:
    7747     68630166 :     case LT_EXPR:
    7748     68630166 :     case GE_EXPR:
    7749     68630166 :     case LE_EXPR:
    7750     68630166 :     case EQ_EXPR:
    7751     68630166 :     case NE_EXPR:
    7752     68630166 :       if ((complain & tf_warning)
    7753     62063641 :           && ((code_orig_arg1 == BOOLEAN_TYPE)
    7754     62063641 :               ^ (code_orig_arg2 == BOOLEAN_TYPE)))
    7755        25453 :         maybe_warn_bool_compare (loc, code, arg1, arg2);
    7756     62063641 :       if (complain & tf_warning && warn_tautological_compare)
    7757       427011 :         warn_tautological_cmp (loc, code, arg1, arg2);
    7758              :       /* Fall through.  */
    7759    139461245 :     case SPACESHIP_EXPR:
    7760    139461245 :     case PLUS_EXPR:
    7761    139461245 :     case MINUS_EXPR:
    7762    139461245 :     case MULT_EXPR:
    7763    139461245 :     case TRUNC_DIV_EXPR:
    7764    139461245 :     case MAX_EXPR:
    7765    139461245 :     case MIN_EXPR:
    7766    139461245 :     case LSHIFT_EXPR:
    7767    139461245 :     case RSHIFT_EXPR:
    7768    139461245 :     case TRUNC_MOD_EXPR:
    7769    139461245 :     case BIT_AND_EXPR:
    7770    139461245 :     case BIT_IOR_EXPR:
    7771    139461245 :     case BIT_XOR_EXPR:
    7772    139461245 :       return cp_build_binary_op (loc, code, arg1, arg2, complain);
    7773              : 
    7774     32178362 :     case UNARY_PLUS_EXPR:
    7775     32178362 :     case NEGATE_EXPR:
    7776     32178362 :     case BIT_NOT_EXPR:
    7777     32178362 :     case TRUTH_NOT_EXPR:
    7778     32178362 :     case PREINCREMENT_EXPR:
    7779     32178362 :     case POSTINCREMENT_EXPR:
    7780     32178362 :     case PREDECREMENT_EXPR:
    7781     32178362 :     case POSTDECREMENT_EXPR:
    7782     32178362 :     case REALPART_EXPR:
    7783     32178362 :     case IMAGPART_EXPR:
    7784     32178362 :     case ABS_EXPR:
    7785     32178362 :     case CO_AWAIT_EXPR:
    7786     32178362 :       return cp_build_unary_op (code, arg1, false, complain);
    7787              : 
    7788      2602906 :     case ARRAY_REF:
    7789      2602906 :       return cp_build_array_ref (input_location, arg1, arg2, complain);
    7790              : 
    7791          747 :     case MEMBER_REF:
    7792          747 :       return build_m_component_ref (cp_build_indirect_ref (loc, arg1,
    7793              :                                                            RO_ARROW_STAR,
    7794              :                                                            complain),
    7795          747 :                                     arg2, complain);
    7796              : 
    7797              :       /* The caller will deal with these.  */
    7798              :     case ADDR_EXPR:
    7799              :     case COMPONENT_REF:
    7800              :     case COMPOUND_EXPR:
    7801              :       return NULL_TREE;
    7802              : 
    7803            0 :     default:
    7804            0 :       gcc_unreachable ();
    7805              :     }
    7806              :   return NULL_TREE;
    7807    240360907 : }
    7808              : 
    7809              : /* Build a new call to operator[].  This may change ARGS.  */
    7810              : 
    7811              : tree
    7812          267 : build_op_subscript (const op_location_t &loc, tree obj,
    7813              :                     vec<tree, va_gc> **args, tree *overload,
    7814              :                     tsubst_flags_t complain)
    7815              : {
    7816          267 :   struct z_candidate *candidates = 0, *cand;
    7817          267 :   tree fns, first_mem_arg = NULL_TREE;
    7818          267 :   bool any_viable_p;
    7819          267 :   tree result = NULL_TREE;
    7820              : 
    7821          267 :   auto_cond_timevar tv (TV_OVERLOAD);
    7822              : 
    7823          267 :   obj = mark_lvalue_use (obj);
    7824              : 
    7825          267 :   if (error_operand_p (obj))
    7826            0 :     return error_mark_node;
    7827              : 
    7828          267 :   tree type = TREE_TYPE (obj);
    7829              : 
    7830          267 :   obj = prep_operand (obj);
    7831              : 
    7832          267 :   if (TYPE_BINFO (type))
    7833              :     {
    7834          267 :       fns = lookup_fnfields (TYPE_BINFO (type), ovl_op_identifier (ARRAY_REF),
    7835              :                              1, complain);
    7836          267 :       if (fns == error_mark_node)
    7837              :         return error_mark_node;
    7838              :     }
    7839              :   else
    7840              :     fns = NULL_TREE;
    7841              : 
    7842          267 :   if (args != NULL && *args != NULL)
    7843              :     {
    7844          267 :       *args = resolve_args (*args, complain);
    7845          267 :       if (*args == NULL)
    7846            0 :         return error_mark_node;
    7847              :     }
    7848              : 
    7849          267 :   conversion_obstack_sentinel cos;
    7850              : 
    7851          267 :   if (fns)
    7852              :     {
    7853          265 :       first_mem_arg = obj;
    7854              : 
    7855          265 :       add_candidates (BASELINK_FUNCTIONS (fns),
    7856              :                       first_mem_arg, *args, NULL_TREE,
    7857              :                       NULL_TREE, false,
    7858          265 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    7859              :                       LOOKUP_NORMAL, &candidates, complain);
    7860              :     }
    7861              : 
    7862              :   /* Be strict here because if we choose a bad conversion candidate, the
    7863              :      errors we get won't mention the call context.  */
    7864          267 :   candidates = splice_viable (candidates, true, &any_viable_p);
    7865          267 :   if (!any_viable_p)
    7866              :     {
    7867           39 :       if (complain & tf_error)
    7868              :         {
    7869            1 :           auto_diagnostic_group d;
    7870            2 :           error ("no match for call to %<%T::operator[] (%A)%>",
    7871            1 :                  TREE_TYPE (obj), build_tree_list_vec (*args));
    7872            1 :           print_z_candidates (loc, candidates);
    7873            1 :         }
    7874           39 :       result = error_mark_node;
    7875              :     }
    7876              :   else
    7877              :     {
    7878          228 :       cand = tourney (candidates, complain);
    7879          228 :       if (cand == 0)
    7880              :         {
    7881            0 :           if (complain & tf_error)
    7882              :             {
    7883            0 :               auto_diagnostic_group d;
    7884            0 :               error ("call of %<%T::operator[] (%A)%> is ambiguous",
    7885            0 :                      TREE_TYPE (obj), build_tree_list_vec (*args));
    7886            0 :               print_z_candidates (loc, candidates);
    7887            0 :             }
    7888            0 :           result = error_mark_node;
    7889              :         }
    7890          228 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    7891          228 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    7892          456 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, ARRAY_REF))
    7893              :         {
    7894          228 :           if (overload)
    7895          228 :             *overload = cand->fn;
    7896          228 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    7897          456 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7898              :             /* There won't be a CALL_EXPR.  */;
    7899          228 :           else if (result && result != error_mark_node)
    7900              :             {
    7901          228 :               tree call = extract_call_expr (result);
    7902          228 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7903              : 
    7904              :               /* Specify evaluation order as per P0145R2.  */
    7905          228 :               CALL_EXPR_ORDERED_ARGS (call) = op_is_ordered (ARRAY_REF) == 1;
    7906              :             }
    7907              : 
    7908              :           /* In an expression of the form `a[]' where cand->fn
    7909              :              which is operator[] turns out to be a static member function,
    7910              :              `a' is none-the-less evaluated.  */
    7911          228 :           result = keep_unused_object_arg (result, obj, cand->fn);
    7912              :         }
    7913              :       else
    7914            0 :         gcc_unreachable ();
    7915              :     }
    7916              : 
    7917          267 :   return result;
    7918          267 : }
    7919              : 
    7920              : /* CALL was returned by some call-building function; extract the actual
    7921              :    CALL_EXPR from any bits that have been tacked on, e.g. by
    7922              :    convert_from_reference.  */
    7923              : 
    7924              : tree
    7925     50389388 : extract_call_expr (tree call)
    7926              : {
    7927     50389785 :   while (TREE_CODE (call) == COMPOUND_EXPR)
    7928          397 :     call = TREE_OPERAND (call, 1);
    7929     50389388 :   if (REFERENCE_REF_P (call))
    7930     12378482 :     call = TREE_OPERAND (call, 0);
    7931     50389388 :   if (TREE_CODE (call) == TARGET_EXPR)
    7932      3743208 :     call = TARGET_EXPR_INITIAL (call);
    7933              : 
    7934     50389388 :   if (TREE_CODE (call) != CALL_EXPR
    7935       809031 :       && TREE_CODE (call) != AGGR_INIT_EXPR
    7936       714704 :       && call != error_mark_node)
    7937       714686 :     return NULL_TREE;
    7938              :   return call;
    7939              : }
    7940              : 
    7941              : /* Returns true if FN has two parameters, of which the second has type
    7942              :    size_t.  */
    7943              : 
    7944              : static bool
    7945       619449 : second_parm_is_size_t (tree fn)
    7946              : {
    7947       619449 :   tree t = FUNCTION_ARG_CHAIN (fn);
    7948       619449 :   if (!t || !same_type_p (TREE_VALUE (t), size_type_node))
    7949       619434 :     return false;
    7950           15 :   t = TREE_CHAIN (t);
    7951           15 :   if (t == void_list_node)
    7952              :     return true;
    7953              :   return false;
    7954              : }
    7955              : 
    7956              : /* True if T, an allocation function, has std::align_val_t as its second
    7957              :    argument.  */
    7958              : 
    7959              : bool
    7960       315738 : aligned_allocation_fn_p (tree t)
    7961              : {
    7962       315738 :   if (!aligned_new_threshold)
    7963              :     return false;
    7964              : 
    7965       306591 :   tree a = FUNCTION_ARG_CHAIN (t);
    7966       306591 :   return (a && same_type_p (TREE_VALUE (a), align_type_node));
    7967              : }
    7968              : 
    7969              : /* True if T is std::destroying_delete_t.  */
    7970              : 
    7971              : static bool
    7972      5555088 : std_destroying_delete_t_p (tree t)
    7973              : {
    7974      5555088 :   return (TYPE_CONTEXT (t) == std_node
    7975      5555088 :           && id_equal (TYPE_IDENTIFIER (t), "destroying_delete_t"));
    7976              : }
    7977              : 
    7978              : /* A deallocation function with at least two parameters whose second parameter
    7979              :    type is of type std::destroying_delete_t is a destroying operator delete. A
    7980              :    destroying operator delete shall be a class member function named operator
    7981              :    delete. [ Note: Array deletion cannot use a destroying operator
    7982              :    delete. --end note ] */
    7983              : 
    7984              : tree
    7985      5555103 : destroying_delete_p (tree t)
    7986              : {
    7987      5555103 :   tree a = TYPE_ARG_TYPES (TREE_TYPE (t));
    7988      5555103 :   if (!a || !TREE_CHAIN (a))
    7989              :     return NULL_TREE;
    7990      5555088 :   tree type = TREE_VALUE (TREE_CHAIN (a));
    7991      5555088 :   return std_destroying_delete_t_p (type) ? type : NULL_TREE;
    7992              : }
    7993              : 
    7994              : struct dealloc_info
    7995              : {
    7996              :   bool sized;
    7997              :   bool aligned;
    7998              :   tree destroying;
    7999              : };
    8000              : 
    8001              : /* Returns true iff T, an element of an OVERLOAD chain, is a usual deallocation
    8002              :    function (3.7.4.2 [basic.stc.dynamic.deallocation]).  If so, and DI is
    8003              :    non-null, also set *DI. */
    8004              : 
    8005              : static bool
    8006      3842978 : usual_deallocation_fn_p (tree t, dealloc_info *di)
    8007              : {
    8008      3842978 :   if (di) *di = dealloc_info();
    8009              : 
    8010              :   /* A template instance is never a usual deallocation function,
    8011              :      regardless of its signature.  */
    8012      3842978 :   if (TREE_CODE (t) == TEMPLATE_DECL
    8013      3842978 :       || primary_template_specialization_p (t))
    8014           12 :     return false;
    8015              : 
    8016              :   /* A usual deallocation function is a deallocation function whose parameters
    8017              :      after the first are
    8018              :      - optionally, a parameter of type std::destroying_delete_t, then
    8019              :      - optionally, a parameter of type std::size_t, then
    8020              :      - optionally, a parameter of type std::align_val_t.  */
    8021      3842966 :   bool global = DECL_NAMESPACE_SCOPE_P (t);
    8022      3842966 :   tree chain = FUNCTION_ARG_CHAIN (t);
    8023      3842966 :   if (chain && destroying_delete_p (t))
    8024              :     {
    8025           78 :       if (di) di->destroying = TREE_VALUE (chain);
    8026           78 :       chain = TREE_CHAIN (chain);
    8027              :     }
    8028      3842966 :   if (chain
    8029      3842963 :       && (!global || flag_sized_deallocation)
    8030      7672026 :       && same_type_p (TREE_VALUE (chain), size_type_node))
    8031              :     {
    8032      1106476 :       if (di) di->sized = true;
    8033      1106476 :       chain = TREE_CHAIN (chain);
    8034              :     }
    8035      3842963 :   if (chain && aligned_new_threshold
    8036      7671097 :       && same_type_p (TREE_VALUE (chain), align_type_node))
    8037              :     {
    8038      1644440 :       if (di) di->aligned = true;
    8039      1644440 :       chain = TREE_CHAIN (chain);
    8040              :     }
    8041      3842966 :   return (chain == void_list_node);
    8042              : }
    8043              : 
    8044              : /* Just return whether FN is a usual deallocation function.  */
    8045              : 
    8046              : bool
    8047         8672 : usual_deallocation_fn_p (tree fn)
    8048              : {
    8049         8672 :   return usual_deallocation_fn_p (fn, NULL);
    8050              : }
    8051              : 
    8052              : /* Build a call to operator delete.  This has to be handled very specially,
    8053              :    because the restrictions on what signatures match are different from all
    8054              :    other call instances.  For a normal delete, only a delete taking (void *)
    8055              :    or (void *, size_t) is accepted.  For a placement delete, only an exact
    8056              :    match with the placement new is accepted.
    8057              : 
    8058              :    CODE is either DELETE_EXPR or VEC_DELETE_EXPR.
    8059              :    ADDR is the pointer to be deleted.
    8060              :    SIZE is the size of the memory block to be deleted.
    8061              :    GLOBAL_P is true if the delete-expression should not consider
    8062              :    class-specific delete operators.
    8063              :    CORO_P is true if the allocation is for a coroutine, where the two argument
    8064              :    usual deallocation should be chosen in preference to the single argument
    8065              :    version in a class context.
    8066              :    PLACEMENT is the corresponding placement new call, or NULL_TREE.
    8067              : 
    8068              :    If this call to "operator delete" is being generated as part to
    8069              :    deallocate memory allocated via a new-expression (as per [expr.new]
    8070              :    which requires that if the initialization throws an exception then
    8071              :    we call a deallocation function), then ALLOC_FN is the allocation
    8072              :    function.  */
    8073              : 
    8074              : static tree
    8075      1178080 : build_op_delete_call_1 (enum tree_code code, tree addr, tree size,
    8076              :                         bool global_p, bool coro_p, tree placement,
    8077              :                         tree alloc_fn, tsubst_flags_t complain)
    8078              : {
    8079      1178080 :   tree fn = NULL_TREE;
    8080      1178080 :   tree fns, fnname, type, t;
    8081      1178080 :   dealloc_info di_fn = { };
    8082              : 
    8083      1178080 :   if (addr == error_mark_node)
    8084              :     return error_mark_node;
    8085              : 
    8086      1178080 :   type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
    8087              : 
    8088      1178080 :   fnname = ovl_op_identifier (false, code);
    8089              : 
    8090       836522 :   if (CLASS_TYPE_P (type)
    8091       836486 :       && COMPLETE_TYPE_P (complete_type (type))
    8092      2014543 :       && !global_p)
    8093              :     /* In [class.free]
    8094              : 
    8095              :        If the result of the lookup is ambiguous or inaccessible, or if
    8096              :        the lookup selects a placement deallocation function, the
    8097              :        program is ill-formed.
    8098              : 
    8099              :        Therefore, we ask lookup_fnfields to complain about ambiguity.  */
    8100              :     {
    8101       472022 :       fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1, complain);
    8102       472022 :       if (fns == error_mark_node)
    8103              :         return error_mark_node;
    8104              :     }
    8105              :   else
    8106              :     fns = NULL_TREE;
    8107              : 
    8108       472019 :   if (fns == NULL_TREE)
    8109      1177020 :     fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    8110              : 
    8111              :   /* Strip const and volatile from addr.  */
    8112      1178077 :   tree oaddr = addr;
    8113      1178077 :   addr = cp_convert (ptr_type_node, addr, complain);
    8114              : 
    8115      1178077 :   tree excluded_destroying = NULL_TREE;
    8116              : 
    8117      1178077 :   if (placement)
    8118              :     {
    8119              :       /* "A declaration of a placement deallocation function matches the
    8120              :          declaration of a placement allocation function if it has the same
    8121              :          number of parameters and, after parameter transformations (8.3.5),
    8122              :          all parameter types except the first are identical."
    8123              : 
    8124              :          So we build up the function type we want and ask instantiate_type
    8125              :          to get it for us.  */
    8126       620312 :       t = FUNCTION_ARG_CHAIN (alloc_fn);
    8127       620312 :       t = tree_cons (NULL_TREE, ptr_type_node, t);
    8128       620312 :       t = build_function_type (void_type_node, t);
    8129              : 
    8130       620312 :       fn = instantiate_type (t, fns, tf_none);
    8131       620312 :       if (fn == error_mark_node)
    8132              :         return NULL_TREE;
    8133              : 
    8134       619449 :       fn = MAYBE_BASELINK_FUNCTIONS (fn);
    8135              : 
    8136              :       /* "If the lookup finds the two-parameter form of a usual deallocation
    8137              :          function (3.7.4.2) and that function, considered as a placement
    8138              :          deallocation function, would have been selected as a match for the
    8139              :          allocation function, the program is ill-formed."  */
    8140       619449 :       if (second_parm_is_size_t (fn))
    8141              :         {
    8142            9 :           const char *const msg1
    8143              :             = G_("exception cleanup for this placement new selects "
    8144              :                  "non-placement %<operator delete%>");
    8145            9 :           const char *const msg2
    8146              :             = G_("%qD is a usual (non-placement) deallocation "
    8147              :                  "function in C++14 (or with %<-fsized-deallocation%>)");
    8148              : 
    8149              :           /* But if the class has an operator delete (void *), then that is
    8150              :              the usual deallocation function, so we shouldn't complain
    8151              :              about using the operator delete (void *, size_t).  */
    8152            9 :           if (DECL_CLASS_SCOPE_P (fn))
    8153           18 :             for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8154              :               {
    8155            9 :                 if (usual_deallocation_fn_p (elt)
    8156            9 :                     && FUNCTION_ARG_CHAIN (elt) == void_list_node)
    8157            3 :                   goto ok;
    8158              :               }
    8159              :           /* Before C++14 a two-parameter global deallocation function is
    8160              :              always a placement deallocation function, but warn if
    8161              :              -Wc++14-compat.  */
    8162            3 :           else if (!flag_sized_deallocation)
    8163              :             {
    8164            1 :               if (complain & tf_warning)
    8165              :                 {
    8166            1 :                   auto_diagnostic_group d;
    8167            1 :                   if (warning (OPT_Wc__14_compat, msg1))
    8168            1 :                     inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
    8169            1 :                 }
    8170            1 :               goto ok;
    8171              :             }
    8172              : 
    8173            5 :           if (complain & tf_warning_or_error)
    8174              :             {
    8175            5 :               auto_diagnostic_group d;
    8176            5 :               if (permerror (input_location, msg1))
    8177              :                 {
    8178              :                   /* Only mention C++14 for namespace-scope delete.  */
    8179            5 :                   if (DECL_NAMESPACE_SCOPE_P (fn))
    8180            2 :                     inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
    8181              :                   else
    8182            3 :                     inform (DECL_SOURCE_LOCATION (fn),
    8183              :                             "%qD is a usual (non-placement) deallocation "
    8184              :                             "function", fn);
    8185              :                 }
    8186            5 :             }
    8187              :           else
    8188            0 :             return error_mark_node;
    8189      1177214 :         ok:;
    8190              :         }
    8191              :     }
    8192              :   else
    8193              :     /* "Any non-placement deallocation function matches a non-placement
    8194              :        allocation function. If the lookup finds a single matching
    8195              :        deallocation function, that function will be called; otherwise, no
    8196              :        deallocation function will be called."  */
    8197      4949836 :     for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8198              :       {
    8199      3834306 :         dealloc_info di_elt;
    8200      3834306 :         if (usual_deallocation_fn_p (elt, &di_elt))
    8201              :           {
    8202              :             /* If we're called for an EH cleanup in a new-expression, we can't
    8203              :                use a destroying delete; the exception was thrown before the
    8204              :                object was constructed.  */
    8205      2211050 :             if (alloc_fn && di_elt.destroying)
    8206              :               {
    8207           13 :                 excluded_destroying = elt;
    8208      1126614 :                 continue;
    8209              :               }
    8210              : 
    8211      2211037 :             if (!fn)
    8212              :               {
    8213       557740 :                 fn = elt;
    8214       557740 :                 di_fn = di_elt;
    8215       557740 :                 continue;
    8216              :               }
    8217              : 
    8218              :             /* -- If any of the deallocation functions is a destroying
    8219              :                operator delete, all deallocation functions that are not
    8220              :                destroying operator deletes are eliminated from further
    8221              :                consideration.  */
    8222      1653297 :             if (di_elt.destroying != di_fn.destroying)
    8223              :               {
    8224           12 :                 if (di_elt.destroying)
    8225              :                   {
    8226            6 :                     fn = elt;
    8227            6 :                     di_fn = di_elt;
    8228              :                   }
    8229           12 :                 continue;
    8230              :               }
    8231              : 
    8232              :             /* -- If the type has new-extended alignment, a function with a
    8233              :                parameter of type std::align_val_t is preferred; otherwise a
    8234              :                function without such a parameter is preferred. If exactly one
    8235              :                preferred function is found, that function is selected and the
    8236              :                selection process terminates. If more than one preferred
    8237              :                function is found, all non-preferred functions are eliminated
    8238              :                from further consideration.  */
    8239      1653285 :             if (aligned_new_threshold)
    8240              :               {
    8241      1653044 :                 bool want_align = type_has_new_extended_alignment (type);
    8242      1653044 :                 if (di_elt.aligned != di_fn.aligned)
    8243              :                   {
    8244       568849 :                     if (want_align == di_elt.aligned)
    8245              :                       {
    8246       533168 :                         fn = elt;
    8247       533168 :                         di_fn = di_elt;
    8248              :                       }
    8249       568849 :                     continue;
    8250              :                   }
    8251              :               }
    8252              : 
    8253              :             /* -- If the deallocation functions have class scope, the one
    8254              :                without a parameter of type std::size_t is selected.  */
    8255      1084436 :             bool want_size;
    8256      1084436 :             if (DECL_CLASS_SCOPE_P (fn) && !coro_p)
    8257              :               want_size = false;
    8258              : 
    8259              :             /* -- If the type is complete and if, for the second alternative
    8260              :                (delete array) only, the operand is a pointer to a class type
    8261              :                with a non-trivial destructor or a (possibly multi-dimensional)
    8262              :                array thereof, the function with a parameter of type std::size_t
    8263              :                is selected.
    8264              : 
    8265              :                -- Otherwise, it is unspecified whether a deallocation function
    8266              :                with a parameter of type std::size_t is selected.  */
    8267              :             else
    8268              :               {
    8269      1084328 :                 want_size = COMPLETE_TYPE_P (type);
    8270      1084328 :                 if (code == VEC_DELETE_EXPR
    8271      1084328 :                     && !TYPE_VEC_NEW_USES_COOKIE (type))
    8272              :                   /* We need a cookie to determine the array size.  */
    8273              :                   want_size = false;
    8274              :               }
    8275      1084436 :             gcc_assert (di_fn.sized != di_elt.sized);
    8276      1084436 :             if (want_size == di_elt.sized)
    8277              :               {
    8278        43385 :                 fn = elt;
    8279        43385 :                 di_fn = di_elt;
    8280              :               }
    8281              :           }
    8282              :       }
    8283              : 
    8284              :   /* If we have a matching function, call it.  */
    8285      1177214 :   if (fn)
    8286              :     {
    8287      1177189 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    8288              : 
    8289              :       /* If the FN is a member function, make sure that it is
    8290              :          accessible.  */
    8291      1177189 :       if (BASELINK_P (fns))
    8292          990 :         perform_or_defer_access_check (BASELINK_BINFO (fns), fn, fn,
    8293              :                                        complain);
    8294              : 
    8295              :       /* Core issue 901: It's ok to new a type with deleted delete.  */
    8296      1177189 :       if (DECL_DELETED_FN (fn) && alloc_fn)
    8297              :         return NULL_TREE;
    8298              : 
    8299      1177183 :       tree ret;
    8300      1177183 :       if (placement)
    8301              :         {
    8302              :           /* The placement args might not be suitable for overload
    8303              :              resolution at this point, so build the call directly.  */
    8304       619449 :           int nargs = call_expr_nargs (placement);
    8305       619449 :           tree *argarray = XALLOCAVEC (tree, nargs);
    8306       619449 :           int i;
    8307       619449 :           argarray[0] = addr;
    8308      1238949 :           for (i = 1; i < nargs; i++)
    8309       619500 :             argarray[i] = CALL_EXPR_ARG (placement, i);
    8310       619449 :           if (!mark_used (fn, complain) && !(complain & tf_error))
    8311            0 :             return error_mark_node;
    8312       619449 :           ret = build_cxx_call (fn, nargs, argarray, complain);
    8313              :         }
    8314              :       else
    8315              :         {
    8316       557734 :           tree destroying = di_fn.destroying;
    8317       557734 :           if (destroying)
    8318              :             {
    8319              :               /* Strip const and volatile from addr but retain the type of the
    8320              :                  object.  */
    8321           25 :               tree rtype = TREE_TYPE (TREE_TYPE (oaddr));
    8322           25 :               rtype = cv_unqualified (rtype);
    8323           25 :               rtype = TYPE_POINTER_TO (rtype);
    8324           25 :               addr = cp_convert (rtype, oaddr, complain);
    8325           25 :               destroying = build_functional_cast (input_location,
    8326              :                                                   destroying, NULL_TREE,
    8327              :                                                   complain);
    8328              :             }
    8329              : 
    8330       557734 :           releasing_vec args;
    8331       557734 :           args->quick_push (addr);
    8332       557734 :           if (destroying)
    8333           25 :             args->quick_push (destroying);
    8334       557734 :           if (di_fn.sized)
    8335       520924 :             args->quick_push (size);
    8336       557734 :           if (di_fn.aligned)
    8337              :             {
    8338        17844 :               tree al = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (type));
    8339        17844 :               args->quick_push (al);
    8340              :             }
    8341       557734 :           ret = cp_build_function_call_vec (fn, &args, complain);
    8342       557734 :         }
    8343              : 
    8344              :       /* Set this flag for all callers of this function.  In addition to
    8345              :          delete-expressions, this is called for deallocating coroutine state;
    8346              :          treat that as an implicit delete-expression.  This is also called for
    8347              :          the delete if the constructor throws in a new-expression, and for a
    8348              :          deleting destructor (which implements a delete-expression).  */
    8349              :       /* But leave this flag off for destroying delete to avoid wrong
    8350              :          assumptions in the optimizers.  */
    8351      1177183 :       tree call = extract_call_expr (ret);
    8352      1177183 :       if (TREE_CODE (call) == CALL_EXPR && !destroying_delete_p (fn))
    8353      1177152 :         CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    8354              : 
    8355      1177183 :       return ret;
    8356              :     }
    8357              : 
    8358              :   /* If there's only a destroying delete that we can't use because the
    8359              :      object isn't constructed yet, and we used global new, use global
    8360              :      delete as well.  */
    8361           25 :   if (excluded_destroying
    8362           25 :       && DECL_NAMESPACE_SCOPE_P (alloc_fn))
    8363            7 :     return build_op_delete_call (code, addr, size, true, placement,
    8364            7 :                                  alloc_fn, complain);
    8365              : 
    8366              :   /* [expr.new]
    8367              : 
    8368              :      If no unambiguous matching deallocation function can be found,
    8369              :      propagating the exception does not cause the object's memory to
    8370              :      be freed.  */
    8371           18 :   if (alloc_fn)
    8372              :     {
    8373           15 :       if ((complain & tf_warning)
    8374           15 :           && !placement)
    8375              :         {
    8376           15 :           bool w = warning (0,
    8377              :                             "no corresponding deallocation function for %qD",
    8378              :                             alloc_fn);
    8379           15 :           if (w && excluded_destroying)
    8380            3 :             inform (DECL_SOURCE_LOCATION (excluded_destroying), "destroying "
    8381              :                     "delete %qD cannot be used to release the allocated memory"
    8382              :                     " if the initialization throws because the object is not "
    8383              :                     "constructed yet", excluded_destroying);
    8384              :         }
    8385           15 :       return NULL_TREE;
    8386              :     }
    8387              : 
    8388            3 :   if (complain & tf_error)
    8389            3 :     error ("no suitable %<operator %s%> for %qT",
    8390            3 :            OVL_OP_INFO (false, code)->name, type);
    8391            3 :   return error_mark_node;
    8392              : }
    8393              : 
    8394              : /* Arguments as per build_op_delete_call_1 ().  */
    8395              : 
    8396              : tree
    8397      1174893 : build_op_delete_call (enum tree_code code, tree addr, tree size, bool global_p,
    8398              :                       tree placement, tree alloc_fn, tsubst_flags_t complain)
    8399              : {
    8400      1174893 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/false,
    8401      1174893 :                                  placement, alloc_fn, complain);
    8402              : }
    8403              : 
    8404              : /* Arguments as per build_op_delete_call_1 ().  */
    8405              : 
    8406              : tree
    8407         3187 : build_coroutine_op_delete_call (enum tree_code code, tree addr, tree size,
    8408              :                                 bool global_p, tree placement, tree alloc_fn,
    8409              :                                 tsubst_flags_t complain)
    8410              : {
    8411         3187 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/true,
    8412         3187 :                                  placement, alloc_fn, complain);
    8413              : }
    8414              : 
    8415              : /* Issue diagnostics about a disallowed access of DECL, using DIAG_DECL
    8416              :    in the diagnostics.
    8417              : 
    8418              :    If ISSUE_ERROR is true, then issue an error about the access, followed
    8419              :    by a note showing the declaration.  Otherwise, just show the note.
    8420              : 
    8421              :    DIAG_DECL and DIAG_LOCATION will almost always be the same.
    8422              :    DIAG_LOCATION is just another DECL.  NO_ACCESS_REASON is an optional
    8423              :    parameter used to specify why DECL wasn't accessible (e.g. ak_private
    8424              :    would be because DECL was private).  If not using NO_ACCESS_REASON,
    8425              :    then it must be ak_none, and the access failure reason will be
    8426              :    figured out by looking at the protection of DECL.  */
    8427              : 
    8428              : void
    8429         1179 : complain_about_access (tree decl, tree diag_decl, tree diag_location,
    8430              :                        bool issue_error, access_kind no_access_reason)
    8431              : {
    8432              :   /* If we have not already figured out why DECL is inaccessible...  */
    8433         1179 :   if (no_access_reason == ak_none)
    8434              :     {
    8435              :       /* Examine the access of DECL to find out why.  */
    8436          997 :       if (TREE_PRIVATE (decl))
    8437              :         no_access_reason = ak_private;
    8438          225 :       else if (TREE_PROTECTED (decl))
    8439              :         no_access_reason = ak_protected;
    8440              :     }
    8441              : 
    8442              :   /* Now generate an error message depending on calculated access.  */
    8443          227 :   if (no_access_reason == ak_private)
    8444              :     {
    8445          954 :       if (issue_error)
    8446          940 :         error ("%q#D is private within this context", diag_decl);
    8447          954 :       inform (DECL_SOURCE_LOCATION (diag_location), "declared private here");
    8448              :     }
    8449          225 :   else if (no_access_reason == ak_protected)
    8450              :     {
    8451          180 :       if (issue_error)
    8452          166 :         error ("%q#D is protected within this context", diag_decl);
    8453          180 :       inform (DECL_SOURCE_LOCATION (diag_location), "declared protected here");
    8454              :     }
    8455              :   /* Couldn't figure out why DECL is inaccesible, so just say it's
    8456              :      inaccessible.  */
    8457              :   else
    8458              :     {
    8459           45 :       if (issue_error)
    8460           45 :         error ("%q#D is inaccessible within this context", diag_decl);
    8461           45 :       inform (DECL_SOURCE_LOCATION (diag_decl), "declared here");
    8462              :     }
    8463         1179 : }
    8464              : 
    8465              : /* Initialize a temporary of type TYPE with EXPR.  The FLAGS are a
    8466              :    bitwise or of LOOKUP_* values.  If any errors are warnings are
    8467              :    generated, set *DIAGNOSTIC_FN to "error" or "warning",
    8468              :    respectively.  If no diagnostics are generated, set *DIAGNOSTIC_FN
    8469              :    to NULL.  */
    8470              : 
    8471              : static tree
    8472     19753113 : build_temp (tree expr, tree type, int flags,
    8473              :             enum diagnostics::kind *diagnostic_kind, tsubst_flags_t complain)
    8474              : {
    8475     19753113 :   int savew, savee;
    8476              : 
    8477     19753113 :   *diagnostic_kind = diagnostics::kind::unspecified;
    8478              : 
    8479              :   /* If the source is a packed field, calling the copy constructor will require
    8480              :      binding the field to the reference parameter to the copy constructor, and
    8481              :      we'll end up with an infinite loop.  If we can use a bitwise copy, then
    8482              :      do that now.  */
    8483     19753113 :   if ((lvalue_kind (expr) & clk_packed)
    8484            6 :       && CLASS_TYPE_P (TREE_TYPE (expr))
    8485     19753119 :       && !type_has_nontrivial_copy_init (TREE_TYPE (expr)))
    8486            3 :     return get_target_expr (expr, complain);
    8487              : 
    8488              :   /* In decltype, we might have decided not to wrap this call in a TARGET_EXPR.
    8489              :      But it turns out to be a subexpression, so perform temporary
    8490              :      materialization now.  */
    8491     19753110 :   if (TREE_CODE (expr) == CALL_EXPR
    8492            6 :       && CLASS_TYPE_P (type)
    8493     19753116 :       && same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (expr)))
    8494            3 :     expr = build_cplus_new (type, expr, complain);
    8495              : 
    8496     19753110 :   savew = warningcount + werrorcount, savee = errorcount;
    8497     19753110 :   releasing_vec args (make_tree_vector_single (expr));
    8498     19753110 :   expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
    8499              :                                     &args, type, flags, complain);
    8500     19753110 :   if (warningcount + werrorcount > savew)
    8501            0 :     *diagnostic_kind = diagnostics::kind::warning;
    8502     19753110 :   else if (errorcount > savee)
    8503           77 :     *diagnostic_kind = diagnostics::kind::error;
    8504     19753110 :   return expr;
    8505     19753110 : }
    8506              : 
    8507              : /* Get any location for EXPR, falling back to input_location.
    8508              : 
    8509              :    If the result is in a system header and is the virtual location for
    8510              :    a token coming from the expansion of a macro, unwind it to the
    8511              :    location of the expansion point of the macro (e.g. to avoid the
    8512              :    diagnostic being suppressed for expansions of NULL where "NULL" is
    8513              :    in a system header).  */
    8514              : 
    8515              : static location_t
    8516      2419211 : get_location_for_expr_unwinding_for_system_header (tree expr)
    8517              : {
    8518      2419211 :   location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
    8519      2419211 :   loc = expansion_point_location_if_in_system_header (loc);
    8520      2419211 :   return loc;
    8521              : }
    8522              : 
    8523              : /* Perform warnings about peculiar, but valid, conversions from/to NULL.
    8524              :    Also handle a subset of zero as null warnings.
    8525              :    EXPR is implicitly converted to type TOTYPE.
    8526              :    FN and ARGNUM are used for diagnostics.  */
    8527              : 
    8528              : static void
    8529    596999855 : conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
    8530              : {
    8531              :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    8532    596999855 :   if (TREE_CODE (totype) != BOOLEAN_TYPE
    8533    373786126 :       && ARITHMETIC_TYPE_P (totype)
    8534    791467227 :       && null_node_p (expr))
    8535              :     {
    8536           94 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8537           94 :       if (fn)
    8538              :         {
    8539           33 :           auto_diagnostic_group d;
    8540           33 :           if (warning_at (loc, OPT_Wconversion_null,
    8541              :                           "passing NULL to non-pointer argument %P of %qD",
    8542              :                           argnum, fn))
    8543           27 :             inform (get_fndecl_argument_location (fn, argnum),
    8544              :                     "declared here");
    8545           33 :         }
    8546              :       else
    8547           61 :         warning_at (loc, OPT_Wconversion_null,
    8548              :                     "converting to non-pointer type %qT from NULL", totype);
    8549              :     }
    8550              : 
    8551              :   /* Issue warnings if "false" is converted to a NULL pointer */
    8552    596999761 :   else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
    8553    596999761 :            && TYPE_PTR_P (totype))
    8554              :     {
    8555            7 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8556            7 :       if (fn)
    8557              :         {
    8558            3 :           auto_diagnostic_group d;
    8559            3 :           if (warning_at (loc, OPT_Wconversion_null,
    8560              :                           "converting %<false%> to pointer type for argument "
    8561              :                           "%P of %qD", argnum, fn))
    8562            3 :             inform (get_fndecl_argument_location (fn, argnum),
    8563              :                     "declared here");
    8564            3 :         }
    8565              :       else
    8566            4 :         warning_at (loc, OPT_Wconversion_null,
    8567              :                     "converting %<false%> to pointer type %qT", totype);
    8568              :     }
    8569              :   /* Handle zero as null pointer warnings for cases other
    8570              :      than EQ_EXPR and NE_EXPR */
    8571    545918102 :   else if ((TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype))
    8572    597308797 :            && null_ptr_cst_p (expr))
    8573              :     {
    8574      2419110 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8575      2419110 :       maybe_warn_zero_as_null_pointer_constant (expr, loc);
    8576              :     }
    8577    596999855 : }
    8578              : 
    8579              : /* We gave a diagnostic during a conversion.  If this was in the second
    8580              :    standard conversion sequence of a user-defined conversion sequence, say
    8581              :    which user-defined conversion.  */
    8582              : 
    8583              : static void
    8584         5216 : maybe_print_user_conv_context (conversion *convs)
    8585              : {
    8586         5216 :   if (convs->user_conv_p)
    8587          164 :     for (conversion *t = convs; t; t = next_conversion (t))
    8588          140 :       if (t->kind == ck_user)
    8589              :         {
    8590           43 :           print_z_candidate (0, N_("  after user-defined conversion:"),
    8591              :                              t->cand);
    8592           43 :           break;
    8593              :         }
    8594         5216 : }
    8595              : 
    8596              : /* Locate the parameter with the given index within FNDECL.
    8597              :    ARGNUM is zero based, -1 indicates the `this' argument of a method.
    8598              :    Return the location of the FNDECL itself if there are problems.  */
    8599              : 
    8600              : location_t
    8601      8490654 : get_fndecl_argument_location (tree fndecl, int argnum)
    8602              : {
    8603              :   /* The locations of implicitly-declared functions are likely to be
    8604              :      more meaningful than those of their parameters.  */
    8605      8490654 :   if (DECL_ARTIFICIAL (fndecl))
    8606          297 :     return DECL_SOURCE_LOCATION (fndecl);
    8607              : 
    8608      8490357 :   if (argnum == -1)
    8609           49 :     return DECL_SOURCE_LOCATION (fndecl);
    8610              : 
    8611      8490308 :   int i;
    8612      8490308 :   tree param;
    8613              : 
    8614              :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8615      8490308 :   for (i = 0, param = FUNCTION_FIRST_USER_PARM (fndecl);
    8616     21307063 :        i < argnum && param;
    8617     12816755 :        i++, param = TREE_CHAIN (param))
    8618              :     ;
    8619              : 
    8620              :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    8621              :      return the location of FNDECL.  */
    8622      8490308 :   if (param == NULL)
    8623           28 :     return DECL_SOURCE_LOCATION (fndecl);
    8624              : 
    8625      8490280 :   return DECL_SOURCE_LOCATION (param);
    8626              : }
    8627              : 
    8628              : /* If FNDECL is non-NULL, issue a note highlighting ARGNUM
    8629              :    within its declaration (or the fndecl itself if something went
    8630              :    wrong).  */
    8631              : 
    8632              : void
    8633         6926 : maybe_inform_about_fndecl_for_bogus_argument_init (tree fn, int argnum,
    8634              :                                                    const char *highlight_color)
    8635              : {
    8636         6926 :   if (fn)
    8637              :     {
    8638         1098 :       gcc_rich_location richloc (get_fndecl_argument_location (fn, argnum));
    8639         1098 :       richloc.set_highlight_color (highlight_color);
    8640         1098 :       inform (&richloc,
    8641              :               "initializing argument %P of %qD", argnum, fn);
    8642         1098 :     }
    8643         6926 : }
    8644              : 
    8645              : /* Maybe warn about C++20 Conversions to arrays of unknown bound.  C is
    8646              :    the conversion, EXPR is the expression we're converting.  */
    8647              : 
    8648              : static void
    8649     50383999 : maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
    8650              : {
    8651     50383999 :   if (cxx_dialect >= cxx20)
    8652              :     return;
    8653              : 
    8654       419361 :   tree type = TREE_TYPE (expr);
    8655       419361 :   type = strip_pointer_operator (type);
    8656              : 
    8657       419361 :   if (TREE_CODE (type) != ARRAY_TYPE
    8658       419361 :       || TYPE_DOMAIN (type) == NULL_TREE)
    8659              :     return;
    8660              : 
    8661         1848 :   if (pedantic && conv_binds_to_array_of_unknown_bound (c))
    8662           10 :     pedwarn (loc, OPT_Wc__20_extensions,
    8663              :              "conversions to arrays of unknown bound "
    8664              :              "are only available with %<-std=c++20%> or %<-std=gnu++20%>");
    8665              : }
    8666              : 
    8667              : /* We call this recursively in convert_like_internal.  */
    8668              : static tree convert_like (conversion *, tree, tree, int, bool, bool, bool,
    8669              :                           tsubst_flags_t);
    8670              : 
    8671              : /* Adjust the result EXPR of a conversion to the expected type TOTYPE, which
    8672              :    must be equivalent but might be a typedef.  */
    8673              : 
    8674              : static tree
    8675   1017168317 : maybe_adjust_type_name (tree type, tree expr, conversion_kind kind)
    8676              : {
    8677   1017168317 :   if (expr == error_mark_node
    8678   1017168266 :       || processing_template_decl)
    8679              :     return expr;
    8680              : 
    8681    912508759 :   tree etype = TREE_TYPE (expr);
    8682    912508759 :   if (etype == type)
    8683              :     return expr;
    8684              : 
    8685    129603819 :   gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p (etype, type)
    8686              :                        || is_bitfield_expr_with_lowered_type (expr)
    8687              :                        || seen_error ());
    8688              : 
    8689    126873052 :   if (SCALAR_TYPE_P (type)
    8690    250286006 :       && (kind == ck_rvalue
    8691              :           /* ??? We should be able to do this for ck_identity of more prvalue
    8692              :              expressions, but checking !obvalue_p here breaks, so for now let's
    8693              :              just handle NON_LVALUE_EXPR (such as the location wrapper for a
    8694              :              literal).  Maybe we want to express already-rvalue in the
    8695              :              conversion somehow?  */
    8696    110531450 :           || TREE_CODE (expr) == NON_LVALUE_EXPR))
    8697     14382553 :     expr = build_nop (type, expr);
    8698              : 
    8699              :   return expr;
    8700              : }
    8701              : 
    8702              : /* Perform the conversions in CONVS on the expression EXPR.  FN and
    8703              :    ARGNUM are used for diagnostics.  ARGNUM is zero based, -1
    8704              :    indicates the `this' argument of a method.  INNER is nonzero when
    8705              :    being called to continue a conversion chain. It is negative when a
    8706              :    reference binding will be applied, positive otherwise.  If
    8707              :    ISSUE_CONVERSION_WARNINGS is true, warnings about suspicious
    8708              :    conversions will be emitted if appropriate.  If C_CAST_P is true,
    8709              :    this conversion is coming from a C-style cast; in that case,
    8710              :    conversions to inaccessible bases are permitted.  */
    8711              : 
    8712              : static tree
    8713   1255666966 : convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
    8714              :                        bool issue_conversion_warnings, bool c_cast_p,
    8715              :                        bool nested_p, tsubst_flags_t complain)
    8716              : {
    8717   1255666966 :   tree totype = convs->type;
    8718   1255666966 :   enum diagnostics::kind diag_kind;
    8719   1255666966 :   int flags;
    8720   1255666966 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    8721   1255666966 :   const bool stub_object_p = is_stub_object (expr);
    8722              : 
    8723   1255666966 :   if (convs->bad_p && !(complain & tf_error))
    8724        66764 :     return error_mark_node;
    8725              : 
    8726   1255600202 :   gcc_checking_assert (!TYPE_REF_P (TREE_TYPE (expr)));
    8727              : 
    8728   1255600202 :   if (convs->bad_p
    8729         6899 :       && convs->kind != ck_user
    8730         6805 :       && convs->kind != ck_list
    8731         6799 :       && convs->kind != ck_ambig
    8732         6799 :       && (convs->kind != ck_ref_bind
    8733         5224 :           || (convs->user_conv_p && next_conversion (convs)->bad_p))
    8734         1596 :       && (convs->kind != ck_rvalue
    8735           15 :           || SCALAR_TYPE_P (totype))
    8736   1255601789 :       && convs->kind != ck_base)
    8737              :     {
    8738         1587 :       int complained = 0;
    8739         1587 :       conversion *t = convs;
    8740              : 
    8741              :       /* Give a helpful error if this is bad because of excess braces.  */
    8742           46 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8743           46 :           && SCALAR_TYPE_P (totype)
    8744           34 :           && CONSTRUCTOR_NELTS (expr) > 0
    8745         1621 :           && BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
    8746              :         {
    8747           11 :           complained = permerror (loc, "too many braces around initializer "
    8748              :                                   "for %qT", totype);
    8749           33 :           while (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8750           55 :                  && CONSTRUCTOR_NELTS (expr) == 1)
    8751           22 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    8752              :         }
    8753              : 
    8754              :       /* Give a helpful error if this is bad because a conversion to bool
    8755              :          from std::nullptr_t requires direct-initialization.  */
    8756         1587 :       if (NULLPTR_TYPE_P (TREE_TYPE (expr))
    8757         1587 :           && TREE_CODE (totype) == BOOLEAN_TYPE)
    8758           15 :         complained = permerror (loc, "converting to %qH from %qI requires "
    8759              :                                 "direct-initialization",
    8760           15 :                                 totype, TREE_TYPE (expr));
    8761              : 
    8762         1587 :       if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (expr))
    8763           72 :           && SCALAR_FLOAT_TYPE_P (totype)
    8764         1659 :           && (extended_float_type_p (TREE_TYPE (expr))
    8765           18 :               || extended_float_type_p (totype)))
    8766           72 :         switch (cp_compare_floating_point_conversion_ranks (TREE_TYPE (expr),
    8767              :                                                             totype))
    8768              :           {
    8769           69 :           case 2:
    8770           69 :             if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow "
    8771              :                          "converting to %qH from %qI with greater "
    8772           69 :                          "conversion rank", totype, TREE_TYPE (expr)))
    8773         1587 :               complained = 1;
    8774           15 :             else if (!complained)
    8775           15 :               complained = -1;
    8776              :             break;
    8777            3 :           case 3:
    8778            3 :             if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow "
    8779              :                          "converting to %qH from %qI with unordered "
    8780            3 :                          "conversion rank", totype, TREE_TYPE (expr)))
    8781              :               complained = 1;
    8782            0 :             else if (!complained)
    8783           15 :               complained = -1;
    8784              :             break;
    8785              :           default:
    8786              :             break;
    8787              :           }
    8788              : 
    8789         3190 :       for (; t ; t = next_conversion (t))
    8790              :         {
    8791         3181 :           if (t->kind == ck_user && t->cand->reason)
    8792              :             {
    8793           52 :               auto_diagnostic_group d;
    8794           52 :               complained = permerror (loc, "invalid user-defined conversion "
    8795           52 :                                       "from %qH to %qI", TREE_TYPE (expr),
    8796              :                                       totype);
    8797           52 :               if (complained)
    8798              :                 {
    8799           52 :                   auto_diagnostic_nesting_level sentinel;
    8800           52 :                   print_z_candidate (loc, N_("candidate is:"), t->cand);
    8801           52 :                 }
    8802           52 :               expr = convert_like (t, expr, fn, argnum,
    8803              :                                    /*issue_conversion_warnings=*/false,
    8804              :                                    /*c_cast_p=*/false, /*nested_p=*/true,
    8805              :                                    complain);
    8806           52 :               break;
    8807           52 :             }
    8808         3129 :           else if (t->kind == ck_user || !t->bad_p)
    8809              :             {
    8810         1526 :               expr = convert_like (t, expr, fn, argnum,
    8811              :                                    /*issue_conversion_warnings=*/false,
    8812              :                                    /*c_cast_p=*/false, /*nested_p=*/true,
    8813              :                                    complain);
    8814         1526 :               if (t->bad_p)
    8815            0 :                 complained = 1;
    8816              :               break;
    8817              :             }
    8818         1603 :           else if (t->kind == ck_ambig)
    8819            0 :             return convert_like (t, expr, fn, argnum,
    8820              :                                  /*issue_conversion_warnings=*/false,
    8821              :                                  /*c_cast_p=*/false, /*nested_p=*/true,
    8822            0 :                                  complain);
    8823         1603 :           else if (t->kind == ck_identity)
    8824              :             break;
    8825              :         }
    8826         1587 :       if (!complained && stub_object_p)
    8827              :         {
    8828              :           /* An error diagnosed within a trait, don't give extra labels.  */
    8829           12 :           error_at (loc, "invalid conversion from %qH to %qI",
    8830            6 :                     TREE_TYPE (expr), totype);
    8831            6 :           complained = 1;
    8832              :         }
    8833         1581 :       else if (!complained && expr != error_mark_node)
    8834              :         {
    8835         1429 :           range_label_for_type_mismatch label (TREE_TYPE (expr), totype);
    8836         1429 :           gcc_rich_location richloc (loc, &label, highlight_colors::percent_h);
    8837         1429 :           complained = permerror (&richloc,
    8838              :                                   "invalid conversion from %qH to %qI",
    8839         1429 :                                   TREE_TYPE (expr), totype);
    8840         1429 :           if (complained)
    8841         1374 :             maybe_emit_indirection_note (loc, expr, totype);
    8842         1429 :         }
    8843         1587 :       if (convs->kind == ck_ref_bind)
    8844           21 :         expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
    8845              :                                      LOOKUP_NORMAL, NULL_TREE,
    8846              :                                      complain);
    8847              :       else
    8848         1566 :         expr = cp_convert (totype, expr, complain);
    8849         1587 :       if (complained == 1)
    8850         1515 :         maybe_inform_about_fndecl_for_bogus_argument_init
    8851         1515 :           (fn, argnum, highlight_colors::percent_i);
    8852         1587 :       return expr;
    8853              :     }
    8854              : 
    8855   1255598615 :   if (issue_conversion_warnings && (complain & tf_warning))
    8856    596999855 :     conversion_null_warnings (totype, expr, fn, argnum);
    8857              : 
    8858   1255598615 :   switch (convs->kind)
    8859              :     {
    8860      7958282 :     case ck_user:
    8861      7958282 :       {
    8862      7958282 :         struct z_candidate *cand = convs->cand;
    8863              : 
    8864      7958282 :         if (cand == NULL)
    8865              :           /* We chose the surrogate function from add_conv_candidate, now we
    8866              :              actually need to build the conversion.  */
    8867           64 :           cand = build_user_type_conversion_1 (totype, expr,
    8868              :                                                LOOKUP_NO_CONVERSION, complain);
    8869              : 
    8870      7958282 :         tree convfn = cand->fn;
    8871              : 
    8872              :         /* When converting from an init list we consider explicit
    8873              :            constructors, but actually trying to call one is an error.  */
    8874      8516719 :         if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
    8875         9659 :             && BRACE_ENCLOSED_INITIALIZER_P (expr)
    8876              :             /* Unless this is for direct-list-initialization.  */
    8877         9656 :             && (!CONSTRUCTOR_IS_DIRECT_INIT (expr) || convs->need_temporary_p)
    8878              :             /* And in C++98 a default constructor can't be explicit.  */
    8879      7958519 :             && cxx_dialect >= cxx11)
    8880              :           {
    8881          236 :             if (!(complain & tf_error))
    8882           53 :               return error_mark_node;
    8883          183 :             location_t loc = location_of (expr);
    8884          183 :             if (CONSTRUCTOR_NELTS (expr) == 0
    8885          183 :                 && FUNCTION_FIRST_USER_PARMTYPE (convfn) != void_list_node)
    8886              :               {
    8887            7 :                 auto_diagnostic_group d;
    8888            7 :                 if (pedwarn (loc, 0, "converting to %qT from initializer list "
    8889              :                              "would use explicit constructor %qD",
    8890              :                              totype, convfn))
    8891              :                   {
    8892            7 :                     inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8893              :                             convfn);
    8894            7 :                     inform (loc, "in C++11 and above a default constructor "
    8895              :                             "can be explicit");
    8896              :                   }
    8897            7 :               }
    8898              :             else
    8899              :               {
    8900          176 :                 auto_diagnostic_group d;
    8901          176 :                 error ("converting to %qT from initializer list would use "
    8902              :                        "explicit constructor %qD", totype, convfn);
    8903          176 :                 inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8904              :                         convfn);
    8905          176 :               }
    8906              :           }
    8907              : 
    8908              :         /* If we're initializing from {}, it's value-initialization.  */
    8909       997354 :         if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8910       997346 :             && CONSTRUCTOR_NELTS (expr) == 0
    8911       180701 :             && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)
    8912      8138903 :             && !processing_template_decl)
    8913              :           {
    8914       180674 :             if (abstract_virtuals_error (NULL_TREE, totype, complain))
    8915           15 :               return error_mark_node;
    8916       180659 :             expr = build_value_init (totype, complain);
    8917       180659 :             expr = get_target_expr (expr, complain);
    8918       180659 :             if (expr != error_mark_node)
    8919       180519 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8920       180659 :             return expr;
    8921              :           }
    8922              : 
    8923              :         /* We don't know here whether EXPR is being used as an lvalue or
    8924              :            rvalue, but we know it's read.  */
    8925      7777555 :         mark_exp_read (expr);
    8926              : 
    8927              :         /* Give the conversion call the location of EXPR rather than the
    8928              :            location of the context that caused the conversion.  */
    8929      7777555 :         iloc_sentinel ils (loc);
    8930              : 
    8931              :         /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow
    8932              :            any more UDCs.  */
    8933      7777555 :         expr = build_over_call (cand, LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
    8934              :                                 complain);
    8935              : 
    8936              :         /* If this is a constructor or a function returning an aggr type,
    8937              :            we need to build up a TARGET_EXPR.  */
    8938     15555110 :         if (DECL_CONSTRUCTOR_P (convfn))
    8939              :           {
    8940      3882468 :             expr = build_cplus_new (totype, expr, complain);
    8941              : 
    8942              :             /* Remember that this was list-initialization.  */
    8943      3882468 :             if (convs->check_narrowing && expr != error_mark_node)
    8944       840825 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8945              :           }
    8946              : 
    8947      7777555 :         return expr;
    8948      7777555 :       }
    8949    864723462 :     case ck_identity:
    8950    864723462 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    8951              :         {
    8952      1247579 :           int nelts = CONSTRUCTOR_NELTS (expr);
    8953       209630 :           if (nelts == 0)
    8954      1037949 :             expr = build_value_init (totype, complain);
    8955       209630 :           else if (nelts == 1)
    8956       209630 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    8957              :           else
    8958            0 :             gcc_unreachable ();
    8959              :         }
    8960    864723462 :       expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p,
    8961              :                        /*read_p=*/true, UNKNOWN_LOCATION,
    8962              :                        /*reject_builtin=*/true);
    8963              : 
    8964    864723462 :       if (type_unknown_p (expr))
    8965        17418 :         expr = instantiate_type (totype, expr, complain);
    8966    864723462 :       if (!nested_p && TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    8967        49121 :         expr = cp_convert (totype, TREE_OPERAND (expr, 0), complain);
    8968    864723462 :       if (expr == null_node
    8969    864723462 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype))
    8970              :         /* If __null has been converted to an integer type, we do not want to
    8971              :            continue to warn about uses of EXPR as an integer, rather than as a
    8972              :            pointer.  */
    8973       145239 :         expr = build_int_cst (totype, 0);
    8974    864723462 :       return maybe_adjust_type_name (totype, expr, convs->kind);
    8975           47 :     case ck_ambig:
    8976              :       /* We leave bad_p off ck_ambig because overload resolution considers
    8977              :          it valid, it just fails when we try to perform it.  So we need to
    8978              :          check complain here, too.  */
    8979           47 :       if (complain & tf_error)
    8980              :         {
    8981              :           /* Call build_user_type_conversion again for the error.  */
    8982            3 :           int flags = (convs->need_temporary_p
    8983           47 :                        ? LOOKUP_IMPLICIT : LOOKUP_NORMAL);
    8984           47 :           build_user_type_conversion (totype, convs->u.expr, flags, complain);
    8985           47 :           gcc_assert (seen_error ());
    8986           47 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    8987              :         }
    8988           47 :       return error_mark_node;
    8989              : 
    8990         9713 :     case ck_list:
    8991         9713 :       {
    8992              :         /* Conversion to std::initializer_list<T>.  */
    8993         9713 :         tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (totype), 0);
    8994         9713 :         unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (expr);
    8995         9713 :         tree array;
    8996              : 
    8997         9713 :         if (tree init = maybe_init_list_as_array (elttype, expr))
    8998              :           {
    8999          132 :             elttype
    9000          132 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    9001              :                                                    | TYPE_QUAL_CONST));
    9002          132 :             tree index_type = TYPE_DOMAIN (TREE_TYPE (init));
    9003          132 :             array = build_cplus_array_type (elttype, index_type);
    9004          132 :             len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (index_type)) + 1;
    9005          132 :             array = build_vec_init_expr (array, init, complain);
    9006          132 :             array = get_target_expr (array);
    9007          132 :             array = cp_build_addr_expr (array, complain);
    9008              :           }
    9009         9581 :         else if (len)
    9010              :           {
    9011         9200 :             tree val;
    9012         9200 :             unsigned ix;
    9013         9200 :             tree new_ctor = build_constructor (init_list_type_node, NULL);
    9014              : 
    9015              :             /* Convert all the elements.  */
    9016        68614 :             FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val)
    9017              :               {
    9018        59429 :                 if (TREE_CODE (val) == RAW_DATA_CST)
    9019              :                   {
    9020              :                     /* For conversion to initializer_list<unsigned char> or
    9021              :                        initializer_list<char> or initializer_list<signed char>
    9022              :                        we can optimize and keep RAW_DATA_CST with adjusted
    9023              :                        type if we report narrowing errors if needed, for
    9024              :                        others this converts each element separately.  */
    9025           48 :                     if (convs->u.list[ix]->kind == ck_std)
    9026              :                       {
    9027           18 :                         tree et = convs->u.list[ix]->type;
    9028           18 :                         conversion *next = next_conversion (convs->u.list[ix]);
    9029           18 :                         gcc_assert (et
    9030              :                                     && (TREE_CODE (et) == INTEGER_TYPE
    9031              :                                         || is_byte_access_type (et))
    9032              :                                     && TYPE_PRECISION (et) == CHAR_BIT
    9033              :                                     && next
    9034              :                                     && next->kind == ck_identity);
    9035           18 :                         if (!TYPE_UNSIGNED (et)
    9036              :                             /* For RAW_DATA_CST, TREE_TYPE (val) can be
    9037              :                                either integer_type_node (when it has been
    9038              :                                created by the lexer from CPP_EMBED) or
    9039              :                                after digestion/conversion some integral
    9040              :                                type with CHAR_BIT precision.  For int with
    9041              :                                precision higher than CHAR_BIT or unsigned char
    9042              :                                diagnose narrowing conversions from
    9043              :                                that int/unsigned char to signed char if any
    9044              :                                byte has most significant bit set.  */
    9045           18 :                             && (TYPE_UNSIGNED (TREE_TYPE (val))
    9046           12 :                                 || (TYPE_PRECISION (TREE_TYPE (val))
    9047              :                                     > CHAR_BIT)))
    9048         2460 :                           for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
    9049              :                             {
    9050         2454 :                               if (RAW_DATA_SCHAR_ELT (val, i) >= 0)
    9051         2448 :                                 continue;
    9052            6 :                               else if (complain & tf_error)
    9053              :                                 {
    9054            6 :                                   location_t loc
    9055            6 :                                     = cp_expr_loc_or_input_loc (val);
    9056            6 :                                   int savederrorcount = errorcount;
    9057           18 :                                   permerror_opt (loc, OPT_Wnarrowing,
    9058              :                                                  "narrowing conversion of "
    9059              :                                                  "%qd from %qH to %qI",
    9060            6 :                                                  RAW_DATA_UCHAR_ELT (val, i),
    9061            6 :                                                  TREE_TYPE (val), et);
    9062            6 :                                   if (errorcount != savederrorcount)
    9063            6 :                                     return error_mark_node;
    9064              :                                 }
    9065              :                               else
    9066            0 :                                 return error_mark_node;
    9067              :                             }
    9068           12 :                         tree sub = copy_node (val);
    9069           12 :                         TREE_TYPE (sub) = et;
    9070           12 :                         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    9071              :                                                 NULL_TREE, sub);
    9072              :                       }
    9073              :                     else
    9074              :                       {
    9075           30 :                         conversion *conv = convs->u.list[ix];
    9076           30 :                         gcc_assert (conv->kind == ck_list);
    9077        15495 :                         for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
    9078              :                           {
    9079        15465 :                             tree elt
    9080        15465 :                               = build_int_cst (TREE_TYPE (val),
    9081        15465 :                                                RAW_DATA_UCHAR_ELT (val, i));
    9082        15465 :                             tree sub
    9083        15465 :                               = convert_like (conv->u.list[i], elt,
    9084              :                                               fn, argnum, false, false,
    9085              :                                               /*nested_p=*/true, complain);
    9086        15465 :                             if (sub == error_mark_node)
    9087              :                               return sub;
    9088        15465 :                             if (!check_narrowing (TREE_TYPE (sub), elt,
    9089              :                                                   complain))
    9090            0 :                               return error_mark_node;
    9091        15465 :                             tree nc = new_ctor;
    9092        15465 :                             CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (nc),
    9093              :                                                     NULL_TREE, sub);
    9094        15465 :                             if (!TREE_CONSTANT (sub))
    9095        11679 :                               TREE_CONSTANT (new_ctor) = false;
    9096              :                           }
    9097              :                       }
    9098           42 :                     len += RAW_DATA_LENGTH (val) - 1;
    9099           42 :                     continue;
    9100           42 :                   }
    9101        59381 :                 tree sub = convert_like (convs->u.list[ix], val, fn,
    9102              :                                          argnum, false, false,
    9103              :                                          /*nested_p=*/true, complain);
    9104        59381 :                 if (sub == error_mark_node)
    9105              :                   return sub;
    9106         1501 :                 if (!BRACE_ENCLOSED_INITIALIZER_P (val)
    9107        59392 :                     && !check_narrowing (TREE_TYPE (sub), val, complain))
    9108            0 :                   return error_mark_node;
    9109        59372 :                 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    9110              :                                         NULL_TREE, sub);
    9111        59372 :                 if (!TREE_CONSTANT (sub))
    9112        10410 :                   TREE_CONSTANT (new_ctor) = false;
    9113              :               }
    9114              :             /* Build up the array.  */
    9115         9185 :             elttype
    9116         9185 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    9117              :                                                    | TYPE_QUAL_CONST));
    9118         9185 :             array = build_array_of_n_type (elttype, len);
    9119         9185 :             array = finish_compound_literal (array, new_ctor, complain);
    9120              :             /* This is dubious now, should be blessed by P2752.  */
    9121         9185 :             DECL_MERGEABLE (TARGET_EXPR_SLOT (array)) = true;
    9122         9185 :             array = cp_build_addr_expr (array, complain);
    9123              :           }
    9124              :         else
    9125          381 :           array = nullptr_node;
    9126              : 
    9127         9698 :         array = cp_convert (build_pointer_type (elttype), array, complain);
    9128         9698 :         if (array == error_mark_node)
    9129              :           return error_mark_node;
    9130              : 
    9131              :         /* Build up the initializer_list object.  Note: fail gracefully
    9132              :            if the object cannot be completed because, for example, no
    9133              :            definition is provided (c++/80956).  */
    9134         9698 :         totype = complete_type_or_maybe_complain (totype, NULL_TREE, complain);
    9135         9698 :         if (!totype)
    9136            0 :           return error_mark_node;
    9137         9698 :         tree field = next_aggregate_field (TYPE_FIELDS (totype));
    9138         9698 :         vec<constructor_elt, va_gc> *vec = NULL;
    9139         9698 :         CONSTRUCTOR_APPEND_ELT (vec, field, array);
    9140         9698 :         field = next_aggregate_field (DECL_CHAIN (field));
    9141         9698 :         CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len));
    9142         9698 :         tree new_ctor = build_constructor (totype, vec);
    9143         9698 :         return get_target_expr (new_ctor, complain);
    9144              :       }
    9145              : 
    9146      1282839 :     case ck_aggr:
    9147      1282839 :       if (TREE_CODE (totype) == COMPLEX_TYPE)
    9148              :         {
    9149        27183 :           tree real = CONSTRUCTOR_ELT (expr, 0)->value;
    9150        27183 :           tree imag = CONSTRUCTOR_ELT (expr, 1)->value;
    9151        27183 :           real = perform_implicit_conversion (TREE_TYPE (totype),
    9152              :                                               real, complain);
    9153        27183 :           imag = perform_implicit_conversion (TREE_TYPE (totype),
    9154              :                                               imag, complain);
    9155        27183 :           expr = build2 (COMPLEX_EXPR, totype, real, imag);
    9156        27183 :           return expr;
    9157              :         }
    9158      1255656 :       expr = reshape_init (totype, expr, complain);
    9159      1255656 :       expr = get_target_expr (digest_init (totype, expr, complain),
    9160              :                                      complain);
    9161      1255656 :       if (expr != error_mark_node)
    9162      1255645 :         TARGET_EXPR_LIST_INIT_P (expr) = true;
    9163              :       return expr;
    9164              : 
    9165    381624272 :     default:
    9166    381624272 :       break;
    9167    381624272 :     };
    9168              : 
    9169    381624272 :   conversion *nc = next_conversion (convs);
    9170    381624272 :   if (convs->kind == ck_ref_bind && nc->kind == ck_qual
    9171        25108 :       && !convs->need_temporary_p)
    9172              :     /* direct_reference_binding might have inserted a ck_qual under
    9173              :        this ck_ref_bind for the benefit of conversion sequence ranking.
    9174              :        Don't actually perform that conversion.  */
    9175        23309 :     nc = next_conversion (nc);
    9176              : 
    9177    381624272 :   expr = convert_like (nc, expr, fn, argnum,
    9178              :                        convs->kind == ck_ref_bind
    9179    381624272 :                        ? issue_conversion_warnings : false,
    9180              :                        c_cast_p, /*nested_p=*/true, complain & ~tf_no_cleanup);
    9181    381624272 :   if (expr == error_mark_node)
    9182              :     return error_mark_node;
    9183              : 
    9184    381623799 :   switch (convs->kind)
    9185              :     {
    9186    172013490 :     case ck_rvalue:
    9187    172013490 :       expr = decay_conversion (expr, complain);
    9188    172013490 :       if (expr == error_mark_node)
    9189              :         {
    9190           15 :           if (complain & tf_error)
    9191              :             {
    9192           12 :               auto_diagnostic_group d;
    9193           12 :               maybe_print_user_conv_context (convs);
    9194           12 :               maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9195           12 :             }
    9196           15 :           return error_mark_node;
    9197              :         }
    9198              : 
    9199    172013475 :       if ((complain & tf_warning) && fn
    9200     50489525 :           && warn_suggest_attribute_format)
    9201              :         {
    9202          706 :           tree rhstype = TREE_TYPE (expr);
    9203          706 :           const enum tree_code coder = TREE_CODE (rhstype);
    9204          706 :           const enum tree_code codel = TREE_CODE (totype);
    9205          706 :           if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    9206          250 :               && coder == codel
    9207          956 :               && check_missing_format_attribute (totype, rhstype))
    9208            6 :             warning (OPT_Wsuggest_attribute_format,
    9209              :                      "argument of function call might be a candidate "
    9210              :                      "for a format attribute");
    9211              :         }
    9212              : 
    9213    172013475 :       if (! MAYBE_CLASS_TYPE_P (totype))
    9214    152444855 :         return maybe_adjust_type_name (totype, expr, convs->kind);
    9215              : 
    9216              :       /* Don't introduce copies when passing arguments along to the inherited
    9217              :          constructor.  */
    9218     19568620 :       if (current_function_decl
    9219     16064734 :           && flag_new_inheriting_ctors
    9220     51697608 :           && DECL_INHERITED_CTOR (current_function_decl))
    9221              :         return expr;
    9222              : 
    9223     19548496 :       if (TREE_CODE (expr) == TARGET_EXPR
    9224     19548496 :           && TARGET_EXPR_LIST_INIT_P (expr))
    9225              :         /* Copy-list-initialization doesn't actually involve a copy.  */
    9226              :         return expr;
    9227              : 
    9228              :       /* Fall through.  */
    9229     21756468 :     case ck_base:
    9230     21756468 :       if (convs->kind == ck_base && !convs->need_temporary_p)
    9231              :         {
    9232              :           /* We are going to bind a reference directly to a base-class
    9233              :              subobject of EXPR.  */
    9234              :           /* Build an expression for `*((base*) &expr)'.  */
    9235      2003355 :           expr = convert_to_base (expr, totype,
    9236      2003355 :                                   !c_cast_p, /*nonnull=*/true, complain);
    9237      2003355 :           return expr;
    9238              :         }
    9239              : 
    9240              :       /* Copy-initialization where the cv-unqualified version of the source
    9241              :          type is the same class as, or a derived class of, the class of the
    9242              :          destination [is treated as direct-initialization].  [dcl.init] */
    9243     19753113 :       flags = LOOKUP_NORMAL;
    9244              :       /* This conversion is being done in the context of a user-defined
    9245              :          conversion (i.e. the second step of copy-initialization), so
    9246              :          don't allow any more.  */
    9247     19753113 :       if (convs->user_conv_p)
    9248       256395 :         flags |= LOOKUP_NO_CONVERSION;
    9249              :       /* We might be performing a conversion of the argument
    9250              :          to the user-defined conversion, i.e., not a conversion of the
    9251              :          result of the user-defined conversion.  In which case we skip
    9252              :          explicit constructors.  */
    9253     19753113 :       if (convs->copy_init_p)
    9254     19486950 :         flags |= LOOKUP_ONLYCONVERTING;
    9255     19753113 :       expr = build_temp (expr, totype, flags, &diag_kind, complain);
    9256     19753113 :       if (diag_kind != diagnostics::kind::unspecified && complain)
    9257              :         {
    9258           77 :           auto_diagnostic_group d;
    9259           77 :           maybe_print_user_conv_context (convs);
    9260           77 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9261           77 :         }
    9262              : 
    9263     19753113 :       return build_cplus_new (totype, expr, complain);
    9264              : 
    9265     88712632 :     case ck_ref_bind:
    9266     88712632 :       {
    9267     88712632 :         tree ref_type = totype;
    9268              : 
    9269     88712632 :         if (convs->bad_p && !next_conversion (convs)->bad_p)
    9270              :           {
    9271         5127 :             tree extype = TREE_TYPE (expr);
    9272         5127 :             auto_diagnostic_group d;
    9273         5127 :             if (TYPE_REF_IS_RVALUE (ref_type)
    9274         5127 :                 && lvalue_p (expr))
    9275         1638 :               error_at (loc, "cannot bind rvalue reference of type %qH to "
    9276              :                         "lvalue of type %qI", totype, extype);
    9277         6132 :             else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr)
    9278         4953 :                      && !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type)))
    9279              :               {
    9280         1215 :                 conversion *next = next_conversion (convs);
    9281         1215 :                 if (next->kind == ck_std)
    9282              :                   {
    9283           59 :                     next = next_conversion (next);
    9284           59 :                     error_at (loc, "cannot bind non-const lvalue reference of "
    9285              :                               "type %qH to a value of type %qI",
    9286              :                               totype, next->type);
    9287              :                   }
    9288         1156 :                 else if (!CP_TYPE_CONST_P (TREE_TYPE (ref_type)))
    9289          815 :                   error_at (loc, "cannot bind non-const lvalue reference of "
    9290              :                             "type %qH to an rvalue of type %qI", totype, extype);
    9291              :                 else // extype is volatile
    9292          341 :                   error_at (loc, "cannot bind lvalue reference of type "
    9293              :                             "%qH to an rvalue of type %qI", totype,
    9294              :                             extype);
    9295              :               }
    9296         2274 :             else if (!reference_compatible_p (TREE_TYPE (totype), extype))
    9297              :               {
    9298              :                 /* If we're converting from T[] to T[N], don't talk
    9299              :                    about discarding qualifiers.  (Converting from T[N] to
    9300              :                    T[] is allowed by P0388R4.)  */
    9301         2274 :                 if (TREE_CODE (extype) == ARRAY_TYPE
    9302           27 :                     && TYPE_DOMAIN (extype) == NULL_TREE
    9303           15 :                     && TREE_CODE (TREE_TYPE (totype)) == ARRAY_TYPE
    9304         2289 :                     && TYPE_DOMAIN (TREE_TYPE (totype)) != NULL_TREE)
    9305           15 :                   error_at (loc, "cannot bind reference of type %qH to %qI "
    9306              :                             "due to different array bounds", totype, extype);
    9307              :                 else
    9308         2259 :                   error_at (loc, "binding reference of type %qH to %qI "
    9309              :                             "discards qualifiers", totype, extype);
    9310              :               }
    9311              :             else
    9312            0 :               gcc_unreachable ();
    9313         5127 :             maybe_print_user_conv_context (convs);
    9314         5127 :             maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9315              : 
    9316         5127 :             return error_mark_node;
    9317         5127 :           }
    9318     88707505 :         else if (complain & tf_warning)
    9319     48499058 :           maybe_warn_array_conv (loc, convs, expr);
    9320              : 
    9321              :         /* If necessary, create a temporary.
    9322              : 
    9323              :            VA_ARG_EXPR and CONSTRUCTOR expressions are special cases
    9324              :            that need temporaries, even when their types are reference
    9325              :            compatible with the type of reference being bound, so the
    9326              :            upcoming call to cp_build_addr_expr doesn't fail.  */
    9327     88707505 :         if (convs->need_temporary_p
    9328     85660638 :             || TREE_CODE (expr) == CONSTRUCTOR
    9329     85660555 :             || TREE_CODE (expr) == VA_ARG_EXPR)
    9330              :           {
    9331              :             /* Otherwise, a temporary of type "cv1 T1" is created and
    9332              :                initialized from the initializer expression using the rules
    9333              :                for a non-reference copy-initialization (8.5).  */
    9334              : 
    9335      3046950 :             tree type = TREE_TYPE (ref_type);
    9336      3046950 :             cp_lvalue_kind lvalue = lvalue_kind (expr);
    9337              : 
    9338      3046950 :             gcc_assert (similar_type_p (type, next_conversion (convs)->type));
    9339      3046950 :             if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
    9340      3937029 :                 && !TYPE_REF_IS_RVALUE (ref_type))
    9341              :               {
    9342              :                 /* If the reference is volatile or non-const, we
    9343              :                    cannot create a temporary.  */
    9344          105 :                 if (complain & tf_error)
    9345              :                   {
    9346          103 :                     if (lvalue & clk_bitfield)
    9347           30 :                       error_at (loc, "cannot bind bit-field %qE to %qT",
    9348              :                                 expr, ref_type);
    9349           73 :                     else if (lvalue & clk_packed)
    9350            9 :                       error_at (loc, "cannot bind packed field %qE to %qT",
    9351              :                                 expr, ref_type);
    9352              :                     else
    9353           64 :                       error_at (loc, "cannot bind rvalue %qE to %qT",
    9354              :                                 expr, ref_type);
    9355              :                   }
    9356          105 :                 return error_mark_node;
    9357              :               }
    9358              :             /* If the source is a packed field, and we must use a copy
    9359              :                constructor, then building the target expr will require
    9360              :                binding the field to the reference parameter to the
    9361              :                copy constructor, and we'll end up with an infinite
    9362              :                loop.  If we can use a bitwise copy, then we'll be
    9363              :                OK.  */
    9364      3046845 :             if ((lvalue & clk_packed)
    9365           20 :                 && CLASS_TYPE_P (type)
    9366      3046862 :                 && type_has_nontrivial_copy_init (type))
    9367              :               {
    9368            6 :                 error_at (loc, "cannot bind packed field %qE to %qT",
    9369              :                           expr, ref_type);
    9370            6 :                 return error_mark_node;
    9371              :               }
    9372      3046839 :             if (lvalue & clk_bitfield)
    9373              :               {
    9374           24 :                 expr = convert_bitfield_to_declared_type (expr);
    9375           24 :                 expr = fold_convert (type, expr);
    9376              :               }
    9377              : 
    9378              :             /* Creating &TARGET_EXPR<> in a template would break when
    9379              :                tsubsting the expression, so use an IMPLICIT_CONV_EXPR
    9380              :                instead.  This can happen even when there's no class
    9381              :                involved, e.g., when converting an integer to a reference
    9382              :                type.  */
    9383      3046839 :             if (processing_template_decl)
    9384         9215 :               return build1 (IMPLICIT_CONV_EXPR, totype, expr);
    9385      3037624 :             expr = build_target_expr_with_type (expr, type, complain);
    9386              :           }
    9387              : 
    9388              :         /* Take the address of the thing to which we will bind the
    9389              :            reference.  */
    9390     88698179 :         expr = cp_build_addr_expr (expr, complain);
    9391     88698179 :         if (expr == error_mark_node)
    9392              :           return error_mark_node;
    9393              : 
    9394              :         /* Convert it to a pointer to the type referred to by the
    9395              :            reference.  This will adjust the pointer if a derived to
    9396              :            base conversion is being performed.  */
    9397     88698179 :         expr = cp_convert (build_pointer_type (TREE_TYPE (ref_type)),
    9398              :                            expr, complain);
    9399              :         /* Convert the pointer to the desired reference type.  */
    9400     88698179 :         return build_nop (ref_type, expr);
    9401              :       }
    9402              : 
    9403      3761536 :     case ck_lvalue:
    9404      3761536 :       return decay_conversion (expr, complain);
    9405              : 
    9406       218160 :     case ck_fnptr:
    9407              :       /* ??? Should the address of a transaction-safe pointer point to the TM
    9408              :         clone, and this conversion look up the primary function?  */
    9409       218160 :       return build_nop (totype, expr);
    9410              : 
    9411      2075538 :     case ck_qual:
    9412              :       /* Warn about deprecated conversion if appropriate.  */
    9413      2075538 :       if (complain & tf_warning)
    9414              :         {
    9415      1884941 :           string_conv_p (totype, expr, 1);
    9416      1884941 :           maybe_warn_array_conv (loc, convs, expr);
    9417              :         }
    9418              :       break;
    9419              : 
    9420      3414951 :     case ck_ptr:
    9421      3414951 :       if (convs->base_p)
    9422       202981 :         expr = convert_to_base (expr, totype, !c_cast_p,
    9423              :                                 /*nonnull=*/false, complain);
    9424      3414951 :       return build_nop (totype, expr);
    9425              : 
    9426        27517 :     case ck_pmem:
    9427        27517 :       return convert_ptrmem (totype, expr, /*allow_inverse_p=*/false,
    9428        27517 :                              c_cast_p, complain);
    9429              : 
    9430              :     default:
    9431              :       break;
    9432              :     }
    9433              : 
    9434    111241248 :   if (convs->check_narrowing
    9435    166101744 :       && !check_narrowing (totype, expr, complain,
    9436     54860496 :                            convs->check_narrowing_const_only))
    9437          459 :     return error_mark_node;
    9438              : 
    9439    222481578 :   warning_sentinel w (warn_zero_as_null_pointer_constant);
    9440    111240789 :   if (issue_conversion_warnings)
    9441     88565175 :     expr = cp_convert_and_check (totype, expr, complain);
    9442              :   else
    9443              :     {
    9444     22675614 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9445           36 :         expr = TREE_OPERAND (expr, 0);
    9446     22675614 :       expr = cp_convert (totype, expr, complain);
    9447              :     }
    9448              : 
    9449    111240789 :   return expr;
    9450              : }
    9451              : 
    9452              : /* Return true if converting FROM to TO is unsafe in a template.  */
    9453              : 
    9454              : static bool
    9455      1793922 : conv_unsafe_in_template_p (tree to, tree from)
    9456              : {
    9457              :   /* Converting classes involves TARGET_EXPR.  */
    9458      1793922 :   if (CLASS_TYPE_P (to) || CLASS_TYPE_P (from))
    9459              :     return true;
    9460              : 
    9461              :   /* Converting real to integer produces FIX_TRUNC_EXPR which tsubst
    9462              :      doesn't handle.  */
    9463      1384091 :   if (SCALAR_FLOAT_TYPE_P (from) && INTEGRAL_OR_ENUMERATION_TYPE_P (to))
    9464              :     return true;
    9465              : 
    9466              :   /* Converting integer to real isn't a trivial conversion, either.  */
    9467      1384088 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (from) && SCALAR_FLOAT_TYPE_P (to))
    9468            3 :     return true;
    9469              : 
    9470              :   return false;
    9471              : }
    9472              : 
    9473              : /* Wrapper for convert_like_internal that handles creating
    9474              :    IMPLICIT_CONV_EXPR.  */
    9475              : 
    9476              : static tree
    9477   1256076794 : convert_like (conversion *convs, tree expr, tree fn, int argnum,
    9478              :               bool issue_conversion_warnings, bool c_cast_p, bool nested_p,
    9479              :               tsubst_flags_t complain)
    9480              : {
    9481              :   /* Creating &TARGET_EXPR<> in a template breaks when substituting,
    9482              :      and creating a CALL_EXPR in a template breaks in finish_call_expr
    9483              :      so use an IMPLICIT_CONV_EXPR for this conversion.  We would have
    9484              :      created such codes e.g. when calling a user-defined conversion
    9485              :      function.  */
    9486   1256076794 :   tree conv_expr = NULL_TREE;
    9487   1256076794 :   if (processing_template_decl
    9488    105757339 :       && convs->kind != ck_identity
    9489   1257870716 :       && conv_unsafe_in_template_p (convs->type, TREE_TYPE (expr)))
    9490              :     {
    9491       409837 :       conv_expr = build1 (IMPLICIT_CONV_EXPR, convs->type, expr);
    9492       409837 :       if (convs->kind != ck_ref_bind)
    9493        45567 :         conv_expr = convert_from_reference (conv_expr);
    9494       409837 :       if (!convs->bad_p)
    9495              :         return conv_expr;
    9496              :       /* Do the normal processing to give the bad_p errors.  But we still
    9497              :          need to return the IMPLICIT_CONV_EXPR, unless we're returning
    9498              :          error_mark_node.  */
    9499              :     }
    9500   1255666966 :   expr = convert_like_internal (convs, expr, fn, argnum,
    9501              :                                 issue_conversion_warnings, c_cast_p,
    9502              :                                 nested_p, complain);
    9503   1255666966 :   if (expr == error_mark_node)
    9504              :     return error_mark_node;
    9505   1255592826 :   return conv_expr ? conv_expr : expr;
    9506              : }
    9507              : 
    9508              : /* Convenience wrapper for convert_like.  */
    9509              : 
    9510              : static inline tree
    9511    655949928 : convert_like (conversion *convs, tree expr, tsubst_flags_t complain)
    9512              : {
    9513    655949928 :   return convert_like (convs, expr, NULL_TREE, 0,
    9514              :                        /*issue_conversion_warnings=*/true,
    9515    655949928 :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9516              : }
    9517              : 
    9518              : /* Convenience wrapper for convert_like.  */
    9519              : 
    9520              : static inline tree
    9521    178260249 : convert_like_with_context (conversion *convs, tree expr, tree fn, int argnum,
    9522              :                            tsubst_flags_t complain)
    9523              : {
    9524            0 :   return convert_like (convs, expr, fn, argnum,
    9525              :                        /*issue_conversion_warnings=*/true,
    9526              :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9527              : }
    9528              : 
    9529              : /* ARG is being passed to a varargs function.  Perform any conversions
    9530              :    required.  Return the converted value.  */
    9531              : 
    9532              : tree
    9533      1345244 : convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
    9534              : {
    9535      1345244 :   tree arg_type = TREE_TYPE (arg);
    9536      1345244 :   location_t loc = cp_expr_loc_or_input_loc (arg);
    9537              : 
    9538              :   /* [expr.call]
    9539              : 
    9540              :      If the argument has integral or enumeration type that is subject
    9541              :      to the integral promotions (_conv.prom_), or a floating-point
    9542              :      type that is subject to the floating-point promotion
    9543              :      (_conv.fpprom_), the value of the argument is converted to the
    9544              :      promoted type before the call.  */
    9545      1345244 :   if (SCALAR_FLOAT_TYPE_P (arg_type)
    9546        46925 :       && (TYPE_PRECISION (arg_type)
    9547        46925 :           < TYPE_PRECISION (double_type_node))
    9548        11497 :       && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (arg_type))
    9549      1356063 :       && !extended_float_type_p (arg_type))
    9550              :     {
    9551        10815 :       if ((complain & tf_warning)
    9552        10812 :           && warn_double_promotion && !c_inhibit_evaluation_warnings)
    9553            3 :         warning_at (loc, OPT_Wdouble_promotion,
    9554              :                     "implicit conversion from %qH to %qI when passing "
    9555              :                     "argument to function",
    9556              :                     arg_type, double_type_node);
    9557        10815 :       if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    9558            3 :         arg = TREE_OPERAND (arg, 0);
    9559        10815 :       arg = mark_rvalue_use (arg);
    9560        10815 :       arg = convert_to_real_nofold (double_type_node, arg);
    9561              :     }
    9562      1334429 :   else if (NULLPTR_TYPE_P (arg_type))
    9563              :     {
    9564           75 :       arg = mark_rvalue_use (arg);
    9565           75 :       if (TREE_SIDE_EFFECTS (arg))
    9566              :         {
    9567            6 :           warning_sentinel w(warn_unused_result);
    9568            6 :           arg = cp_build_compound_expr (arg, null_pointer_node, complain);
    9569            6 :         }
    9570              :       else
    9571           69 :         arg = null_pointer_node;
    9572              :     }
    9573      1334354 :   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type))
    9574              :     {
    9575       887078 :       if (SCOPED_ENUM_P (arg_type))
    9576              :         {
    9577           56 :           tree prom = cp_convert (ENUM_UNDERLYING_TYPE (arg_type), arg,
    9578              :                                   complain);
    9579           56 :           prom = cp_perform_integral_promotions (prom, complain);
    9580          109 :           if (abi_version_crosses (6)
    9581           30 :               && TYPE_MODE (TREE_TYPE (prom)) != TYPE_MODE (arg_type)
    9582           86 :               && (complain & tf_warning))
    9583           60 :             warning_at (loc, OPT_Wabi, "scoped enum %qT passed through %<...%>"
    9584              :                         " as %qT before %<-fabi-version=6%>, %qT after",
    9585              :                         arg_type,
    9586           30 :                         TREE_TYPE (prom), ENUM_UNDERLYING_TYPE (arg_type));
    9587           56 :           if (!abi_version_at_least (6))
    9588      1345244 :             arg = prom;
    9589              :         }
    9590              :       else
    9591       887022 :         arg = cp_perform_integral_promotions (arg, complain);
    9592              :     }
    9593              :   else
    9594              :     /* [expr.call]
    9595              : 
    9596              :        The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
    9597              :        standard conversions are performed.  */
    9598       447276 :     arg = decay_conversion (arg, complain);
    9599              : 
    9600      1345244 :   arg = require_complete_type (arg, complain);
    9601      1345244 :   arg_type = TREE_TYPE (arg);
    9602              : 
    9603      1345244 :   if (arg != error_mark_node
    9604              :       /* In a template (or ill-formed code), we can have an incomplete type
    9605              :          even after require_complete_type, in which case we don't know
    9606              :          whether it has trivial copy or not.  */
    9607      1345232 :       && COMPLETE_TYPE_P (arg_type)
    9608      2690476 :       && !cp_unevaluated_operand)
    9609              :     {
    9610              :       /* [expr.call] 5.2.2/7:
    9611              :          Passing a potentially-evaluated argument of class type (Clause 9)
    9612              :          with a non-trivial copy constructor or a non-trivial destructor
    9613              :          with no corresponding parameter is conditionally-supported, with
    9614              :          implementation-defined semantics.
    9615              : 
    9616              :          We support it as pass-by-invisible-reference, just like a normal
    9617              :          value parameter.
    9618              : 
    9619              :          If the call appears in the context of a sizeof expression,
    9620              :          it is not potentially-evaluated.  */
    9621       632337 :       if (type_has_nontrivial_copy_init (arg_type)
    9622       632337 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))
    9623              :         {
    9624           34 :           arg = force_rvalue (arg, complain);
    9625           34 :           if (complain & tf_warning)
    9626           34 :             warning (OPT_Wconditionally_supported,
    9627              :                      "passing objects of non-trivially-copyable "
    9628              :                      "type %q#T through %<...%> is conditionally supported",
    9629              :                      arg_type);
    9630           34 :           return build1 (ADDR_EXPR, build_reference_type (arg_type), arg);
    9631              :         }
    9632              :       /* Build up a real lvalue-to-rvalue conversion in case the
    9633              :          copy constructor is trivial but not callable.  */
    9634       632303 :       else if (CLASS_TYPE_P (arg_type))
    9635        44088 :         force_rvalue (arg, complain);
    9636              : 
    9637              :     }
    9638              : 
    9639              :   return arg;
    9640              : }
    9641              : 
    9642              : /* va_arg (EXPR, TYPE) is a builtin. Make sure it is not abused.  */
    9643              : 
    9644              : tree
    9645        31142 : build_x_va_arg (location_t loc, tree expr, tree type)
    9646              : {
    9647        31142 :   if (processing_template_decl)
    9648              :     {
    9649           39 :       tree r = build_min (VA_ARG_EXPR, type, expr);
    9650           39 :       SET_EXPR_LOCATION (r, loc);
    9651           39 :       return r;
    9652              :     }
    9653              : 
    9654        31103 :   type = complete_type_or_else (type, NULL_TREE);
    9655              : 
    9656        31103 :   if (expr == error_mark_node || !type)
    9657              :     return error_mark_node;
    9658              : 
    9659        31082 :   expr = mark_lvalue_use (expr);
    9660              : 
    9661        31082 :   if (TYPE_REF_P (type))
    9662              :     {
    9663            6 :       error ("cannot receive reference type %qT through %<...%>", type);
    9664            6 :       return error_mark_node;
    9665              :     }
    9666              : 
    9667        31076 :   if (type_has_nontrivial_copy_init (type)
    9668        31076 :       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    9669              :     {
    9670              :       /* conditionally-supported behavior [expr.call] 5.2.2/7.  Let's treat
    9671              :          it as pass by invisible reference.  */
    9672           12 :       warning_at (loc, OPT_Wconditionally_supported,
    9673              :                  "receiving objects of non-trivially-copyable type %q#T "
    9674              :                  "through %<...%> is conditionally-supported", type);
    9675              : 
    9676           12 :       tree ref = cp_build_reference_type (type, false);
    9677           12 :       expr = build_va_arg (loc, expr, ref);
    9678           12 :       return convert_from_reference (expr);
    9679              :     }
    9680              : 
    9681        31064 :   tree ret = build_va_arg (loc, expr, type);
    9682        31064 :   if (CLASS_TYPE_P (type))
    9683              :     /* Wrap the VA_ARG_EXPR in a TARGET_EXPR now so other code doesn't need to
    9684              :        know how to handle it.  */
    9685        12094 :     ret = get_target_expr (ret);
    9686              :   return ret;
    9687              : }
    9688              : 
    9689              : /* TYPE has been given to va_arg.  Apply the default conversions which
    9690              :    would have happened when passed via ellipsis.  Return the promoted
    9691              :    type, or the passed type if there is no change.  */
    9692              : 
    9693              : tree
    9694      2514101 : cxx_type_promotes_to (tree type)
    9695              : {
    9696      2514101 :   tree promote;
    9697              : 
    9698              :   /* Perform the array-to-pointer and function-to-pointer
    9699              :      conversions.  */
    9700      2514101 :   type = type_decays_to (type);
    9701              : 
    9702      2514101 :   promote = type_promotes_to (type);
    9703      2514101 :   if (same_type_p (type, promote))
    9704      2514077 :     promote = type;
    9705              : 
    9706      2514101 :   return promote;
    9707              : }
    9708              : 
    9709              : /* ARG is a default argument expression being passed to a parameter of
    9710              :    the indicated TYPE, which is a parameter to FN.  PARMNUM is the
    9711              :    zero-based argument number.  Do any required conversions.  Return
    9712              :    the converted value.  */
    9713              : 
    9714              : static GTY(()) vec<tree, va_gc> *default_arg_context;
    9715              : void
    9716      8058617 : push_defarg_context (tree fn)
    9717      8058617 : { vec_safe_push (default_arg_context, fn); }
    9718              : 
    9719              : void
    9720      8058617 : pop_defarg_context (void)
    9721      8058617 : { default_arg_context->pop (); }
    9722              : 
    9723              : tree
    9724      1632656 : convert_default_arg (tree type, tree arg, tree fn, int parmnum,
    9725              :                      tsubst_flags_t complain)
    9726              : {
    9727      1632656 :   int i;
    9728      1632656 :   tree t;
    9729              : 
    9730              :   /* See through clones.  */
    9731      1632656 :   fn = DECL_ORIGIN (fn);
    9732              :   /* And inheriting ctors.  */
    9733      1632656 :   if (flag_new_inheriting_ctors)
    9734      1632016 :     fn = strip_inheriting_ctors (fn);
    9735              : 
    9736              :   /* Detect recursion.  */
    9737      1634486 :   FOR_EACH_VEC_SAFE_ELT (default_arg_context, i, t)
    9738         1836 :     if (t == fn)
    9739              :       {
    9740            6 :         if (complain & tf_error)
    9741            6 :           error ("recursive evaluation of default argument for %q#D", fn);
    9742            6 :         return error_mark_node;
    9743              :       }
    9744              : 
    9745              :   /* If the ARG is an unparsed default argument expression, the
    9746              :      conversion cannot be performed.  */
    9747      1632650 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
    9748              :     {
    9749           15 :       if (complain & tf_error)
    9750           15 :         error ("call to %qD uses the default argument for parameter %P, which "
    9751              :                "is not yet defined", fn, parmnum);
    9752           15 :       return error_mark_node;
    9753              :     }
    9754              : 
    9755      1632635 :   push_defarg_context (fn);
    9756              : 
    9757      1632635 :   if (fn && DECL_TEMPLATE_INFO (fn))
    9758      1353960 :     arg = tsubst_default_argument (fn, parmnum, type, arg, complain);
    9759              : 
    9760              :   /* Due to:
    9761              : 
    9762              :        [dcl.fct.default]
    9763              : 
    9764              :        The names in the expression are bound, and the semantic
    9765              :        constraints are checked, at the point where the default
    9766              :        expressions appears.
    9767              : 
    9768              :      we must not perform access checks here.  */
    9769      1632635 :   push_deferring_access_checks (dk_no_check);
    9770              :   /* We must make a copy of ARG, in case subsequent processing
    9771              :      alters any part of it.  */
    9772      1632635 :   arg = break_out_target_exprs (arg, /*clear location*/true);
    9773              : 
    9774      1632635 :   arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT,
    9775              :                                     ICR_DEFAULT_ARGUMENT, fn, parmnum,
    9776              :                                     complain);
    9777      1632635 :   arg = convert_for_arg_passing (type, arg, complain);
    9778      1632635 :   pop_deferring_access_checks();
    9779              : 
    9780      1632635 :   pop_defarg_context ();
    9781              : 
    9782      1632635 :   return arg;
    9783              : }
    9784              : 
    9785              : /* Returns the type which will really be used for passing an argument of
    9786              :    type TYPE.  */
    9787              : 
    9788              : tree
    9789    680457745 : type_passed_as (tree type)
    9790              : {
    9791              :   /* Pass classes with copy ctors by invisible reference.  */
    9792    680457745 :   if (TREE_ADDRESSABLE (type))
    9793       597389 :     type = build_reference_type (type);
    9794              : 
    9795    680457745 :   return type;
    9796              : }
    9797              : 
    9798              : /* Actually perform the appropriate conversion.  */
    9799              : 
    9800              : tree
    9801    184508325 : convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain)
    9802              : {
    9803    184508325 :   tree bitfield_type;
    9804              : 
    9805              :   /* If VAL is a bitfield, then -- since it has already been converted
    9806              :      to TYPE -- it cannot have a precision greater than TYPE.
    9807              : 
    9808              :      If it has a smaller precision, we must widen it here.  For
    9809              :      example, passing "int f:3;" to a function expecting an "int" will
    9810              :      not result in any conversion before this point.
    9811              : 
    9812              :      If the precision is the same we must not risk widening.  For
    9813              :      example, the COMPONENT_REF for a 32-bit "long long" bitfield will
    9814              :      often have type "int", even though the C++ type for the field is
    9815              :      "long long".  If the value is being passed to a function
    9816              :      expecting an "int", then no conversions will be required.  But,
    9817              :      if we call convert_bitfield_to_declared_type, the bitfield will
    9818              :      be converted to "long long".  */
    9819    184508325 :   bitfield_type = is_bitfield_expr_with_lowered_type (val);
    9820    184508325 :   if (bitfield_type
    9821    184508325 :       && TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type))
    9822            0 :     val = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type), val);
    9823              : 
    9824    184508325 :   if (val == error_mark_node)
    9825              :     ;
    9826              :   /* Pass classes with copy ctors by invisible reference.  */
    9827    184505253 :   else if (TREE_ADDRESSABLE (type))
    9828       192089 :     val = build1 (ADDR_EXPR, build_reference_type (type), val);
    9829    184508325 :   if (complain & tf_warning)
    9830    162853058 :     maybe_warn_parm_abi (type, cp_expr_loc_or_input_loc (val));
    9831              : 
    9832    130221043 :   if (complain & tf_warning)
    9833    130221043 :     warn_for_address_of_packed_member (type, val);
    9834              : 
    9835              :   /* gimplify_arg elides TARGET_EXPRs that initialize a function argument,
    9836              :      unless the initializer is a CONSTRUCTOR.  In that case, we fail to
    9837              :      elide the copy anyway.  See that function for more information.  */
    9838     11898374 :   if (SIMPLE_TARGET_EXPR_P (val)
    9839    194462740 :       && TREE_CODE (TARGET_EXPR_INITIAL (val)) != CONSTRUCTOR)
    9840      7171723 :     set_target_expr_eliding (val);
    9841              : 
    9842    184508325 :   return val;
    9843              : }
    9844              : 
    9845              : /* Returns non-zero iff FN is a function with magic varargs, i.e. ones for
    9846              :    which just decay_conversion or no conversions at all should be done.
    9847              :    This is true for some builtins which don't act like normal functions.
    9848              :    Return 2 if just decay_conversion and removal of excess precision should
    9849              :    be done, 1 if just decay_conversion.  Return 3 for special treatment of
    9850              :    the 3rd argument for __builtin_*_overflow_p.  Return 4 for special
    9851              :    treatment of the 1st argument for
    9852              :    __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g.  */
    9853              : 
    9854              : int
    9855    230607052 : magic_varargs_p (tree fn)
    9856              : {
    9857    230607052 :   if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
    9858      6813972 :     switch (DECL_FUNCTION_CODE (fn))
    9859              :       {
    9860              :       case BUILT_IN_CLASSIFY_TYPE:
    9861              :       case BUILT_IN_CONSTANT_P:
    9862              :       case BUILT_IN_NEXT_ARG:
    9863              :       case BUILT_IN_VA_START:
    9864              :         return 1;
    9865              : 
    9866        20842 :       case BUILT_IN_ADD_OVERFLOW_P:
    9867        20842 :       case BUILT_IN_SUB_OVERFLOW_P:
    9868        20842 :       case BUILT_IN_MUL_OVERFLOW_P:
    9869        20842 :         return 3;
    9870              : 
    9871       376979 :       case BUILT_IN_ISFINITE:
    9872       376979 :       case BUILT_IN_ISINF:
    9873       376979 :       case BUILT_IN_ISINF_SIGN:
    9874       376979 :       case BUILT_IN_ISNAN:
    9875       376979 :       case BUILT_IN_ISNORMAL:
    9876       376979 :       case BUILT_IN_FPCLASSIFY:
    9877       376979 :         return 2;
    9878              : 
    9879        91721 :       case BUILT_IN_CLZG:
    9880        91721 :       case BUILT_IN_CTZG:
    9881        91721 :       case BUILT_IN_CLRSBG:
    9882        91721 :       case BUILT_IN_FFSG:
    9883        91721 :       case BUILT_IN_PARITYG:
    9884        91721 :       case BUILT_IN_POPCOUNTG:
    9885        91721 :         return 4;
    9886              : 
    9887      6084136 :       default:
    9888      6084136 :         return lookup_attribute ("type generic",
    9889     12168272 :                                  TYPE_ATTRIBUTES (TREE_TYPE (fn))) != 0;
    9890              :       }
    9891              : 
    9892              :   return 0;
    9893              : }
    9894              : 
    9895              : /* Returns the decl of the dispatcher function if FN is a function version.  */
    9896              : 
    9897              : tree
    9898          237 : get_function_version_dispatcher (tree fn)
    9899              : {
    9900          237 :   tree dispatcher_decl = NULL;
    9901              : 
    9902          237 :   if (DECL_LOCAL_DECL_P (fn))
    9903            9 :     fn = DECL_LOCAL_DECL_ALIAS (fn);
    9904              : 
    9905          237 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
    9906              :               && DECL_FUNCTION_VERSIONED (fn));
    9907              : 
    9908          237 :   gcc_assert (targetm.get_function_versions_dispatcher);
    9909          237 :   dispatcher_decl = targetm.get_function_versions_dispatcher (fn);
    9910              : 
    9911          237 :   if (dispatcher_decl == NULL)
    9912              :     {
    9913            9 :       error_at (input_location, "use of multiversioned function "
    9914              :                                 "without a default");
    9915            9 :       return NULL;
    9916              :     }
    9917              : 
    9918          228 :   retrofit_lang_decl (dispatcher_decl);
    9919          228 :   gcc_assert (dispatcher_decl != NULL);
    9920              :   return dispatcher_decl;
    9921              : }
    9922              : 
    9923              : /* fn is a function version dispatcher that is marked used. Mark all the
    9924              :    semantically identical function versions it will dispatch as used.  */
    9925              : 
    9926              : void
    9927          156 : mark_versions_used (tree fn)
    9928              : {
    9929          156 :   struct cgraph_node *node;
    9930          156 :   struct cgraph_function_version_info *node_v;
    9931          156 :   struct cgraph_function_version_info *it_v;
    9932              : 
    9933          156 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    9934              : 
    9935          156 :   node = cgraph_node::get (fn);
    9936          156 :   if (node == NULL)
    9937              :     return;
    9938              : 
    9939          156 :   gcc_assert (node->dispatcher_function);
    9940              : 
    9941          156 :   node_v = node->function_version ();
    9942          156 :   if (node_v == NULL)
    9943              :     return;
    9944              : 
    9945              :   /* All semantically identical versions are chained.  Traverse and mark each
    9946              :      one of them as used.  */
    9947          156 :   it_v = node_v->next;
    9948         1128 :   while (it_v != NULL)
    9949              :     {
    9950          972 :       mark_used (it_v->this_node->decl);
    9951          972 :       it_v = it_v->next;
    9952              :     }
    9953              : }
    9954              : 
    9955              : /* Build a call to "the copy constructor" for the type of A, even if it
    9956              :    wouldn't be selected by normal overload resolution.  Used for
    9957              :    diagnostics.  */
    9958              : 
    9959              : static tree
    9960            3 : call_copy_ctor (tree a, tsubst_flags_t complain)
    9961              : {
    9962            3 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (a));
    9963            3 :   tree binfo = TYPE_BINFO (ctype);
    9964            3 :   tree copy = get_copy_ctor (ctype, complain);
    9965            3 :   copy = build_baselink (binfo, binfo, copy, NULL_TREE);
    9966            3 :   tree ob = build_dummy_object (ctype);
    9967            3 :   releasing_vec args (make_tree_vector_single (a));
    9968            3 :   tree r = build_new_method_call (ob, copy, &args, NULL_TREE,
    9969              :                                   LOOKUP_NORMAL, NULL, complain);
    9970            3 :   return r;
    9971            3 : }
    9972              : 
    9973              : /* Return the base constructor corresponding to COMPLETE_CTOR or NULL_TREE.  */
    9974              : 
    9975              : static tree
    9976           42 : base_ctor_for (tree complete_ctor)
    9977              : {
    9978           42 :   tree clone;
    9979           42 :   FOR_EACH_CLONE (clone, DECL_CLONED_FUNCTION (complete_ctor))
    9980           42 :     if (DECL_BASE_CONSTRUCTOR_P (clone))
    9981              :       return clone;
    9982              :   return NULL_TREE;
    9983              : }
    9984              : 
    9985              : /* Try to make EXP suitable to be used as the initializer for a base subobject,
    9986              :    and return whether we were successful.  EXP must have already been cleared
    9987              :    by unsafe_copy_elision_p{,_opt}.  */
    9988              : 
    9989              : static bool
    9990          206 : make_base_init_ok (tree exp)
    9991              : {
    9992          206 :   if (TREE_CODE (exp) == TARGET_EXPR)
    9993          206 :     exp = TARGET_EXPR_INITIAL (exp);
    9994          209 :   while (TREE_CODE (exp) == COMPOUND_EXPR)
    9995            3 :     exp = TREE_OPERAND (exp, 1);
    9996          206 :   if (TREE_CODE (exp) == COND_EXPR)
    9997              :     {
    9998            3 :       bool ret = make_base_init_ok (TREE_OPERAND (exp, 2));
    9999            3 :       if (tree op1 = TREE_OPERAND (exp, 1))
   10000              :         {
   10001            3 :           bool r1 = make_base_init_ok (op1);
   10002              :           /* If unsafe_copy_elision_p was false, the arms should match.  */
   10003            3 :           gcc_assert (r1 == ret);
   10004              :         }
   10005            3 :       return ret;
   10006              :     }
   10007          203 :   if (TREE_CODE (exp) != AGGR_INIT_EXPR)
   10008              :     /* A trivial copy is OK.  */
   10009              :     return true;
   10010           60 :   if (!AGGR_INIT_VIA_CTOR_P (exp))
   10011              :     /* unsafe_copy_elision_p_opt must have said this is OK.  */
   10012              :     return true;
   10013           42 :   tree fn = cp_get_callee_fndecl_nofold (exp);
   10014           42 :   if (DECL_BASE_CONSTRUCTOR_P (fn))
   10015              :     return true;
   10016           42 :   gcc_assert (DECL_COMPLETE_CONSTRUCTOR_P (fn));
   10017           42 :   fn = base_ctor_for (fn);
   10018           42 :   if (!fn || DECL_HAS_VTT_PARM_P (fn))
   10019              :     /* The base constructor has more parameters, so we can't just change the
   10020              :        call target.  It would be possible to splice in the appropriate
   10021              :        arguments, but probably not worth the complexity.  */
   10022              :     return false;
   10023           33 :   mark_used (fn);
   10024           33 :   AGGR_INIT_EXPR_FN (exp) = build_address (fn);
   10025           33 :   return true;
   10026              : }
   10027              : 
   10028              : /* Return 2 if T refers to a base, 1 if a potentially-overlapping field,
   10029              :    neither of which can be used for return by invisible reference.  We avoid
   10030              :    doing C++17 mandatory copy elision for either of these cases.
   10031              : 
   10032              :    This returns non-zero even if the type of T has no tail padding that other
   10033              :    data could be allocated into, because that depends on the particular ABI.
   10034              :    unsafe_copy_elision_p_opt does consider whether there is padding.  */
   10035              : 
   10036              : int
   10037     57267906 : unsafe_return_slot_p (tree t)
   10038              : {
   10039              :   /* Check empty bases separately, they don't have fields.  */
   10040     57267906 :   if (is_empty_base_ref (t))
   10041              :     return 2;
   10042              : 
   10043              :   /* A delegating constructor might be used to initialize a base.  */
   10044     56788720 :   if (current_function_decl
   10045     78638400 :       && DECL_CONSTRUCTOR_P (current_function_decl)
   10046     61485673 :       && (t == current_class_ref
   10047      4535317 :           || tree_strip_nop_conversions (t) == current_class_ptr))
   10048       209171 :     return 2;
   10049              : 
   10050     56579549 :   STRIP_NOPS (t);
   10051     56579549 :   if (TREE_CODE (t) == ADDR_EXPR)
   10052        77368 :     t = TREE_OPERAND (t, 0);
   10053     56579549 :   if (TREE_CODE (t) == COMPONENT_REF)
   10054      4702309 :     t = TREE_OPERAND (t, 1);
   10055     56579549 :   if (TREE_CODE (t) != FIELD_DECL)
   10056              :     return false;
   10057      4774470 :   if (!CLASS_TYPE_P (TREE_TYPE (t)))
   10058              :     /* The middle-end will do the right thing for scalar types.  */
   10059              :     return false;
   10060      3313633 :   if (DECL_FIELD_IS_BASE (t))
   10061              :     return 2;
   10062      2514965 :   if (lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (t)))
   10063              :     return 1;
   10064              :   return 0;
   10065              : }
   10066              : 
   10067              : /* True IFF EXP is a prvalue that represents return by invisible reference.  */
   10068              : 
   10069              : static bool
   10070       268815 : init_by_return_slot_p (tree exp)
   10071              : {
   10072              :   /* Copy elision only happens with a TARGET_EXPR.  */
   10073       268818 :   if (TREE_CODE (exp) != TARGET_EXPR)
   10074              :     return false;
   10075        13423 :   tree init = TARGET_EXPR_INITIAL (exp);
   10076              :   /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR.  */
   10077        13429 :   while (TREE_CODE (init) == COMPOUND_EXPR)
   10078            6 :     init = TREE_OPERAND (init, 1);
   10079        13423 :   if (TREE_CODE (init) == COND_EXPR)
   10080              :     {
   10081              :       /* We'll end up copying from each of the arms of the COND_EXPR directly
   10082              :          into the target, so look at them.  */
   10083            6 :       if (tree op = TREE_OPERAND (init, 1))
   10084            6 :         if (init_by_return_slot_p (op))
   10085              :           return true;
   10086            3 :       return init_by_return_slot_p (TREE_OPERAND (init, 2));
   10087              :     }
   10088        13417 :   return (TREE_CODE (init) == AGGR_INIT_EXPR
   10089        13417 :           && !AGGR_INIT_VIA_CTOR_P (init));
   10090              : }
   10091              : 
   10092              : /* We can't elide a copy from a function returning by value to a
   10093              :    potentially-overlapping subobject, as the callee might clobber tail padding.
   10094              :    Return true iff this could be that case.
   10095              : 
   10096              :    Places that use this function (or _opt) to decide to elide a copy should
   10097              :    probably use make_safe_copy_elision instead.  */
   10098              : 
   10099              : bool
   10100      3304309 : unsafe_copy_elision_p (tree target, tree exp)
   10101              : {
   10102      3304309 :   return unsafe_return_slot_p (target) && init_by_return_slot_p (exp);
   10103              : }
   10104              : 
   10105              : /* As above, but for optimization allow more cases that are actually safe.  */
   10106              : 
   10107              : static bool
   10108     11546905 : unsafe_copy_elision_p_opt (tree target, tree exp)
   10109              : {
   10110     11546905 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
   10111              :   /* It's safe to elide the copy for a class with no tail padding.  */
   10112     11546905 :   if (!is_empty_class (type)
   10113     11546905 :       && tree_int_cst_equal (TYPE_SIZE (type), CLASSTYPE_SIZE (type)))
   10114              :     return false;
   10115      3232148 :   return unsafe_copy_elision_p (target, exp);
   10116              : }
   10117              : 
   10118              : /* Try to make EXP suitable to be used as the initializer for TARGET,
   10119              :    and return whether we were successful.  */
   10120              : 
   10121              : bool
   10122           23 : make_safe_copy_elision (tree target, tree exp)
   10123              : {
   10124           23 :   int uns = unsafe_return_slot_p (target);
   10125           23 :   if (!uns)
   10126              :     return true;
   10127           23 :   if (init_by_return_slot_p (exp))
   10128              :     return false;
   10129           23 :   if (uns == 1)
   10130              :     return true;
   10131           19 :   return make_base_init_ok (exp);
   10132              : }
   10133              : 
   10134              : /* True IFF the result of the conversion C is a prvalue.  */
   10135              : 
   10136              : static bool
   10137     18979008 : conv_is_prvalue (conversion *c)
   10138              : {
   10139     18979008 :   if (c->kind == ck_rvalue)
   10140              :     return true;
   10141     18979008 :   if (c->kind == ck_base && c->need_temporary_p)
   10142              :     return true;
   10143     18979008 :   if (c->kind == ck_user && !TYPE_REF_P (c->type))
   10144              :     return true;
   10145     18850995 :   if (c->kind == ck_identity && c->u.expr
   10146     18622959 :       && TREE_CODE (c->u.expr) == TARGET_EXPR)
   10147           56 :     return true;
   10148              : 
   10149              :   return false;
   10150              : }
   10151              : 
   10152              : /* True iff C is a conversion that binds a reference to a prvalue.  */
   10153              : 
   10154              : static bool
   10155     18980024 : conv_binds_ref_to_prvalue (conversion *c)
   10156              : {
   10157     18980024 :   if (c->kind != ck_ref_bind)
   10158              :     return false;
   10159     18980024 :   if (c->need_temporary_p)
   10160              :     return true;
   10161              : 
   10162     18979008 :   return conv_is_prvalue (next_conversion (c));
   10163              : }
   10164              : 
   10165              : /* True iff EXPR represents a (subobject of a) temporary.  */
   10166              : 
   10167              : static bool
   10168        13788 : expr_represents_temporary_p (tree expr)
   10169              : {
   10170        13892 :   while (handled_component_p (expr))
   10171          104 :     expr = TREE_OPERAND (expr, 0);
   10172        13788 :   return TREE_CODE (expr) == TARGET_EXPR;
   10173              : }
   10174              : 
   10175              : /* True iff C is a conversion that binds a reference to a temporary.
   10176              :    This is a superset of conv_binds_ref_to_prvalue: here we're also
   10177              :    interested in xvalues.  */
   10178              : 
   10179              : static bool
   10180        13090 : conv_binds_ref_to_temporary (conversion *c)
   10181              : {
   10182        13090 :   if (conv_binds_ref_to_prvalue (c))
   10183              :     return true;
   10184        12663 :   if (c->kind != ck_ref_bind)
   10185              :     return false;
   10186        12663 :   c = next_conversion (c);
   10187              :   /* This is the case for
   10188              :        struct Base {};
   10189              :        struct Derived : Base {};
   10190              :        const Base& b(Derived{});
   10191              :      where we bind 'b' to the Base subobject of a temporary object of type
   10192              :      Derived.  The subobject is an xvalue; the whole object is a prvalue.
   10193              : 
   10194              :      The ck_base doesn't have to be present for cases like X{}.m.  */
   10195        12663 :   if (c->kind == ck_base)
   10196            8 :     c = next_conversion (c);
   10197        12595 :   if (c->kind == ck_identity && c->u.expr
   10198        25258 :       && expr_represents_temporary_p (c->u.expr))
   10199              :     return true;
   10200              :   return false;
   10201              : }
   10202              : 
   10203              : /* Return tristate::TS_TRUE if converting EXPR to a reference type TYPE binds
   10204              :    the reference to a temporary.  Return tristate::TS_FALSE if converting
   10205              :    EXPR to a reference type TYPE doesn't bind the reference to a temporary.  If
   10206              :    the conversion is invalid or bad, return tristate::TS_UNKNOWN.  DIRECT_INIT_P
   10207              :    says whether the conversion should be done in direct- or copy-initialization
   10208              :    context.  */
   10209              : 
   10210              : tristate
   10211        13591 : ref_conv_binds_to_temporary (tree type, tree expr, bool direct_init_p/*=false*/)
   10212              : {
   10213        13591 :   gcc_assert (TYPE_REF_P (type));
   10214              : 
   10215        13591 :   conversion_obstack_sentinel cos;
   10216              : 
   10217        13591 :   const int flags = direct_init_p ? LOOKUP_NORMAL : LOOKUP_IMPLICIT;
   10218        13591 :   conversion *conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   10219              :                                           /*c_cast_p=*/false, flags, tf_none);
   10220        13591 :   if (!conv || conv->bad_p)
   10221          501 :     return tristate::unknown ();
   10222              : 
   10223        13090 :   if (conv_binds_ref_to_temporary (conv))
   10224              :     {
   10225              :       /* Actually perform the conversion to check access control.  */
   10226          433 :       if (convert_like (conv, expr, tf_none) != error_mark_node)
   10227          421 :         return tristate (true);
   10228              :       else
   10229           12 :         return tristate::unknown ();
   10230              :     }
   10231              : 
   10232        12657 :   return tristate (false);
   10233        13591 : }
   10234              : 
   10235              : /* Call the trivial destructor for INSTANCE, which can be either an lvalue of
   10236              :    class type or a pointer to class type.  If NO_PTR_DEREF is true and
   10237              :    INSTANCE has pointer type, clobber the pointer rather than what it points
   10238              :    to.  */
   10239              : 
   10240              : tree
   10241      3401293 : build_trivial_dtor_call (tree instance, bool no_ptr_deref)
   10242              : {
   10243      3401293 :   gcc_assert (!is_dummy_object (instance));
   10244              : 
   10245      3401293 :   if (!flag_lifetime_dse)
   10246              :     {
   10247           58 :     no_clobber:
   10248           77 :       return fold_convert (void_type_node, instance);
   10249              :     }
   10250              : 
   10251      3467739 :   if (INDIRECT_TYPE_P (TREE_TYPE (instance))
   10252      3401235 :       && (!no_ptr_deref || TYPE_REF_P (TREE_TYPE (instance))))
   10253              :     {
   10254      3227174 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
   10255           19 :         goto no_clobber;
   10256      3227155 :       instance = cp_build_fold_indirect_ref (instance);
   10257              :     }
   10258              : 
   10259              :   /* A trivial destructor should still clobber the object.  */
   10260      3401216 :   tree clobber = build_clobber (TREE_TYPE (instance), CLOBBER_OBJECT_END);
   10261      3401216 :   return build2 (MODIFY_EXPR, void_type_node,
   10262      3401216 :                  instance, clobber);
   10263              : }
   10264              : 
   10265              : /* Return true if in an immediate function context, or an unevaluated operand,
   10266              :    or a default argument/member initializer, or a subexpression of an immediate
   10267              :    invocation.  */
   10268              : 
   10269              : bool
   10270     12434316 : in_immediate_context ()
   10271              : {
   10272     12434316 :   return (cp_unevaluated_operand != 0
   10273     10913009 :           || (current_function_decl != NULL_TREE
   10274     18924476 :               && DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
   10275              :           /* DR 2631: default args and DMI aren't immediately evaluated.
   10276              :              Return true here so immediate_invocation_p returns false.  */
   10277     10173332 :           || current_binding_level->kind == sk_function_parms
   10278     10172128 :           || current_binding_level->kind == sk_template_parms
   10279     10143717 :           || parsing_nsdmi ()
   10280     22576323 :           || in_consteval_if_p);
   10281              : }
   10282              : 
   10283              : /* Return true if a call to FN with number of arguments NARGS
   10284              :    is an immediate invocation.  */
   10285              : 
   10286              : bool
   10287    268949005 : immediate_invocation_p (tree fn)
   10288              : {
   10289    268949005 :   return (TREE_CODE (fn) == FUNCTION_DECL
   10290    268949005 :           && DECL_IMMEDIATE_FUNCTION_P (fn)
   10291    272885754 :           && !in_immediate_context ());
   10292              : }
   10293              : 
   10294              : /* Subroutine of the various build_*_call functions.  Overload resolution
   10295              :    has chosen a winning candidate CAND; build up a CALL_EXPR accordingly.
   10296              :    ARGS is a TREE_LIST of the unconverted arguments to the call.  FLAGS is a
   10297              :    bitmask of various LOOKUP_* flags which apply to the call itself.  */
   10298              : 
   10299              : static tree
   10300    291619305 : build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
   10301              : {
   10302    291619305 :   tree fn = cand->fn;
   10303    291619305 :   const vec<tree, va_gc> *args = cand->args;
   10304    291619305 :   tree first_arg = cand->first_arg;
   10305    291619305 :   conversion **convs = cand->convs;
   10306    291619305 :   tree parm = TYPE_ARG_TYPES (TREE_TYPE (fn));
   10307    291619305 :   int parmlen;
   10308    291619305 :   tree val;
   10309    291619305 :   int nargs;
   10310    291619305 :   tree *argarray;
   10311    291619305 :   bool already_used = false;
   10312              : 
   10313              :   /* In a template, there is no need to perform all of the work that
   10314              :      is normally done.  We are only interested in the type of the call
   10315              :      expression, i.e., the return type of the function.  Any semantic
   10316              :      errors will be deferred until the template is instantiated.  */
   10317    291619305 :   if (processing_template_decl)
   10318              :     {
   10319     29121584 :       if (undeduced_auto_decl (fn))
   10320         9942 :         mark_used (fn, complain);
   10321              :       else
   10322              :         /* Otherwise set TREE_USED for the benefit of -Wunused-function.
   10323              :            See PR80598.  */
   10324     29111642 :         TREE_USED (fn) = 1;
   10325              : 
   10326     29121584 :       tree return_type = TREE_TYPE (TREE_TYPE (fn));
   10327     29121584 :       tree callee;
   10328     29121584 :       if (first_arg == NULL_TREE)
   10329              :         {
   10330     21164607 :           callee = build_addr_func (fn, complain);
   10331     21164607 :           if (callee == error_mark_node)
   10332              :             return error_mark_node;
   10333              :         }
   10334              :       else
   10335              :         {
   10336      7956977 :           callee = build_baselink (cand->conversion_path, cand->access_path,
   10337              :                                    fn, NULL_TREE);
   10338      7956977 :           callee = build_min (COMPONENT_REF, TREE_TYPE (fn),
   10339              :                               first_arg, callee, NULL_TREE);
   10340              :         }
   10341              : 
   10342     29121584 :       tree expr = build_call_vec (return_type, callee, args);
   10343     29121584 :       SET_EXPR_LOCATION (expr, input_location);
   10344     29121584 :       if (TREE_THIS_VOLATILE (fn) && cfun)
   10345      2437480 :         current_function_returns_abnormally = 1;
   10346     29121584 :       if (TREE_DEPRECATED (fn)
   10347     29121584 :           && warning_suppressed_at (input_location,
   10348              :                                     OPT_Wdeprecated_declarations))
   10349              :         /* Make the expr consistent with the location.  */
   10350        18882 :         TREE_NO_WARNING (expr) = true;
   10351     29121584 :       if (immediate_invocation_p (fn))
   10352              :         {
   10353       191000 :           tree obj_arg = NULL_TREE;
   10354       382000 :           if (DECL_CONSTRUCTOR_P (fn))
   10355            3 :             obj_arg = first_arg;
   10356              :           /* Look through *(const T *)&obj.  */
   10357            3 :           if (obj_arg && INDIRECT_REF_P (obj_arg))
   10358              :             {
   10359            3 :               tree addr = TREE_OPERAND (obj_arg, 0);
   10360            3 :               STRIP_NOPS (addr);
   10361            3 :               if (TREE_CODE (addr) == ADDR_EXPR)
   10362              :                 {
   10363            0 :                   tree typeo = TREE_TYPE (obj_arg);
   10364            0 :                   tree typei = TREE_TYPE (TREE_OPERAND (addr, 0));
   10365            0 :                   if (same_type_ignoring_top_level_qualifiers_p (typeo, typei))
   10366            0 :                     obj_arg = TREE_OPERAND (addr, 0);
   10367              :                 }
   10368              :             }
   10369       191000 :           fold_non_dependent_expr (expr, complain,
   10370              :                                    /*manifestly_const_eval=*/true,
   10371              :                                    obj_arg);
   10372              :         }
   10373     29121584 :       return convert_from_reference (expr);
   10374              :     }
   10375              : 
   10376              :   /* Give any warnings we noticed during overload resolution.  */
   10377    262497721 :   if (cand->warnings && (complain & tf_warning))
   10378              :     {
   10379              :       struct candidate_warning *w;
   10380           98 :       for (w = cand->warnings; w; w = w->next)
   10381           49 :         joust (cand, w->loser, 1, complain);
   10382              :     }
   10383              : 
   10384              :   /* Core issue 2327: P0135 doesn't say how to handle the case where the
   10385              :      argument to the copy constructor ends up being a prvalue after
   10386              :      conversion.  Let's do the normal processing, but pretend we aren't
   10387              :      actually using the copy constructor.  */
   10388    262497721 :   bool force_elide = false;
   10389    262497721 :   if (cxx_dialect >= cxx17
   10390    260531558 :       && cand->num_convs == 1
   10391    143762619 :       && DECL_COMPLETE_CONSTRUCTOR_P (fn)
   10392     50746586 :       && (DECL_COPY_CONSTRUCTOR_P (fn)
   10393     24907952 :           || DECL_MOVE_CONSTRUCTOR_P (fn))
   10394     19048790 :       && !unsafe_return_slot_p (first_arg)
   10395    281464601 :       && conv_binds_ref_to_prvalue (convs[0]))
   10396              :     {
   10397       128655 :       force_elide = true;
   10398       128655 :       goto not_really_used;
   10399              :     }
   10400              : 
   10401              :   /* OK, we're actually calling this inherited constructor; set its deletedness
   10402              :      appropriately.  We can get away with doing this here because calling is
   10403              :      the only way to refer to a constructor.  */
   10404    524738132 :   if (DECL_INHERITED_CTOR (fn)
   10405     37376619 :       && !deduce_inheriting_ctor (fn))
   10406              :     {
   10407            2 :       if (complain & tf_error)
   10408            2 :         mark_used (fn);
   10409            2 :       return error_mark_node;
   10410              :     }
   10411              : 
   10412              :   /* Make =delete work with SFINAE.  */
   10413    262369064 :   if (DECL_DELETED_FN (fn))
   10414              :     {
   10415      1169321 :       if (complain & tf_error)
   10416              :         {
   10417         2258 :           mark_used (fn);
   10418         2258 :           if (cand->next)
   10419              :             {
   10420         2065 :               if (flag_diagnostics_all_candidates)
   10421            9 :                 print_z_candidates (input_location, cand, /*only_viable_p=*/false);
   10422              :               else
   10423         2056 :                 inform (input_location,
   10424              :                         "use %<-fdiagnostics-all-candidates%> to display "
   10425              :                         "considered candidates");
   10426              :             }
   10427              :         }
   10428      1169321 :       return error_mark_node;
   10429              :     }
   10430              : 
   10431    261199743 :   if (DECL_FUNCTION_MEMBER_P (fn))
   10432              :     {
   10433    137591570 :       tree access_fn;
   10434              :       /* If FN is a template function, two cases must be considered.
   10435              :          For example:
   10436              : 
   10437              :            struct A {
   10438              :              protected:
   10439              :                template <class T> void f();
   10440              :            };
   10441              :            template <class T> struct B {
   10442              :              protected:
   10443              :                void g();
   10444              :            };
   10445              :            struct C : A, B<int> {
   10446              :              using A::f;        // #1
   10447              :              using B<int>::g;     // #2
   10448              :            };
   10449              : 
   10450              :          In case #1 where `A::f' is a member template, DECL_ACCESS is
   10451              :          recorded in the primary template but not in its specialization.
   10452              :          We check access of FN using its primary template.
   10453              : 
   10454              :          In case #2, where `B<int>::g' has a DECL_TEMPLATE_INFO simply
   10455              :          because it is a member of class template B, DECL_ACCESS is
   10456              :          recorded in the specialization `B<int>::g'.  We cannot use its
   10457              :          primary template because `B<T>::g' and `B<int>::g' may have
   10458              :          different access.  */
   10459    137591570 :       if (DECL_TEMPLATE_INFO (fn)
   10460    137591570 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   10461     11001879 :         access_fn = DECL_TI_TEMPLATE (fn);
   10462              :       else
   10463              :         access_fn = fn;
   10464    137591570 :       if (!perform_or_defer_access_check (cand->access_path, access_fn,
   10465              :                                           fn, complain))
   10466        19966 :         return error_mark_node;
   10467              :     }
   10468              : 
   10469              :   /* If we're checking for implicit delete, don't bother with argument
   10470              :      conversions.  */
   10471    261179777 :   if (flags & LOOKUP_SPECULATIVE)
   10472              :     {
   10473     30698828 :       if (cand->viable == 1)
   10474              :         return fn;
   10475          117 :       else if (!(complain & tf_error))
   10476              :         /* Reject bad conversions now.  */
   10477          102 :         return error_mark_node;
   10478              :       /* else continue to get conversion error.  */
   10479              :     }
   10480              : 
   10481    230480949 :  not_really_used:
   10482              : 
   10483              :   /* N3276 magic doesn't apply to nested calls.  */
   10484    230609619 :   tsubst_flags_t decltype_flag = (complain & tf_decltype);
   10485    230609619 :   complain &= ~tf_decltype;
   10486              :   /* No-Cleanup doesn't apply to nested calls either.  */
   10487    230609619 :   tsubst_flags_t no_cleanup_complain = complain;
   10488    230609619 :   complain &= ~tf_no_cleanup;
   10489              : 
   10490              :   /* Find maximum size of vector to hold converted arguments.  */
   10491    230609619 :   parmlen = list_length (parm);
   10492    437694083 :   nargs = vec_safe_length (args) + (first_arg != NULL_TREE ? 1 : 0);
   10493    230609619 :   if (parmlen > nargs)
   10494              :     nargs = parmlen;
   10495    230609619 :   argarray = XALLOCAVEC (tree, nargs);
   10496              : 
   10497    461219235 :   in_consteval_if_p_temp_override icip;
   10498              :   /* If the call is immediate function invocation, make sure
   10499              :      taking address of immediate functions is allowed in its arguments.  */
   10500    230609619 :   if (immediate_invocation_p (STRIP_TEMPLATE (fn)))
   10501      2156233 :     in_consteval_if_p = true;
   10502              : 
   10503    230609619 :   int argarray_size = 0;
   10504    230609619 :   unsigned int arg_index = 0;
   10505    230609619 :   int conv_index = 0;
   10506    230609619 :   int param_index = 0;
   10507    230609619 :   tree parmd = DECL_ARGUMENTS (fn);
   10508              : 
   10509    324074870 :   auto consume_object_arg = [&arg_index, &first_arg, args]()
   10510              :     {
   10511     93465251 :       if (!first_arg)
   10512            0 :         return (*args)[arg_index++];
   10513     93465251 :       tree object_arg = first_arg;
   10514     93465251 :       first_arg = NULL_TREE;
   10515     93465251 :       return object_arg;
   10516    230609619 :     };
   10517              : 
   10518              :   /* The implicit parameters to a constructor are not considered by overload
   10519              :      resolution, and must be of the proper type.  */
   10520    230609619 :   if (DECL_CONSTRUCTOR_P (fn))
   10521              :     {
   10522     26964052 :       tree object_arg = consume_object_arg ();
   10523     26964052 :       argarray[argarray_size++] = build_this (object_arg);
   10524     26964052 :       parm = TREE_CHAIN (parm);
   10525     26964052 :       if (parmd)
   10526     26964052 :         parmd = DECL_CHAIN (parmd);
   10527              :       /* We should never try to call the abstract constructor.  */
   10528     26964052 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (fn));
   10529              : 
   10530     26964052 :       if (DECL_HAS_VTT_PARM_P (fn))
   10531              :         {
   10532        16829 :           argarray[argarray_size++] = (*args)[arg_index];
   10533        16829 :           ++arg_index;
   10534        16829 :           parm = TREE_CHAIN (parm);
   10535        16829 :           if (parmd)
   10536        16829 :             parmd = DECL_CHAIN (parmd);
   10537              :         }
   10538              :     }
   10539              :   /* Bypass access control for 'this' parameter.  */
   10540    203645567 :   else if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
   10541              :     {
   10542     66495047 :       tree arg = build_this (consume_object_arg ());
   10543     66495047 :       tree argtype = TREE_TYPE (arg);
   10544              : 
   10545     66495047 :       if (arg == error_mark_node)
   10546              :         return error_mark_node;
   10547     66495044 :       if (convs[conv_index++]->bad_p)
   10548              :         {
   10549         1061 :           if (complain & tf_error)
   10550              :             {
   10551          103 :               auto_diagnostic_group d;
   10552          103 :               if (permerror (input_location, "passing %qT as %<this%> "
   10553              :                              "argument discards qualifiers",
   10554          103 :                              TREE_TYPE (argtype)))
   10555          100 :                 inform (DECL_SOURCE_LOCATION (fn), "  in call to %qD", fn);
   10556          103 :             }
   10557              :           else
   10558              :             return error_mark_node;
   10559              :         }
   10560              : 
   10561              :       /* The class where FN is defined.  */
   10562     66494086 :       tree ctx = DECL_CONTEXT (fn);
   10563              : 
   10564              :       /* See if the function member or the whole class type is declared
   10565              :          final and the call can be devirtualized.  */
   10566     66494086 :       if (DECL_FINAL_P (fn) || CLASSTYPE_FINAL (ctx))
   10567       139821 :         flags |= LOOKUP_NONVIRTUAL;
   10568              : 
   10569              :       /* [class.mfct.non-static]: If a non-static member function of a class
   10570              :          X is called for an object that is not of type X, or of a type
   10571              :          derived from X, the behavior is undefined.
   10572              : 
   10573              :          So we can assume that anything passed as 'this' is non-null, and
   10574              :          optimize accordingly.  */
   10575              :       /* Check that the base class is accessible.  */
   10576     66494086 :       if (!accessible_base_p (TREE_TYPE (argtype),
   10577     66494086 :                               BINFO_TYPE (cand->conversion_path), true))
   10578              :         {
   10579           33 :           if (complain & tf_error)
   10580           30 :             error ("%qT is not an accessible base of %qT",
   10581           30 :                    BINFO_TYPE (cand->conversion_path),
   10582           30 :                    TREE_TYPE (argtype));
   10583              :           else
   10584            3 :             return error_mark_node;
   10585              :         }
   10586              :       /* If fn was found by a using declaration, the conversion path
   10587              :          will be to the derived class, not the base declaring fn. We
   10588              :          must convert to the base.  */
   10589     66494083 :       tree base_binfo = cand->conversion_path;
   10590     66494083 :       if (BINFO_TYPE (base_binfo) != ctx)
   10591              :         {
   10592       128483 :           base_binfo = lookup_base (base_binfo, ctx, ba_unique, NULL, complain);
   10593       128483 :           if (base_binfo == error_mark_node)
   10594              :             return error_mark_node;
   10595              :         }
   10596              : 
   10597              :       /* If we know the dynamic type of the object, look up the final overrider
   10598              :          in the BINFO.  */
   10599     67659283 :       if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
   10600     67198656 :           && resolves_to_fixed_type_p (arg))
   10601              :         {
   10602         1069 :           tree ov = lookup_vfn_in_binfo (DECL_VINDEX (fn), base_binfo);
   10603              : 
   10604              :           /* And unwind base_binfo to match.  If we don't find the type we're
   10605              :              looking for in BINFO_INHERITANCE_CHAIN, we're looking at diamond
   10606              :              inheritance; for now do a normal virtual call in that case.  */
   10607         1069 :           tree octx = DECL_CONTEXT (ov);
   10608         1069 :           tree obinfo = base_binfo;
   10609         2213 :           while (obinfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (obinfo), octx))
   10610           39 :             obinfo = BINFO_INHERITANCE_CHAIN (obinfo);
   10611         1069 :           if (obinfo)
   10612              :             {
   10613         1066 :               fn = ov;
   10614         1066 :               base_binfo = obinfo;
   10615         1066 :               flags |= LOOKUP_NONVIRTUAL;
   10616              :             }
   10617              :         }
   10618              : 
   10619     66494077 :       tree converted_arg = build_base_path (PLUS_EXPR, arg,
   10620              :                                             base_binfo, 1, complain);
   10621              : 
   10622     66494077 :       argarray[argarray_size++] = converted_arg;
   10623     66494077 :       parm = TREE_CHAIN (parm);
   10624     66494077 :       if (parmd)
   10625     66494077 :         parmd = DECL_CHAIN (parmd);
   10626              :     }
   10627              : 
   10628    408868898 :   auto handle_arg = [fn, flags](tree type,
   10629              :                                 tree arg,
   10630              :                                 int const param_index,
   10631              :                                 conversion *conv,
   10632              :                                 tsubst_flags_t const arg_complain)
   10633              :     {
   10634              :       /* Set user_conv_p on the argument conversions, so rvalue/base handling
   10635              :          knows not to allow any more UDCs.  This needs to happen after we
   10636              :          process cand->warnings.  */
   10637    178260249 :       if (flags & LOOKUP_NO_CONVERSION)
   10638      4767135 :         conv->user_conv_p = true;
   10639              : 
   10640    178260249 :       if (arg_complain & tf_warning)
   10641    124433323 :         maybe_warn_pessimizing_move (arg, type, /*return_p=*/false);
   10642              : 
   10643    178260249 :       tree val = convert_like_with_context (conv, arg, fn,
   10644              :                                             param_index, arg_complain);
   10645    178260249 :       val = convert_for_arg_passing (type, val, arg_complain);
   10646    178260249 :       return val;
   10647    230608649 :     };
   10648              : 
   10649    410499940 :   auto handle_indeterminate_arg = [](tree parmd, tree val)
   10650              :     {
   10651    179891291 :       if (parmd
   10652    179891291 :           && lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (parmd)))
   10653              :         {
   10654           48 :           STRIP_NOPS (val);
   10655           48 :           if (TREE_CODE (val) == ADDR_EXPR
   10656           48 :               && TREE_CODE (TREE_OPERAND (val, 0)) == TARGET_EXPR)
   10657              :             {
   10658           48 :               val = TARGET_EXPR_SLOT (TREE_OPERAND (val, 0));
   10659           48 :               if (auto_var_p (val) && DECL_ARTIFICIAL (val))
   10660              :                 {
   10661           48 :                   tree id = get_identifier ("indeterminate");
   10662           48 :                   DECL_ATTRIBUTES (val)
   10663           96 :                     = tree_cons (build_tree_list (NULL_TREE, id), NULL_TREE,
   10664           48 :                                  DECL_ATTRIBUTES (val));
   10665              :                 }
   10666              :             }
   10667              :         }
   10668    179891291 :     };
   10669              : 
   10670    230608649 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   10671              :     {
   10672         6152 :       gcc_assert (cand->num_convs > 0);
   10673         6152 :       tree object_arg = consume_object_arg ();
   10674         6152 :       val = handle_arg (TREE_VALUE (parm),
   10675              :                         object_arg,
   10676              :                         param_index++,
   10677         6152 :                         convs[conv_index++],
   10678              :                         complain);
   10679              : 
   10680         6152 :       if (val == error_mark_node)
   10681              :         return error_mark_node;
   10682              :       else
   10683              :         {
   10684         6040 :           argarray[argarray_size++] = val;
   10685         6040 :           handle_indeterminate_arg (parmd, val);
   10686              :         }
   10687         6040 :       parm = TREE_CHAIN (parm);
   10688         6040 :       if (parmd)
   10689         6040 :         parmd = DECL_CHAIN (parmd);
   10690              :     }
   10691              : 
   10692    230608537 :   gcc_assert (first_arg == NULL_TREE);
   10693    408861242 :   for (; arg_index < vec_safe_length (args) && parm;
   10694    178252705 :        parm = TREE_CHAIN (parm), ++arg_index, ++param_index, ++conv_index)
   10695              :     {
   10696    178254097 :       tree current_arg = (*args)[arg_index];
   10697              : 
   10698              :       /* If the argument is NULL and used to (implicitly) instantiate a
   10699              :          template function (and bind one of the template arguments to
   10700              :          the type of 'long int'), we don't want to warn about passing NULL
   10701              :          to non-pointer argument.
   10702              :          For example, if we have this template function:
   10703              : 
   10704              :            template<typename T> void func(T x) {}
   10705              : 
   10706              :          we want to warn (when -Wconversion is enabled) in this case:
   10707              : 
   10708              :            void foo() {
   10709              :              func<int>(NULL);
   10710              :            }
   10711              : 
   10712              :          but not in this case:
   10713              : 
   10714              :            void foo() {
   10715              :              func(NULL);
   10716              :            }
   10717              :       */
   10718    178254097 :       bool const conversion_warning = !(null_node_p (current_arg)
   10719        45005 :                                         && DECL_TEMPLATE_INFO (fn)
   10720           60 :                                         && cand->template_decl
   10721           30 :                                         && !cand->explicit_targs);
   10722              : 
   10723           15 :       tsubst_flags_t const arg_complain
   10724              :         = conversion_warning ? complain : complain & ~tf_warning;
   10725              : 
   10726    178254097 :       val = handle_arg (TREE_VALUE (parm),
   10727              :                         current_arg,
   10728              :                         param_index,
   10729    178254097 :                         convs[conv_index],
   10730              :                         arg_complain);
   10731              : 
   10732    178254097 :       if (val == error_mark_node)
   10733              :         return error_mark_node;
   10734              :       else
   10735              :         {
   10736    178252705 :           argarray[argarray_size++] = val;
   10737    178252705 :           handle_indeterminate_arg (parmd, val);
   10738              :         }
   10739    178252705 :       if (parmd)
   10740    166369053 :         parmd = DECL_CHAIN (parmd);
   10741              :     }
   10742              : 
   10743              :   /* Default arguments */
   10744    232239691 :   for (; parm && parm != void_list_node;
   10745      1632546 :        parm = TREE_CHAIN (parm), param_index++)
   10746              :     {
   10747      1632660 :       if (TREE_VALUE (parm) == error_mark_node)
   10748              :         return error_mark_node;
   10749      3265296 :       val = convert_default_arg (TREE_VALUE (parm),
   10750      1632648 :                                  TREE_PURPOSE (parm),
   10751              :                                  fn, param_index,
   10752              :                                  complain);
   10753      1632648 :       if (val == error_mark_node)
   10754              :         return error_mark_node;
   10755      1632546 :       argarray[argarray_size++] = val;
   10756      1632546 :       handle_indeterminate_arg (parmd, val);
   10757      1632546 :       if (parmd)
   10758      1632546 :         parmd = DECL_CHAIN (parmd);
   10759              :     }
   10760              : 
   10761              :   /* Ellipsis */
   10762    230607031 :   int magic = magic_varargs_p (fn);
   10763    233629235 :   for (; arg_index < vec_safe_length (args); ++arg_index)
   10764              :     {
   10765      3022225 :       tree a = (*args)[arg_index];
   10766      3022225 :       if ((magic == 3 && arg_index == 2) || (magic == 4 && arg_index == 0))
   10767              :         {
   10768              :           /* Do no conversions for certain magic varargs.  */
   10769       112527 :           a = mark_type_use (a);
   10770       112527 :           if (TREE_CODE (a) == FUNCTION_DECL && reject_gcc_builtin (a))
   10771            0 :             return error_mark_node;
   10772              :         }
   10773      2909698 :       else if (magic != 0)
   10774              :         {
   10775              :           /* Don't truncate excess precision to the semantic type.  */
   10776      1564897 :           if (magic == 1 && TREE_CODE (a) == EXCESS_PRECISION_EXPR)
   10777           84 :             a = TREE_OPERAND (a, 0);
   10778              :           /* For other magic varargs only do decay_conversion.  */
   10779      1564897 :           a = decay_conversion (a, complain);
   10780              :         }
   10781      1344801 :       else if (DECL_CONSTRUCTOR_P (fn)
   10782          336 :                && vec_safe_length (args) == 1
   10783      1344961 :                && same_type_ignoring_top_level_qualifiers_p (DECL_CONTEXT (fn),
   10784          160 :                                                              TREE_TYPE (a)))
   10785              :         {
   10786              :           /* Avoid infinite recursion trying to call A(...).  */
   10787            3 :           if (complain & tf_error)
   10788              :             /* Try to call the actual copy constructor for a good error.  */
   10789            3 :             call_copy_ctor (a, complain);
   10790            3 :           return error_mark_node;
   10791              :         }
   10792              :       else
   10793      1344798 :         a = convert_arg_to_ellipsis (a, complain);
   10794      3022222 :       if (a == error_mark_node)
   10795              :         return error_mark_node;
   10796      3022204 :       argarray[argarray_size++] = a;
   10797              :     }
   10798              : 
   10799    230607010 :   gcc_assert (argarray_size <= nargs);
   10800    230607010 :   nargs = argarray_size;
   10801    230607010 :   icip.reset ();
   10802              : 
   10803              :   /* Avoid performing argument transformation if warnings are disabled.
   10804              :      When tf_warning is set and at least one of the warnings is active
   10805              :      the check_function_arguments function might warn about something.  */
   10806              : 
   10807    230607010 :   bool warned_p = false;
   10808    230607010 :   if ((complain & tf_warning)
   10809    141041597 :       && (warn_nonnull
   10810    139118721 :           || warn_format
   10811    139118718 :           || warn_suggest_attribute_format
   10812    139118622 :           || warn_restrict))
   10813              :     {
   10814      1925222 :       tree *fargs = (!nargs ? argarray
   10815      1589629 :                             : (tree *) alloca (nargs * sizeof (tree)));
   10816      5877829 :       for (int j = 0; j < nargs; j++)
   10817              :         {
   10818              :           /* For -Wformat undo the implicit passing by hidden reference
   10819              :              done by convert_arg_to_ellipsis.  */
   10820      3952607 :           if (TREE_CODE (argarray[j]) == ADDR_EXPR
   10821      3952607 :               && TYPE_REF_P (TREE_TYPE (argarray[j])))
   10822         1490 :             fargs[j] = TREE_OPERAND (argarray[j], 0);
   10823              :           else
   10824      3951117 :             fargs[j] = argarray[j];
   10825              :         }
   10826              : 
   10827      1925222 :       warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn),
   10828              :                                            nargs, fargs, NULL,
   10829              :                                            cp_comp_parm_types);
   10830              :     }
   10831              : 
   10832    461214020 :   if (DECL_INHERITED_CTOR (fn))
   10833              :     {
   10834              :       /* Check for passing ellipsis arguments to an inherited constructor.  We
   10835              :          could handle this by open-coding the inherited constructor rather than
   10836              :          defining it, but let's not bother now.  */
   10837        76734 :       if (!cp_unevaluated_operand
   10838        76473 :           && cand->num_convs
   10839        76473 :           && cand->convs[cand->num_convs-1]->ellipsis_p)
   10840              :         {
   10841           15 :           if (complain & tf_error)
   10842              :             {
   10843           15 :               sorry ("passing arguments to ellipsis of inherited constructor "
   10844              :                      "%qD", cand->fn);
   10845           15 :               inform (DECL_SOURCE_LOCATION (cand->fn), "declared here");
   10846              :             }
   10847           15 :           return error_mark_node;
   10848              :         }
   10849              : 
   10850              :       /* A base constructor inheriting from a virtual base doesn't get the
   10851              :          inherited arguments, just this and __vtt.  */
   10852        76719 :       if (ctor_omit_inherited_parms (fn))
   10853    230606995 :         nargs = 2;
   10854              :     }
   10855              : 
   10856              :   /* Avoid actually calling copy constructors and copy assignment operators,
   10857              :      if possible.  */
   10858              : 
   10859    230606995 :   if (!force_elide
   10860    230478590 :       && (!flag_elide_constructors
   10861              :           /* It's unsafe to elide the operation when handling
   10862              :              a noexcept-expression, it may evaluate to the wrong
   10863              :              value (c++/53025, c++/96090).  */
   10864    230478386 :           || cp_noexcept_operand != 0))
   10865              :     /* Do things the hard way.  */;
   10866    226886251 :   else if (cand->num_convs == 1
   10867    343999852 :            && (DECL_COPY_CONSTRUCTOR_P (fn)
   10868    216991720 :                || DECL_MOVE_CONSTRUCTOR_P (fn)))
   10869              :     {
   10870     11546905 :       tree targ;
   10871     11546905 :       tree arg = argarray[num_artificial_parms_for (fn)];
   10872     11546905 :       tree fa = argarray[0];
   10873     11546905 :       bool trivial = trivial_fn_p (fn);
   10874              : 
   10875              :       /* Pull out the real argument, disregarding const-correctness.  */
   10876     11546905 :       targ = arg;
   10877              :       /* Strip the reference binding for the constructor parameter.  */
   10878            0 :       if (CONVERT_EXPR_P (targ)
   10879     11546905 :           && TYPE_REF_P (TREE_TYPE (targ)))
   10880     11546905 :         targ = TREE_OPERAND (targ, 0);
   10881              :       /* But don't strip any other reference bindings; binding a temporary to a
   10882              :          reference prevents copy elision.  */
   10883     18458210 :       while ((CONVERT_EXPR_P (targ)
   10884     16233370 :               && !TYPE_REF_P (TREE_TYPE (targ)))
   10885     39417428 :              || TREE_CODE (targ) == NON_LVALUE_EXPR)
   10886     14458107 :         targ = TREE_OPERAND (targ, 0);
   10887     11546905 :       if (TREE_CODE (targ) == ADDR_EXPR)
   10888              :         {
   10889      4302833 :           targ = TREE_OPERAND (targ, 0);
   10890      4302833 :           if (!same_type_ignoring_top_level_qualifiers_p
   10891      4302833 :               (TREE_TYPE (TREE_TYPE (arg)), TREE_TYPE (targ)))
   10892              :             targ = NULL_TREE;
   10893              :         }
   10894              :       else
   10895              :         targ = NULL_TREE;
   10896              : 
   10897      4302370 :       if (targ)
   10898              :         arg = targ;
   10899              :       else
   10900      7244535 :         arg = cp_build_fold_indirect_ref (arg);
   10901              : 
   10902              :       /* In C++17 we shouldn't be copying a TARGET_EXPR except into a
   10903              :          potentially-overlapping subobject.  */
   10904     11546905 :       if (CHECKING_P && cxx_dialect >= cxx17)
   10905     11473205 :         gcc_assert (TREE_CODE (arg) != TARGET_EXPR
   10906              :                     || force_elide
   10907              :                     /* It's from binding the ref parm to a packed field. */
   10908              :                     || convs[0]->need_temporary_p
   10909              :                     || seen_error ()
   10910              :                     /* See unsafe_copy_elision_p.  */
   10911              :                     || unsafe_return_slot_p (fa));
   10912              : 
   10913     11546905 :       bool unsafe = unsafe_copy_elision_p_opt (fa, arg);
   10914     11546905 :       bool eliding_temp = (TREE_CODE (arg) == TARGET_EXPR && !unsafe);
   10915              : 
   10916              :       /* [class.copy]: the copy constructor is implicitly defined even if the
   10917              :          implementation elided its use.  But don't warn about deprecation when
   10918              :          eliding a temporary, as then no copy is actually performed.  */
   10919     11546905 :       warning_sentinel s (warn_deprecated_copy, eliding_temp);
   10920     11546905 :       if (force_elide)
   10921              :         /* The language says this isn't called.  */;
   10922     11418500 :       else if (!trivial)
   10923              :         {
   10924      1313922 :           if (!mark_used (fn, complain) && !(complain & tf_error))
   10925            0 :             return error_mark_node;
   10926              :           already_used = true;
   10927              :         }
   10928              :       else
   10929     10104578 :         cp_handle_deprecated_or_unavailable (fn, complain);
   10930              : 
   10931       185753 :       if (eliding_temp && DECL_BASE_CONSTRUCTOR_P (fn)
   10932     11547086 :           && !make_base_init_ok (arg))
   10933              :         unsafe = true;
   10934              : 
   10935              :       /* If we're creating a temp and we already have one, don't create a
   10936              :          new one.  If we're not creating a temp but we get one, use
   10937              :          INIT_EXPR to collapse the temp into our target.  Otherwise, if the
   10938              :          ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
   10939              :          temp or an INIT_EXPR otherwise.  */
   10940     11546905 :       if (is_dummy_object (fa))
   10941              :         {
   10942      9000221 :           if (TREE_CODE (arg) == TARGET_EXPR)
   10943              :             return arg;
   10944      8844106 :           else if (trivial)
   10945      8258186 :             return force_target_expr (DECL_CONTEXT (fn), arg, complain);
   10946              :         }
   10947      2546684 :       else if ((trivial || TREE_CODE (arg) == TARGET_EXPR)
   10948      1824776 :                && !unsafe)
   10949              :         {
   10950      1824688 :           tree to = cp_build_fold_indirect_ref (fa);
   10951      1824688 :           val = cp_build_init_expr (to, arg);
   10952      1824688 :           return val;
   10953              :         }
   10954     11546905 :     }
   10955    215339346 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
   10956      5953955 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR)
   10957    220139580 :            && trivial_fn_p (fn))
   10958              :     {
   10959      3807620 :       tree to = cp_build_fold_indirect_ref (argarray[0]);
   10960      3807620 :       tree type = TREE_TYPE (to);
   10961      3807620 :       tree as_base = CLASSTYPE_AS_BASE (type);
   10962      3807620 :       tree arg = argarray[1];
   10963      3807620 :       location_t loc = cp_expr_loc_or_input_loc (arg);
   10964              : 
   10965      3807620 :       if (is_really_empty_class (type, /*ignore_vptr*/true))
   10966              :         {
   10967              :           /* Avoid copying empty classes, but ensure op= returns an lvalue even
   10968              :              if the object argument isn't one.  */
   10969       232995 :           to = force_lvalue (to, complain);
   10970       232995 :           val = build2 (COMPOUND_EXPR, type, arg, to);
   10971       232995 :           suppress_warning (val, OPT_Wunused);
   10972              :         }
   10973      3574625 :       else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
   10974              :         {
   10975      3103001 :           if (is_std_init_list (type)
   10976      3103001 :               && conv_binds_ref_to_prvalue (convs[1]))
   10977            3 :             warning_at (loc, OPT_Winit_list_lifetime,
   10978              :                         "assignment from temporary %<initializer_list%> does "
   10979              :                         "not extend the lifetime of the underlying array");
   10980      3103001 :           arg = cp_build_fold_indirect_ref (arg);
   10981      3103001 :           val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
   10982              :         }
   10983              :       else
   10984              :         {
   10985              :           /* We must only copy the non-tail padding parts.  */
   10986       471624 :           tree arg0, arg2, t;
   10987       471624 :           tree array_type, alias_set;
   10988              : 
   10989       471624 :           arg2 = TYPE_SIZE_UNIT (as_base);
   10990              :           /* Ensure op= returns an lvalue even if the object argument isn't
   10991              :              one.  */
   10992       471624 :           to = force_lvalue (to, complain);
   10993       471624 :           to = cp_stabilize_reference (to);
   10994       471624 :           arg0 = cp_build_addr_expr (to, complain);
   10995              : 
   10996       471624 :           array_type = build_array_type (unsigned_char_type_node,
   10997              :                                          build_index_type
   10998              :                                            (size_binop (MINUS_EXPR,
   10999              :                                                         arg2, size_int (1))));
   11000       471624 :           alias_set = build_int_cst (build_pointer_type (type), 0);
   11001       471624 :           t = build2 (MODIFY_EXPR, void_type_node,
   11002              :                       build2 (MEM_REF, array_type, arg0, alias_set),
   11003              :                       build2 (MEM_REF, array_type, arg, alias_set));
   11004       471624 :           val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to);
   11005       471624 :           suppress_warning (val, OPT_Wunused);
   11006              :         }
   11007              : 
   11008      3807620 :       cp_handle_deprecated_or_unavailable (fn, complain);
   11009              : 
   11010      3807620 :       return val;
   11011              :     }
   11012    211531726 :   else if (trivial_fn_p (fn))
   11013              :     {
   11014      8018316 :       if (DECL_DESTRUCTOR_P (fn))
   11015      3211705 :         return build_trivial_dtor_call (argarray[0]);
   11016       797453 :       else if (default_ctor_p (fn))
   11017              :         {
   11018       797453 :           if (is_dummy_object (argarray[0]))
   11019       260917 :             return force_target_expr (DECL_CONTEXT (fn), void_node,
   11020       260917 :                                       no_cleanup_complain);
   11021              :           else
   11022       536536 :             return cp_build_fold_indirect_ref (argarray[0]);
   11023              :         }
   11024              :     }
   11025              : 
   11026    212551228 :   gcc_assert (!force_elide);
   11027              : 
   11028    212551228 :   if (!already_used
   11029    212551228 :       && !mark_used (fn, complain))
   11030          773 :     return error_mark_node;
   11031              : 
   11032              :   /* Warn if the built-in writes to an object of a non-trivial type.  */
   11033    212550452 :   if (warn_class_memaccess
   11034      1951864 :       && vec_safe_length (args) >= 2
   11035    213502332 :       && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
   11036        68410 :     maybe_warn_class_memaccess (input_location, fn, args);
   11037              : 
   11038    212550452 :   if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
   11039              :     {
   11040       703513 :       tree t;
   11041       703513 :       tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (argarray[0])),
   11042       703513 :                                 DECL_CONTEXT (fn),
   11043              :                                 ba_any, NULL, complain);
   11044       703513 :       gcc_assert (binfo && binfo != error_mark_node);
   11045              : 
   11046       703513 :       argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1,
   11047              :                                      complain);
   11048       703513 :       if (TREE_SIDE_EFFECTS (argarray[0]))
   11049        44368 :         argarray[0] = save_expr (argarray[0]);
   11050       703513 :       t = build_pointer_type (TREE_TYPE (fn));
   11051       703513 :       fn = build_vfn_ref (argarray[0], DECL_VINDEX (fn));
   11052       703513 :       TREE_TYPE (fn) = t;
   11053              :     }
   11054              :   else
   11055              :     {
   11056              :       /* If FN is marked deprecated or unavailable, then we've already
   11057              :          issued a diagnostic from mark_used above, so avoid redundantly
   11058              :          issuing another one from build_addr_func.  */
   11059    211846939 :       auto w = make_temp_override (deprecated_state,
   11060    211846939 :                                    UNAVAILABLE_DEPRECATED_SUPPRESS);
   11061              : 
   11062    211846939 :       fn = build_addr_func (fn, complain);
   11063    211846939 :       if (fn == error_mark_node)
   11064            0 :         return error_mark_node;
   11065              : 
   11066              :       /* We're actually invoking the function.  (Immediate functions get an
   11067              :          & when invoking it even though the user didn't use &.)  */
   11068    211846939 :       ADDR_EXPR_DENOTES_CALL_P (fn) = true;
   11069    211846939 :     }
   11070              : 
   11071    212550452 :   tree call = build_cxx_call (fn, nargs, argarray, complain|decltype_flag);
   11072    212550452 :   if (call == error_mark_node)
   11073              :     return call;
   11074    212549601 :   if (cand->flags & LOOKUP_LIST_INIT_CTOR)
   11075              :     {
   11076      2128975 :       tree c = extract_call_expr (call);
   11077              :       /* build_new_op will clear this when appropriate.  */
   11078      2128975 :       CALL_EXPR_ORDERED_ARGS (c) = true;
   11079              :     }
   11080    212549601 :   if (warned_p)
   11081              :     {
   11082          253 :       tree c = extract_call_expr (call);
   11083          253 :       if (TREE_CODE (c) == CALL_EXPR)
   11084          253 :         suppress_warning (c /* Suppress all warnings.  */);
   11085              :     }
   11086    212549348 :   else if (TREE_DEPRECATED (fn)
   11087    212549348 :            && warning_suppressed_at (input_location,
   11088              :                                      OPT_Wdeprecated_declarations))
   11089              :     {
   11090            0 :       tree c = extract_call_expr (call);
   11091            0 :       if (TREE_CODE (c) == CALL_EXPR)
   11092            0 :         TREE_NO_WARNING (c) = true;
   11093              :     }
   11094              : 
   11095              :   return call;
   11096              : }
   11097              : 
   11098              : namespace
   11099              : {
   11100              : 
   11101              : /* Return the DECL of the first non-static subobject of class TYPE
   11102              :    that satisfies the predicate PRED or null if none can be found.  */
   11103              : 
   11104              : template <class Predicate>
   11105              : tree
   11106         3548 : first_non_static_field (tree type, Predicate pred)
   11107              : {
   11108         3548 :   if (!type || !CLASS_TYPE_P (type))
   11109              :     return NULL_TREE;
   11110              : 
   11111        71038 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   11112              :     {
   11113        68084 :       if (TREE_CODE (field) != FIELD_DECL)
   11114        43234 :         continue;
   11115        24850 :       if (TREE_STATIC (field))
   11116            0 :         continue;
   11117        24850 :       if (pred (field))
   11118              :         return field;
   11119              :     }
   11120              : 
   11121         2954 :   int i = 0;
   11122              : 
   11123         3074 :   for (tree base_binfo, binfo = TYPE_BINFO (type);
   11124         3074 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   11125              :     {
   11126          126 :       tree base = TREE_TYPE (base_binfo);
   11127          126 :       if (pred (base))
   11128              :         return base;
   11129          120 :       if (tree field = first_non_static_field (base, pred))
   11130              :         return field;
   11131              :     }
   11132              : 
   11133              :   return NULL_TREE;
   11134              : }
   11135              : 
   11136              : struct NonPublicField
   11137              : {
   11138        24100 :   bool operator() (const_tree t) const
   11139              :   {
   11140        24100 :     return DECL_P (t) && (TREE_PRIVATE (t) || TREE_PROTECTED (t));
   11141              :   }
   11142              : };
   11143              : 
   11144              : /* Return the DECL of the first non-public subobject of class TYPE
   11145              :    or null if none can be found.  */
   11146              : 
   11147              : static inline tree
   11148         3254 : first_non_public_field (tree type)
   11149              : {
   11150         3254 :   return first_non_static_field (type, NonPublicField ());
   11151              : }
   11152              : 
   11153              : struct NonTrivialField
   11154              : {
   11155          876 :   bool operator() (const_tree t) const
   11156              :   {
   11157          876 :     return !trivial_type_p (DECL_P (t) ? TREE_TYPE (t) : t);
   11158              :   }
   11159              : };
   11160              : 
   11161              : /* Return the DECL of the first non-trivial subobject of class TYPE
   11162              :    or null if none can be found.  */
   11163              : 
   11164              : static inline tree
   11165          174 : first_non_trivial_field (tree type)
   11166              : {
   11167          174 :   return first_non_static_field (type, NonTrivialField ());
   11168              : }
   11169              : 
   11170              : }   /* unnamed namespace */
   11171              : 
   11172              : /* Return true if all copy and move assignment operator overloads for
   11173              :    class TYPE are trivial and at least one of them is not deleted and,
   11174              :    when ACCESS is set, accessible.  Return false otherwise.  Set
   11175              :    HASASSIGN to true when the TYPE has a (not necessarily trivial)
   11176              :    copy or move assignment.  */
   11177              : 
   11178              : static bool
   11179         5013 : has_trivial_copy_assign_p (tree type, bool access, bool *hasassign)
   11180              : {
   11181         5013 :   tree fns = get_class_binding (type, assign_op_identifier);
   11182         5013 :   bool all_trivial = true;
   11183              : 
   11184              :   /* Iterate over overloads of the assignment operator, checking
   11185              :      accessible copy assignments for triviality.  */
   11186              : 
   11187        16483 :   for (tree f : ovl_range (fns))
   11188              :     {
   11189              :       /* Skip operators that aren't copy assignments.  */
   11190         8555 :       if (!copy_fn_p (f))
   11191         3038 :         continue;
   11192              : 
   11193         5517 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11194         5805 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11195              : 
   11196              :       /* Skip template assignment operators and deleted functions.  */
   11197         5517 :       if (TREE_CODE (f) != FUNCTION_DECL || DECL_DELETED_FN (f))
   11198          694 :         continue;
   11199              : 
   11200         4823 :       if (accessible)
   11201         4571 :         *hasassign = true;
   11202              : 
   11203         4571 :       if (!accessible || !trivial_fn_p (f))
   11204              :         all_trivial = false;
   11205              : 
   11206              :       /* Break early when both properties have been determined.  */
   11207         4823 :       if (*hasassign && !all_trivial)
   11208              :         break;
   11209              :     }
   11210              : 
   11211              :   /* Return true if they're all trivial and one of the expressions
   11212              :      TYPE() = TYPE() or TYPE() = (TYPE&)() is valid.  */
   11213         5013 :   tree ref = cp_build_reference_type (type, false);
   11214         5013 :   return (all_trivial
   11215         5013 :           && (is_trivially_xible (MODIFY_EXPR, type, type)
   11216          333 :               || is_trivially_xible (MODIFY_EXPR, type, ref)));
   11217              : }
   11218              : 
   11219              : /* Return true if all copy and move ctor overloads for class TYPE are
   11220              :    trivial and at least one of them is not deleted and, when ACCESS is
   11221              :    set, accessible.  Return false otherwise.  Set each element of HASCTOR[]
   11222              :    to true when the TYPE has a (not necessarily trivial) default and copy
   11223              :    (or move) ctor, respectively.  */
   11224              : 
   11225              : static bool
   11226         5013 : has_trivial_copy_p (tree type, bool access, bool hasctor[2])
   11227              : {
   11228         5013 :   tree fns = get_class_binding (type, complete_ctor_identifier);
   11229         5013 :   bool all_trivial = true;
   11230              : 
   11231        25093 :   for (tree f : ovl_range (fns))
   11232              :     {
   11233              :       /* Skip template constructors.  */
   11234        12578 :       if (TREE_CODE (f) != FUNCTION_DECL)
   11235          105 :         continue;
   11236              : 
   11237        12473 :       bool cpy_or_move_ctor_p = copy_fn_p (f);
   11238              : 
   11239              :       /* Skip ctors other than default, copy, and move.  */
   11240        12473 :       if (!cpy_or_move_ctor_p && !default_ctor_p (f))
   11241         2749 :         continue;
   11242              : 
   11243         9724 :       if (DECL_DELETED_FN (f))
   11244          306 :         continue;
   11245              : 
   11246         9418 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11247         9610 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11248              : 
   11249         9298 :       if (accessible)
   11250         9298 :         hasctor[cpy_or_move_ctor_p] = true;
   11251              : 
   11252         9418 :       if (cpy_or_move_ctor_p && (!accessible || !trivial_fn_p (f)))
   11253              :         all_trivial = false;
   11254              : 
   11255              :       /* Break early when both properties have been determined.  */
   11256         9418 :       if (hasctor[0] && hasctor[1] && !all_trivial)
   11257              :         break;
   11258              :     }
   11259              : 
   11260         5013 :   return all_trivial;
   11261              : }
   11262              : 
   11263              : /* Issue a warning on a call to the built-in function FNDECL if it is
   11264              :    a raw memory write whose destination is not an object of (something
   11265              :    like) trivial or standard layout type with a non-deleted assignment
   11266              :    and copy ctor.  Detects const correctness violations, corrupting
   11267              :    references, virtual table pointers, and bypassing non-trivial
   11268              :    assignments.  */
   11269              : 
   11270              : static void
   11271        68410 : maybe_warn_class_memaccess (location_t loc, tree fndecl,
   11272              :                             const vec<tree, va_gc> *args)
   11273              : {
   11274              :   /* Except for bcopy where it's second, the destination pointer is
   11275              :      the first argument for all functions handled here.  Compute
   11276              :      the index of the destination and source arguments.  */
   11277        68410 :   unsigned dstidx = DECL_FUNCTION_CODE (fndecl) == BUILT_IN_BCOPY;
   11278        68410 :   unsigned srcidx = !dstidx;
   11279              : 
   11280        68410 :   tree dest = (*args)[dstidx];
   11281        68410 :   if (!TREE_TYPE (dest)
   11282        68410 :       || (TREE_CODE (TREE_TYPE (dest)) != ARRAY_TYPE
   11283        67253 :           && !INDIRECT_TYPE_P (TREE_TYPE (dest))))
   11284        65035 :     return;
   11285              : 
   11286        22002 :   tree srctype = NULL_TREE;
   11287              : 
   11288              :   /* Determine the type of the pointed-to object and whether it's
   11289              :      a complete class type.  */
   11290        22002 :   tree desttype = TREE_TYPE (TREE_TYPE (dest));
   11291              : 
   11292        22002 :   if (!desttype || !COMPLETE_TYPE_P (desttype) || !CLASS_TYPE_P (desttype))
   11293              :     return;
   11294              : 
   11295              :   /* Check to see if the raw memory call is made by a non-static member
   11296              :      function with THIS as the destination argument for the destination
   11297              :      type.  If so, and if the class has no non-trivial bases or members,
   11298              :      be more permissive.  */
   11299         5115 :   if (current_function_decl
   11300         5115 :       && DECL_OBJECT_MEMBER_FUNCTION_P (current_function_decl)
   11301         5382 :       && is_object_parameter (tree_strip_nop_conversions (dest)))
   11302              :     {
   11303          204 :       tree ctx = DECL_CONTEXT (current_function_decl);
   11304          204 :       bool special = same_type_ignoring_top_level_qualifiers_p (ctx, desttype);
   11305          204 :       tree binfo = TYPE_BINFO (ctx);
   11306              : 
   11307          204 :       if (special
   11308          204 :           && !BINFO_VTABLE (binfo)
   11309          378 :           && !first_non_trivial_field (desttype))
   11310              :         return;
   11311              :     }
   11312              : 
   11313              :   /* True if the class is trivial.  */
   11314         5013 :   bool trivial = trivial_type_p (desttype);
   11315              : 
   11316              :   /* Set to true if DESTYPE has an accessible copy assignment.  */
   11317         5013 :   bool hasassign = false;
   11318              :   /* True if all of the class' overloaded copy assignment operators
   11319              :      are all trivial (and not deleted) and at least one of them is
   11320              :      accessible.  */
   11321         5013 :   bool trivassign = has_trivial_copy_assign_p (desttype, true, &hasassign);
   11322              : 
   11323              :   /* Set to true if DESTTYPE has an accessible default and copy ctor,
   11324              :      respectively.  */
   11325         5013 :   bool hasctors[2] = { false, false };
   11326              : 
   11327              :   /* True if all of the class' overloaded copy constructors are all
   11328              :      trivial (and not deleted) and at least one of them is accessible.  */
   11329         5013 :   bool trivcopy = has_trivial_copy_p (desttype, true, hasctors);
   11330              : 
   11331              :   /* Set FLD to the first private/protected member of the class.  */
   11332         5013 :   tree fld = trivial ? first_non_public_field (desttype) : NULL_TREE;
   11333              : 
   11334              :   /* The warning format string.  */
   11335         5013 :   const char *warnfmt = NULL;
   11336              :   /* A suggested alternative to offer instead of the raw memory call.
   11337              :      Empty string when none can be come up with.  */
   11338         5013 :   const char *suggest = "";
   11339         5013 :   bool warned = false;
   11340              : 
   11341         5013 :   switch (DECL_FUNCTION_CODE (fndecl))
   11342              :     {
   11343          560 :     case BUILT_IN_MEMSET:
   11344          560 :       if (!integer_zerop (maybe_constant_value ((*args)[1])))
   11345              :         {
   11346              :           /* Diagnose setting non-copy-assignable or non-trivial types,
   11347              :              or types with a private member, to (potentially) non-zero
   11348              :              bytes.  Since the value of the bytes being written is unknown,
   11349              :              suggest using assignment instead (if one exists).  Also warn
   11350              :              for writes into objects for which zero-initialization doesn't
   11351              :              mean all bits clear (pointer-to-member data, where null is all
   11352              :              bits set).  Since the value being written is (most likely)
   11353              :              non-zero, simply suggest assignment (but not copy assignment).  */
   11354          196 :           suggest = "; use assignment instead";
   11355          196 :           if (!trivassign)
   11356              :             warnfmt = G_("%qD writing to an object of type %#qT with "
   11357              :                          "no trivial copy-assignment");
   11358          125 :           else if (!trivial)
   11359              :             warnfmt = G_("%qD writing to an object of non-trivial type %#qT%s");
   11360           85 :           else if (fld)
   11361              :             {
   11362           24 :               const char *access = TREE_PRIVATE (fld) ? "private" : "protected";
   11363           24 :               warned = warning_at (loc, OPT_Wclass_memaccess,
   11364              :                                    "%qD writing to an object of type %#qT with "
   11365              :                                    "%qs member %qD",
   11366              :                                    fndecl, desttype, access, fld);
   11367              :             }
   11368           61 :           else if (!zero_init_p (desttype))
   11369              :             warnfmt = G_("%qD writing to an object of type %#qT containing "
   11370              :                          "a pointer to data member%s");
   11371              : 
   11372              :           break;
   11373              :         }
   11374              :       /* Fall through.  */
   11375              : 
   11376          481 :     case BUILT_IN_BZERO:
   11377              :       /* Similarly to the above, diagnose clearing non-trivial or non-
   11378              :          standard layout objects, or objects of types with no assignmenmt.
   11379              :          Since the value being written is known to be zero, suggest either
   11380              :          copy assignment, copy ctor, or default ctor as an alternative,
   11381              :          depending on what's available.  */
   11382              : 
   11383          481 :       if (hasassign && hasctors[0])
   11384              :         suggest = G_("; use assignment or value-initialization instead");
   11385           49 :       else if (hasassign)
   11386              :         suggest = G_("; use assignment instead");
   11387           31 :       else if (hasctors[0])
   11388           16 :         suggest = G_("; use value-initialization instead");
   11389              : 
   11390          481 :       if (!trivassign)
   11391              :         warnfmt = G_("%qD clearing an object of type %#qT with "
   11392              :                      "no trivial copy-assignment%s");
   11393          374 :       else if (!trivial)
   11394              :         warnfmt =  G_("%qD clearing an object of non-trivial type %#qT%s");
   11395          304 :       else if (!zero_init_p (desttype))
   11396              :         warnfmt = G_("%qD clearing an object of type %#qT containing "
   11397              :                      "a pointer-to-member%s");
   11398              :       break;
   11399              : 
   11400         2437 :     case BUILT_IN_BCOPY:
   11401         2437 :     case BUILT_IN_MEMCPY:
   11402         2437 :     case BUILT_IN_MEMMOVE:
   11403         2437 :     case BUILT_IN_MEMPCPY:
   11404              :       /* Determine the type of the source object.  */
   11405         2437 :       srctype = TREE_TYPE ((*args)[srcidx]);
   11406         2437 :       if (!srctype || !INDIRECT_TYPE_P (srctype))
   11407            0 :         srctype = void_type_node;
   11408              :       else
   11409         2437 :         srctype = TREE_TYPE (srctype);
   11410              : 
   11411              :       /* Since it's impossible to determine wheter the byte copy is
   11412              :          being used in place of assignment to an existing object or
   11413              :          as a substitute for initialization, assume it's the former.
   11414              :          Determine the best alternative to use instead depending on
   11415              :          what's not deleted.  */
   11416         2437 :       if (hasassign && hasctors[1])
   11417              :         suggest = G_("; use copy-assignment or copy-initialization instead");
   11418          488 :       else if (hasassign)
   11419              :         suggest = G_("; use copy-assignment instead");
   11420          341 :       else if (hasctors[1])
   11421          290 :         suggest = G_("; use copy-initialization instead");
   11422              : 
   11423         2437 :       if (!trivassign)
   11424              :         warnfmt = G_("%qD writing to an object of type %#qT with no trivial "
   11425              :                      "copy-assignment%s");
   11426         1639 :       else if (!trivially_copyable_p (desttype))
   11427              :         warnfmt = G_("%qD writing to an object of non-trivially copyable "
   11428              :                      "type %#qT%s");
   11429         1315 :       else if (!trivcopy)
   11430              :         warnfmt = G_("%qD writing to an object with a deleted copy constructor");
   11431              : 
   11432         1315 :       else if (!trivial
   11433          211 :                && !VOID_TYPE_P (srctype)
   11434          160 :                && !is_byte_access_type (srctype)
   11435         1412 :                && !same_type_ignoring_top_level_qualifiers_p (desttype,
   11436              :                                                               srctype))
   11437              :         {
   11438              :           /* Warn when copying into a non-trivial object from an object
   11439              :              of a different type other than void or char.  */
   11440           54 :           warned = warning_at (loc, OPT_Wclass_memaccess,
   11441              :                                "%qD copying an object of non-trivial type "
   11442              :                                "%#qT from an array of %#qT",
   11443              :                                fndecl, desttype, srctype);
   11444              :         }
   11445         1261 :       else if (fld
   11446          432 :                && !VOID_TYPE_P (srctype)
   11447          384 :                && !is_byte_access_type (srctype)
   11448         1549 :                && !same_type_ignoring_top_level_qualifiers_p (desttype,
   11449              :                                                               srctype))
   11450              :         {
   11451          216 :           const char *access = TREE_PRIVATE (fld) ? "private" : "protected";
   11452          216 :           warned = warning_at (loc, OPT_Wclass_memaccess,
   11453              :                                "%qD copying an object of type %#qT with "
   11454              :                                "%qs member %qD from an array of %#qT; use "
   11455              :                                "assignment or copy-initialization instead",
   11456              :                                fndecl, desttype, access, fld, srctype);
   11457              :         }
   11458         1045 :       else if (!trivial && vec_safe_length (args) > 2)
   11459              :         {
   11460          157 :           tree sz = maybe_constant_value ((*args)[2]);
   11461          157 :           if (!tree_fits_uhwi_p (sz))
   11462              :             break;
   11463              : 
   11464              :           /* Finally, warn on partial copies.  */
   11465           99 :           unsigned HOST_WIDE_INT typesize
   11466           99 :             = tree_to_uhwi (TYPE_SIZE_UNIT (desttype));
   11467           99 :           if (typesize == 0)
   11468              :             break;
   11469           96 :           if (unsigned HOST_WIDE_INT partial = tree_to_uhwi (sz) % typesize)
   11470           12 :             warned = warning_at (loc, OPT_Wclass_memaccess,
   11471              :                                  (typesize - partial > 1
   11472              :                                   ? G_("%qD writing to an object of "
   11473              :                                        "a non-trivial type %#qT leaves %wu "
   11474              :                                        "bytes unchanged")
   11475              :                                   : G_("%qD writing to an object of "
   11476              :                                        "a non-trivial type %#qT leaves %wu "
   11477              :                                        "byte unchanged")),
   11478              :                                  fndecl, desttype, typesize - partial);
   11479              :         }
   11480              :       break;
   11481              : 
   11482          261 :     case BUILT_IN_REALLOC:
   11483              : 
   11484          261 :       if (!trivially_copyable_p (desttype))
   11485              :         warnfmt = G_("%qD moving an object of non-trivially copyable type "
   11486              :                      "%#qT; use %<new%> and %<delete%> instead");
   11487          138 :       else if (!trivcopy)
   11488              :         warnfmt = G_("%qD moving an object of type %#qT with deleted copy "
   11489              :                      "constructor; use %<new%> and %<delete%> instead");
   11490          135 :       else if (!get_dtor (desttype, tf_none))
   11491              :         warnfmt = G_("%qD moving an object of type %#qT with deleted "
   11492              :                      "destructor");
   11493          126 :       else if (!trivial)
   11494              :         {
   11495           33 :           tree sz = maybe_constant_value ((*args)[1]);
   11496           33 :           if (TREE_CODE (sz) == INTEGER_CST
   11497           33 :               && tree_int_cst_lt (sz, TYPE_SIZE_UNIT (desttype)))
   11498              :             /* Finally, warn on reallocation into insufficient space.  */
   11499            7 :             warned = warning_at (loc, OPT_Wclass_memaccess,
   11500              :                                  "%qD moving an object of non-trivial type "
   11501              :                                  "%#qT and size %E into a region of size %E",
   11502            7 :                                  fndecl, desttype, TYPE_SIZE_UNIT (desttype),
   11503              :                                  sz);
   11504              :         }
   11505              :       break;
   11506              : 
   11507              :     default:
   11508              :       return;
   11509              :     }
   11510              : 
   11511          310 :   if (warnfmt)
   11512              :     {
   11513         1569 :       if (suggest)
   11514         1569 :         warned = warning_at (loc, OPT_Wclass_memaccess,
   11515              :                              warnfmt, fndecl, desttype, suggest);
   11516              :       else
   11517              :         warned = warning_at (loc, OPT_Wclass_memaccess,
   11518              :                              warnfmt, fndecl, desttype);
   11519              :     }
   11520              : 
   11521         3375 :   if (warned)
   11522         1879 :     inform (location_of (desttype), "%#qT declared here", desttype);
   11523              : }
   11524              : 
   11525              : /* Build and return a call to FN, using NARGS arguments in ARGARRAY.
   11526              :    If FN is the result of resolving an overloaded target built-in,
   11527              :    ORIG_FNDECL is the original function decl, otherwise it is null.
   11528              :    This function performs no overload resolution, conversion, or other
   11529              :    high-level operations.  */
   11530              : 
   11531              : tree
   11532    221768603 : build_cxx_call (tree fn, int nargs, tree *argarray,
   11533              :                 tsubst_flags_t complain, tree orig_fndecl)
   11534              : {
   11535    221768603 :   tree fndecl;
   11536              : 
   11537              :   /* Remember roughly where this call is.  */
   11538    221768603 :   location_t loc = cp_expr_loc_or_input_loc (fn);
   11539    221768603 :   fn = build_call_a (fn, nargs, argarray);
   11540    221768603 :   SET_EXPR_LOCATION (fn, loc);
   11541              : 
   11542    221768603 :   fndecl = get_callee_fndecl (fn);
   11543    221768603 :   if (!orig_fndecl)
   11544    221768603 :     orig_fndecl = fndecl;
   11545              : 
   11546              :   /* Check that arguments to builtin functions match the expectations.  */
   11547    221768603 :   if (fndecl
   11548    214390776 :       && !processing_template_decl
   11549    436108106 :       && fndecl_built_in_p (fndecl))
   11550              :     {
   11551              :       int i;
   11552              : 
   11553              :       /* We need to take care that values to BUILT_IN_NORMAL
   11554              :          are reduced.  */
   11555     23860965 :       for (i = 0; i < nargs; i++)
   11556     15418541 :         argarray[i] = maybe_constant_value (argarray[i]);
   11557              : 
   11558      8442424 :       if (!check_builtin_function_arguments (EXPR_LOCATION (fn), vNULL, fndecl,
   11559              :                                              orig_fndecl, nargs, argarray,
   11560              :                                              complain & tf_error))
   11561          804 :         return error_mark_node;
   11562      8441620 :       else if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING))
   11563              :         {
   11564        12676 :           tree arg0 = argarray[0];
   11565        12676 :           STRIP_NOPS (arg0);
   11566        12676 :           if (TREE_CODE (arg0) == ADDR_EXPR
   11567          264 :               && DECL_P (TREE_OPERAND (arg0, 0))
   11568        12919 :               && same_type_ignoring_top_level_qualifiers_p
   11569          243 :                         (TREE_TYPE (TREE_TYPE (argarray[0])),
   11570          243 :                          TREE_TYPE (TREE_TYPE (arg0))))
   11571              :             /* For __builtin_clear_padding (&var) we know the type
   11572              :                is for a complete object, so there is no risk in clearing
   11573              :                padding that is reused in some derived class member.  */;
   11574        12440 :           else if (!trivially_copyable_p (TREE_TYPE (TREE_TYPE (argarray[0]))))
   11575              :             {
   11576           18 :               error_at (EXPR_LOC_OR_LOC (argarray[0], input_location),
   11577              :                         "argument %u in call to function %qE "
   11578              :                         "has pointer to a non-trivially-copyable type (%qT)",
   11579           18 :                         1, fndecl, TREE_TYPE (argarray[0]));
   11580           18 :               return error_mark_node;
   11581              :             }
   11582              :         }
   11583              :     }
   11584              : 
   11585    221767781 :   if (VOID_TYPE_P (TREE_TYPE (fn)))
   11586     44162244 :     return maybe_contract_wrap_call (fndecl, fn);
   11587              : 
   11588              :   /* 5.2.2/11: If a function call is a prvalue of object type: if the
   11589              :      function call is either the operand of a decltype-specifier or the
   11590              :      right operand of a comma operator that is the operand of a
   11591              :      decltype-specifier, a temporary object is not introduced for the
   11592              :      prvalue. The type of the prvalue may be incomplete.  */
   11593    177605537 :   if (!(complain & tf_decltype))
   11594              :     {
   11595    142238146 :       fn = require_complete_type (fn, complain);
   11596    142238146 :       if (fn == error_mark_node)
   11597              :         return error_mark_node;
   11598    142238120 :       fn = maybe_contract_wrap_call (fndecl, fn);
   11599              : 
   11600    142238120 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (fn)))
   11601              :         {
   11602     18048540 :           fn = build_cplus_new (TREE_TYPE (fn), fn, complain);
   11603     18048540 :           maybe_warn_parm_abi (TREE_TYPE (fn), loc);
   11604              :         }
   11605              :     }
   11606              :   else
   11607     35367391 :     fn = maybe_contract_wrap_call (fndecl, fn);
   11608    177605511 :   return convert_from_reference (fn);
   11609              : }
   11610              : 
   11611              : /* Returns the value to use for the in-charge parameter when making a
   11612              :    call to a function with the indicated NAME.
   11613              : 
   11614              :    FIXME:Can't we find a neater way to do this mapping?  */
   11615              : 
   11616              : tree
   11617        32256 : in_charge_arg_for_name (tree name)
   11618              : {
   11619        32256 :   if (IDENTIFIER_CTOR_P (name))
   11620              :     {
   11621        18542 :       if (name == complete_ctor_identifier)
   11622         9271 :         return integer_one_node;
   11623         9271 :       gcc_checking_assert (name == base_ctor_identifier);
   11624              :     }
   11625              :   else
   11626              :     {
   11627        13714 :       if (name == complete_dtor_identifier)
   11628         6857 :         return integer_two_node;
   11629         6857 :       else if (name == deleting_dtor_identifier)
   11630              :         /* The deleting dtor should now be handled by
   11631              :            build_delete_destructor_body.  */
   11632            0 :         gcc_unreachable ();
   11633         6857 :       gcc_checking_assert (name == base_dtor_identifier);
   11634              :     }
   11635              : 
   11636        16128 :   return integer_zero_node;
   11637              : }
   11638              : 
   11639              : /* We've built up a constructor call RET.  Complain if it delegates to the
   11640              :    constructor we're currently compiling.  */
   11641              : 
   11642              : static void
   11643       343459 : check_self_delegation (tree ret)
   11644              : {
   11645       343459 :   if (TREE_CODE (ret) == TARGET_EXPR)
   11646            0 :     ret = TARGET_EXPR_INITIAL (ret);
   11647       343459 :   tree fn = cp_get_callee_fndecl_nofold (ret);
   11648       343459 :   if (fn && DECL_ABSTRACT_ORIGIN (fn) == current_function_decl)
   11649           46 :     error ("constructor delegates to itself");
   11650       343459 : }
   11651              : 
   11652              : /* Build a call to a constructor, destructor, or an assignment
   11653              :    operator for INSTANCE, an expression with class type.  NAME
   11654              :    indicates the special member function to call; *ARGS are the
   11655              :    arguments.  ARGS may be NULL.  This may change ARGS.  BINFO
   11656              :    indicates the base of INSTANCE that is to be passed as the `this'
   11657              :    parameter to the member function called.
   11658              : 
   11659              :    FLAGS are the LOOKUP_* flags to use when processing the call.
   11660              : 
   11661              :    If NAME indicates a complete object constructor, INSTANCE may be
   11662              :    NULL_TREE.  In this case, the caller will call build_cplus_new to
   11663              :    store the newly constructed object into a VAR_DECL.  */
   11664              : 
   11665              : tree
   11666     49368604 : build_special_member_call (tree instance, tree name, vec<tree, va_gc> **args,
   11667              :                            tree binfo, int flags, tsubst_flags_t complain)
   11668              : {
   11669     49368604 :   tree fns;
   11670              :   /* The type of the subobject to be constructed or destroyed.  */
   11671     49368604 :   tree class_type;
   11672     49368604 :   vec<tree, va_gc> *allocated = NULL;
   11673     49368604 :   tree ret;
   11674              : 
   11675     49368604 :   gcc_assert (IDENTIFIER_CDTOR_P (name) || name == assign_op_identifier);
   11676              : 
   11677     49368604 :   if (error_operand_p (instance))
   11678            0 :     return error_mark_node;
   11679              : 
   11680     49368604 :   if (IDENTIFIER_DTOR_P (name))
   11681              :     {
   11682     11358341 :       gcc_assert (args == NULL || vec_safe_is_empty (*args));
   11683     11358341 :       if (!type_build_dtor_call (TREE_TYPE (instance)))
   11684              :         /* Shortcut to avoid lazy destructor declaration.  */
   11685         9653 :         return build_trivial_dtor_call (instance);
   11686              :     }
   11687              : 
   11688     49358951 :   if (TYPE_P (binfo))
   11689              :     {
   11690              :       /* Resolve the name.  */
   11691     39994582 :       if (!complete_type_or_maybe_complain (binfo, NULL_TREE, complain))
   11692           24 :         return error_mark_node;
   11693              : 
   11694     39994558 :       binfo = TYPE_BINFO (binfo);
   11695              :     }
   11696              : 
   11697     39994558 :   gcc_assert (binfo != NULL_TREE);
   11698              : 
   11699     49358927 :   class_type = BINFO_TYPE (binfo);
   11700              : 
   11701              :   /* Handle the special case where INSTANCE is NULL_TREE.  */
   11702     49358927 :   if (name == complete_ctor_identifier && !instance)
   11703     28302827 :     instance = build_dummy_object (class_type);
   11704              :   else
   11705              :     {
   11706              :       /* Convert to the base class, if necessary.  */
   11707     21056100 :       if (!same_type_ignoring_top_level_qualifiers_p
   11708     21056100 :           (TREE_TYPE (instance), BINFO_TYPE (binfo)))
   11709              :         {
   11710      1564488 :           if (IDENTIFIER_CDTOR_P (name))
   11711              :             /* For constructors and destructors, either the base is
   11712              :                non-virtual, or it is virtual but we are doing the
   11713              :                conversion from a constructor or destructor for the
   11714              :                complete object.  In either case, we can convert
   11715              :                statically.  */
   11716      1545483 :             instance = convert_to_base_statically (instance, binfo);
   11717              :           else
   11718              :             {
   11719              :               /* However, for assignment operators, we must convert
   11720              :                  dynamically if the base is virtual.  */
   11721        19005 :               gcc_checking_assert (name == assign_op_identifier);
   11722        19005 :               instance = build_base_path (PLUS_EXPR, instance,
   11723              :                                           binfo, /*nonnull=*/1, complain);
   11724              :             }
   11725              :         }
   11726              :     }
   11727              : 
   11728     49358927 :   gcc_assert (instance != NULL_TREE);
   11729              : 
   11730              :   /* In C++17, "If the initializer expression is a prvalue and the
   11731              :      cv-unqualified version of the source type is the same class as the class
   11732              :      of the destination, the initializer expression is used to initialize the
   11733              :      destination object."  Handle that here to avoid doing overload
   11734              :      resolution.  */
   11735     49358927 :   if (cxx_dialect >= cxx17
   11736     49172443 :       && args && vec_safe_length (*args) == 1
   11737     80426822 :       && !unsafe_return_slot_p (instance))
   11738              :     {
   11739     29740045 :       tree arg = (**args)[0];
   11740              : 
   11741      1706718 :       if (BRACE_ENCLOSED_INITIALIZER_P (arg)
   11742      1706554 :           && !TYPE_HAS_LIST_CTOR (class_type)
   11743      1642608 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (arg)
   11744     31382639 :           && CONSTRUCTOR_NELTS (arg) == 1)
   11745      1107763 :         arg = CONSTRUCTOR_ELT (arg, 0)->value;
   11746              : 
   11747     29740045 :       if ((TREE_CODE (arg) == TARGET_EXPR
   11748     14535857 :            || TREE_CODE (arg) == CONSTRUCTOR)
   11749     45543262 :           && (same_type_ignoring_top_level_qualifiers_p
   11750     15803217 :               (class_type, TREE_TYPE (arg))))
   11751              :         {
   11752     14605792 :           if (is_dummy_object (instance))
   11753              :             return arg;
   11754       211150 :           else if (TREE_CODE (arg) == TARGET_EXPR)
   11755       211150 :             TARGET_EXPR_DIRECT_INIT_P (arg) = true;
   11756              : 
   11757       211150 :           if ((complain & tf_error)
   11758       211148 :               && (flags & LOOKUP_DELEGATING_CONS))
   11759            0 :             check_self_delegation (arg);
   11760              :           /* Avoid change of behavior on Wunused-var-2.C.  */
   11761       211150 :           instance = mark_lvalue_use (instance);
   11762       211150 :           return cp_build_init_expr (instance, arg);
   11763              :         }
   11764              :     }
   11765              : 
   11766     34753135 :   fns = lookup_fnfields (binfo, name, 1, complain);
   11767              : 
   11768              :   /* When making a call to a constructor or destructor for a subobject
   11769              :      that uses virtual base classes, pass down a pointer to a VTT for
   11770              :      the subobject.  */
   11771     34753135 :   if ((name == base_ctor_identifier
   11772     32319244 :        || name == base_dtor_identifier)
   11773     36298684 :       && CLASSTYPE_VBASECLASSES (class_type))
   11774              :     {
   11775        46318 :       tree vtt;
   11776        46318 :       tree sub_vtt;
   11777              : 
   11778              :       /* If the current function is a complete object constructor
   11779              :          or destructor, then we fetch the VTT directly.
   11780              :          Otherwise, we look it up using the VTT we were given.  */
   11781        46318 :       vtt = DECL_CHAIN (CLASSTYPE_VTABLES (current_class_type));
   11782        46318 :       vtt = decay_conversion (vtt, complain);
   11783        46318 :       if (vtt == error_mark_node)
   11784            0 :         return error_mark_node;
   11785        46318 :       vtt = build_if_in_charge (vtt, current_vtt_parm);
   11786        46318 :       if (BINFO_SUBVTT_INDEX (binfo))
   11787        46166 :         sub_vtt = fold_build_pointer_plus (vtt, BINFO_SUBVTT_INDEX (binfo));
   11788              :       else
   11789          152 :         sub_vtt = vtt;
   11790              : 
   11791        46318 :       if (args == NULL)
   11792              :         {
   11793        29485 :           allocated = make_tree_vector ();
   11794        29485 :           args = &allocated;
   11795              :         }
   11796              : 
   11797        46318 :       vec_safe_insert (*args, 0, sub_vtt);
   11798              :     }
   11799              : 
   11800     69506270 :   ret = build_new_method_call (instance, fns, args,
   11801     34753135 :                                TYPE_BINFO (BINFO_TYPE (binfo)),
   11802              :                                flags, /*fn=*/NULL,
   11803              :                                complain);
   11804              : 
   11805     34753135 :   if (allocated != NULL)
   11806        29485 :     release_tree_vector (allocated);
   11807              : 
   11808     34753135 :   if ((complain & tf_error)
   11809     30206976 :       && (flags & LOOKUP_DELEGATING_CONS)
   11810       343545 :       && name == complete_ctor_identifier)
   11811       343459 :     check_self_delegation (ret);
   11812              : 
   11813              :   return ret;
   11814              : }
   11815              : 
   11816              : /* Return the NAME, as a C string.  The NAME indicates a function that
   11817              :    is a member of TYPE.  *FREE_P is set to true if the caller must
   11818              :    free the memory returned.
   11819              : 
   11820              :    Rather than go through all of this, we should simply set the names
   11821              :    of constructors and destructors appropriately, and dispense with
   11822              :    ctor_identifier, dtor_identifier, etc.  */
   11823              : 
   11824              : static char *
   11825           91 : name_as_c_string (tree name, tree type, bool *free_p)
   11826              : {
   11827           91 :   const char *pretty_name;
   11828              : 
   11829              :   /* Assume that we will not allocate memory.  */
   11830           91 :   *free_p = false;
   11831              :   /* Constructors and destructors are special.  */
   11832           91 :   if (IDENTIFIER_CDTOR_P (name))
   11833              :     {
   11834           42 :       pretty_name
   11835           42 :         = identifier_to_locale (IDENTIFIER_POINTER (constructor_name (type)));
   11836              :       /* For a destructor, add the '~'.  */
   11837           42 :       if (IDENTIFIER_DTOR_P (name))
   11838              :         {
   11839            0 :           pretty_name = concat ("~", pretty_name, NULL);
   11840              :           /* Remember that we need to free the memory allocated.  */
   11841            0 :           *free_p = true;
   11842              :         }
   11843              :     }
   11844           49 :   else if (IDENTIFIER_CONV_OP_P (name))
   11845              :     {
   11846            0 :       pretty_name = concat ("operator ",
   11847            0 :                             type_as_string_translate (TREE_TYPE (name),
   11848              :                                                       TFF_PLAIN_IDENTIFIER),
   11849              :                             NULL);
   11850              :       /* Remember that we need to free the memory allocated.  */
   11851            0 :       *free_p = true;
   11852              :     }
   11853              :   else
   11854           49 :     pretty_name = identifier_to_locale (IDENTIFIER_POINTER (name));
   11855              : 
   11856           91 :   return const_cast<char *> (pretty_name);
   11857              : }
   11858              : 
   11859              : /* If CANDIDATES contains exactly one candidate, return it, otherwise
   11860              :    return NULL.  */
   11861              : 
   11862              : static z_candidate *
   11863          677 : single_z_candidate (z_candidate *candidates)
   11864              : {
   11865            0 :   if (candidates == NULL)
   11866              :     return NULL;
   11867              : 
   11868          665 :   if (candidates->next)
   11869            0 :     return NULL;
   11870              : 
   11871              :   return candidates;
   11872              : }
   11873              : 
   11874              : /* If CANDIDATE is invalid due to a bad argument type, return the
   11875              :    pertinent conversion_info.
   11876              : 
   11877              :    Otherwise, return NULL.  */
   11878              : 
   11879              : static const conversion_info *
   11880          336 : maybe_get_bad_conversion_for_unmatched_call (const z_candidate *candidate)
   11881              : {
   11882              :   /* Must be an rr_arg_conversion or rr_bad_arg_conversion.  */
   11883          336 :   rejection_reason *r = candidate->reason;
   11884              : 
   11885          336 :   if (r == NULL)
   11886              :     return NULL;
   11887              : 
   11888          336 :   switch (r->code)
   11889              :     {
   11890              :     default:
   11891              :       return NULL;
   11892              : 
   11893           50 :     case rr_arg_conversion:
   11894           50 :       return &r->u.conversion;
   11895              : 
   11896            6 :     case rr_bad_arg_conversion:
   11897            6 :       return &r->u.bad_conversion;
   11898              :     }
   11899              : }
   11900              : 
   11901              : /* Issue an error and note complaining about a bad argument type at a
   11902              :    callsite with a single candidate FNDECL.
   11903              : 
   11904              :    ARG_LOC is the location of the argument (or UNKNOWN_LOCATION, in which
   11905              :    case input_location is used).
   11906              :    FROM_TYPE is the type of the actual argument; TO_TYPE is the type of
   11907              :    the formal parameter.  */
   11908              : 
   11909              : void
   11910          148 : complain_about_bad_argument (location_t arg_loc,
   11911              :                              tree from_type, tree to_type,
   11912              :                              tree fndecl, int parmnum)
   11913              : {
   11914          148 :   auto_diagnostic_group d;
   11915          148 :   range_label_for_type_mismatch rhs_label (from_type, to_type);
   11916          148 :   range_label *label = &rhs_label;
   11917          148 :   if (arg_loc == UNKNOWN_LOCATION)
   11918              :     {
   11919            6 :       arg_loc = input_location;
   11920            6 :       label = NULL;
   11921              :     }
   11922          148 :   gcc_rich_location richloc (arg_loc, label, highlight_colors::percent_h);
   11923          148 :   error_at (&richloc,
   11924              :             "cannot convert %qH to %qI",
   11925              :             from_type, to_type);
   11926          148 :   maybe_inform_about_fndecl_for_bogus_argument_init
   11927          148 :     (fndecl,
   11928              :      parmnum,
   11929              :      highlight_colors::percent_i);
   11930          148 : }
   11931              : 
   11932              : /* Subroutine of build_new_method_call_1, for where there are no viable
   11933              :    candidates for the call.  */
   11934              : 
   11935              : static void
   11936          683 : complain_about_no_candidates_for_method_call (tree instance,
   11937              :                                               z_candidate *candidates,
   11938              :                                               tree explicit_targs,
   11939              :                                               tree basetype,
   11940              :                                               tree optype, tree name,
   11941              :                                               bool skip_first_for_error,
   11942              :                                               vec<tree, va_gc> *user_args)
   11943              : {
   11944          683 :   auto_diagnostic_group d;
   11945          683 :   if (!COMPLETE_OR_OPEN_TYPE_P (basetype))
   11946            0 :     cxx_incomplete_type_error (instance, basetype);
   11947          683 :   else if (optype)
   11948            6 :     error ("no matching function for call to %<%T::operator %T(%A)%#V%>",
   11949              :            basetype, optype, build_tree_list_vec (user_args),
   11950            6 :            TREE_TYPE (instance));
   11951              :   else
   11952              :     {
   11953              :       /* Special-case for when there's a single candidate that's failing
   11954              :          due to a bad argument type.  */
   11955          677 :       if (z_candidate *candidate = single_z_candidate (candidates))
   11956          336 :           if (const conversion_info *conv
   11957          336 :                 = maybe_get_bad_conversion_for_unmatched_call (candidate))
   11958              :             {
   11959           56 :               tree from_type = conv->from;
   11960           56 :               if (!TYPE_P (conv->from))
   11961            6 :                 from_type = lvalue_type (conv->from);
   11962           56 :               complain_about_bad_argument (conv->loc,
   11963           56 :                                            from_type, conv->to_type,
   11964           56 :                                            candidate->fn, conv->n_arg);
   11965           56 :               return;
   11966              :             }
   11967              : 
   11968          621 :       tree arglist = build_tree_list_vec (user_args);
   11969          621 :       tree errname = name;
   11970          621 :       bool twiddle = false;
   11971          621 :       if (IDENTIFIER_CDTOR_P (errname))
   11972              :         {
   11973          319 :           twiddle = IDENTIFIER_DTOR_P (errname);
   11974          319 :           errname = constructor_name (basetype);
   11975              :         }
   11976          621 :       if (explicit_targs)
   11977           47 :         errname = lookup_template_function (errname, explicit_targs);
   11978          621 :       if (skip_first_for_error)
   11979            3 :         arglist = TREE_CHAIN (arglist);
   11980         1242 :       error ("no matching function for call to %<%T::%s%E(%A)%#V%>",
   11981          621 :              basetype, &"~"[!twiddle], errname, arglist,
   11982          621 :              TREE_TYPE (instance));
   11983              :     }
   11984          627 :   print_z_candidates (location_of (name), candidates);
   11985          683 : }
   11986              : 
   11987              : /* Build a call to "INSTANCE.FN (ARGS)".  If FN_P is non-NULL, it will
   11988              :    be set, upon return, to the function called.  ARGS may be NULL.
   11989              :    This may change ARGS.  */
   11990              : 
   11991              : tree
   11992    124641579 : build_new_method_call (tree instance, tree fns, vec<tree, va_gc> **args,
   11993              :                        tree conversion_path, int flags,
   11994              :                        tree *fn_p, tsubst_flags_t complain)
   11995              : {
   11996    124641579 :   struct z_candidate *candidates = 0, *cand;
   11997    124641579 :   tree explicit_targs = NULL_TREE;
   11998    124641579 :   tree basetype = NULL_TREE;
   11999    124641579 :   tree access_binfo;
   12000    124641579 :   tree optype;
   12001    124641579 :   tree first_mem_arg = NULL_TREE;
   12002    124641579 :   tree name;
   12003    124641579 :   bool skip_first_for_error;
   12004    124641579 :   vec<tree, va_gc> *user_args;
   12005    124641579 :   tree call;
   12006    124641579 :   tree fn;
   12007    124641579 :   int template_only = 0;
   12008    124641579 :   bool any_viable_p;
   12009    124641579 :   tree orig_instance;
   12010    124641579 :   tree orig_fns;
   12011    124641579 :   vec<tree, va_gc> *orig_args = NULL;
   12012              : 
   12013    124641579 :   auto_cond_timevar tv (TV_OVERLOAD);
   12014              : 
   12015    124641579 :   gcc_assert (instance != NULL_TREE);
   12016              : 
   12017              :   /* We don't know what function we're going to call, yet.  */
   12018    124641579 :   if (fn_p)
   12019     33243809 :     *fn_p = NULL_TREE;
   12020              : 
   12021    124641579 :   if (error_operand_p (instance)
   12022    124641579 :       || !fns || error_operand_p (fns))
   12023      1399215 :     return error_mark_node;
   12024              : 
   12025    123242364 :   if (!BASELINK_P (fns))
   12026              :     {
   12027            0 :       if (complain & tf_error)
   12028            0 :         error ("call to non-function %qD", fns);
   12029            0 :       return error_mark_node;
   12030              :     }
   12031              : 
   12032    123242364 :   orig_instance = instance;
   12033    123242364 :   orig_fns = fns;
   12034              : 
   12035              :   /* Dismantle the baselink to collect all the information we need.  */
   12036    123242364 :   if (!conversion_path)
   12037     56658452 :     conversion_path = BASELINK_BINFO (fns);
   12038    123242364 :   access_binfo = BASELINK_ACCESS_BINFO (fns);
   12039    123242364 :   optype = BASELINK_OPTYPE (fns);
   12040    123242364 :   fns = BASELINK_FUNCTIONS (fns);
   12041    123242364 :   if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
   12042              :     {
   12043      2974155 :       explicit_targs = TREE_OPERAND (fns, 1);
   12044      2974155 :       fns = TREE_OPERAND (fns, 0);
   12045      2974155 :       template_only = 1;
   12046              :     }
   12047    123242364 :   gcc_assert (OVL_P (fns));
   12048    123242364 :   fn = OVL_FIRST (fns);
   12049    123242364 :   name = DECL_NAME (fn);
   12050              : 
   12051    123242364 :   basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
   12052    123242364 :   gcc_assert (CLASS_TYPE_P (basetype));
   12053              : 
   12054    123242364 :   user_args = args == NULL ? NULL : *args;
   12055              :   /* Under DR 147 A::A() is an invalid constructor call,
   12056              :      not a functional cast.  */
   12057    123242364 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
   12058              :     {
   12059           54 :       if (! (complain & tf_error))
   12060            0 :         return error_mark_node;
   12061              : 
   12062           54 :       basetype = DECL_CONTEXT (fn);
   12063           54 :       name = constructor_name (basetype);
   12064           54 :       auto_diagnostic_group d;
   12065           54 :       if (permerror (input_location,
   12066              :                      "cannot call constructor %<%T::%D%> directly",
   12067              :                      basetype, name))
   12068           54 :         inform (input_location, "for a function-style cast, remove the "
   12069              :                 "redundant %<::%D%>", name);
   12070           54 :       call = build_functional_cast (input_location, basetype,
   12071              :                                     build_tree_list_vec (user_args),
   12072              :                                     complain);
   12073           54 :       return call;
   12074           54 :     }
   12075              : 
   12076    123242310 :   if (processing_template_decl)
   12077      7416865 :     orig_args = args == NULL ? NULL : make_tree_vector_copy (*args);
   12078              : 
   12079              :   /* Process the argument list.  */
   12080    123107025 :   if (args != NULL && *args != NULL)
   12081              :     {
   12082    106820744 :       *args = resolve_args (*args, complain);
   12083    106820744 :       if (*args == NULL)
   12084          153 :         return error_mark_node;
   12085              :       user_args = *args;
   12086              :     }
   12087              : 
   12088              :   /* Consider the object argument to be used even if we end up selecting a
   12089              :      static member function.  */
   12090    123242157 :   instance = mark_type_use (instance);
   12091              : 
   12092              :   /* Figure out whether to skip the first argument for the error
   12093              :      message we will display to users if an error occurs.  We don't
   12094              :      want to display any compiler-generated arguments.  The "this"
   12095              :      pointer hasn't been added yet.  However, we must remove the VTT
   12096              :      pointer if this is a call to a base-class constructor or
   12097              :      destructor.  */
   12098    123242157 :   skip_first_for_error = false;
   12099    123242157 :   if (IDENTIFIER_CDTOR_P (name))
   12100              :     {
   12101              :       /* Callers should explicitly indicate whether they want to ctor
   12102              :          the complete object or just the part without virtual bases.  */
   12103     63559566 :       gcc_assert (name != ctor_identifier);
   12104              : 
   12105              :       /* Remove the VTT pointer, if present.  */
   12106     61125681 :       if ((name == base_ctor_identifier || name == base_dtor_identifier)
   12107     65105115 :           && CLASSTYPE_VBASECLASSES (basetype))
   12108              :         skip_first_for_error = true;
   12109              : 
   12110              :       /* It's OK to call destructors and constructors on cv-qualified
   12111              :          objects.  Therefore, convert the INSTANCE to the unqualified
   12112              :          type, if necessary.  */
   12113     63559566 :       if (!same_type_p (basetype, TREE_TYPE (instance)))
   12114              :         {
   12115       659941 :           instance = build_this (instance);
   12116       659941 :           instance = build_nop (build_pointer_type (basetype), instance);
   12117       659941 :           instance = build_fold_indirect_ref (instance);
   12118              :         }
   12119              :     }
   12120              :   else
   12121    119365182 :     gcc_assert (!DECL_DESTRUCTOR_P (fn) && !DECL_CONSTRUCTOR_P (fn));
   12122              : 
   12123              :   /* For the overload resolution we need to find the actual `this`
   12124              :      that would be captured if the call turns out to be to a
   12125              :      non-static member function.  Do not actually capture it at this
   12126              :      point.  */
   12127    246484314 :   if (DECL_CONSTRUCTOR_P (fn))
   12128              :     /* Constructors don't use the enclosing 'this'.  */
   12129              :     first_mem_arg = instance;
   12130              :   else
   12131     89289020 :     first_mem_arg = maybe_resolve_dummy (instance, false);
   12132              : 
   12133    123242157 :   conversion_obstack_sentinel cos;
   12134              : 
   12135              :   /* The number of arguments artificial parms in ARGS; we subtract one because
   12136              :      there's no 'this' in ARGS.  */
   12137    123242157 :   unsigned skip = num_artificial_parms_for (fn) - 1;
   12138              : 
   12139              :   /* If CONSTRUCTOR_IS_DIRECT_INIT is set, this was a T{ } form
   12140              :      initializer, not T({ }).  */
   12141    123242157 :   if (DECL_CONSTRUCTOR_P (fn)
   12142     28870758 :       && vec_safe_length (user_args) > skip
   12143    149185929 :       && DIRECT_LIST_INIT_P ((*user_args)[skip]))
   12144              :     {
   12145      1700593 :       tree init_list = (*user_args)[skip];
   12146      1700593 :       tree init = NULL_TREE;
   12147              : 
   12148      1700593 :       gcc_assert (user_args->length () == skip + 1
   12149              :                   && !(flags & LOOKUP_ONLYCONVERTING));
   12150              : 
   12151              :       /* If the initializer list has no elements and T is a class type with
   12152              :          a default constructor, the object is value-initialized.  Handle
   12153              :          this here so we don't need to handle it wherever we use
   12154              :          build_special_member_call.  */
   12155      1700593 :       if (CONSTRUCTOR_NELTS (init_list) == 0
   12156       207294 :           && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
   12157              :           /* For a user-provided default constructor, use the normal
   12158              :              mechanisms so that protected access works.  */
   12159       207294 :           && type_has_non_user_provided_default_constructor (basetype)
   12160      1602249 :           && !processing_template_decl)
   12161       108947 :         init = build_value_init (basetype, complain);
   12162              : 
   12163              :       /* If BASETYPE is an aggregate, we need to do aggregate
   12164              :          initialization.  */
   12165      1591646 :       else if (CP_AGGREGATE_TYPE_P (basetype))
   12166              :         {
   12167           41 :           init = reshape_init (basetype, init_list, complain);
   12168           41 :           init = digest_init (basetype, init, complain);
   12169              :         }
   12170              : 
   12171       108988 :       if (init)
   12172              :         {
   12173       108988 :           if (is_dummy_object (instance))
   12174        30886 :             return get_target_expr (init, complain);
   12175        78102 :           return cp_build_init_expr (instance, init);
   12176              :         }
   12177              : 
   12178              :       /* Otherwise go ahead with overload resolution.  */
   12179      1591605 :       add_list_candidates (fns, first_mem_arg, user_args,
   12180              :                            basetype, explicit_targs, template_only,
   12181              :                            conversion_path, access_binfo, flags,
   12182              :                            &candidates, complain);
   12183              :     }
   12184              :   else
   12185    121541564 :     add_candidates (fns, first_mem_arg, user_args, optype,
   12186              :                     explicit_targs, template_only, conversion_path,
   12187              :                     access_binfo, flags, &candidates, complain);
   12188              : 
   12189    123133169 :   any_viable_p = false;
   12190    123133169 :   candidates = splice_viable (candidates, false, &any_viable_p);
   12191              : 
   12192    123133169 :   if (!any_viable_p)
   12193              :     {
   12194              :       /* [dcl.init], 17.6.2.2:
   12195              : 
   12196              :          Otherwise, if no constructor is viable, the destination type is
   12197              :          a (possibly cv-qualified) aggregate class A, and the initializer
   12198              :          is a parenthesized expression-list, the object is initialized as
   12199              :          follows...
   12200              : 
   12201              :          We achieve this by building up a CONSTRUCTOR, as for list-init,
   12202              :          and setting CONSTRUCTOR_IS_PAREN_INIT to distinguish between
   12203              :          the two.  */
   12204        40141 :       if (DECL_CONSTRUCTOR_P (fn)
   12205        34220 :           && !(flags & LOOKUP_ONLYCONVERTING)
   12206        34196 :           && cxx_dialect >= cxx20
   12207        33586 :           && CP_AGGREGATE_TYPE_P (basetype)
   12208        40141 :           && !vec_safe_is_empty (user_args))
   12209              :         {
   12210              :           /* Create a CONSTRUCTOR from ARGS, e.g. {1, 2} from <1, 2>.  */
   12211          920 :           tree ctor = build_constructor_from_vec (init_list_type_node,
   12212              :                                                   user_args);
   12213          920 :           CONSTRUCTOR_IS_DIRECT_INIT (ctor) = true;
   12214          920 :           CONSTRUCTOR_IS_PAREN_INIT (ctor) = true;
   12215          920 :           if (is_dummy_object (instance))
   12216              :             return ctor;
   12217              :           else
   12218              :             {
   12219          610 :               ctor = digest_init (basetype, ctor, complain);
   12220          610 :               if (ctor == error_mark_node)
   12221              :                 return error_mark_node;
   12222          417 :               return cp_build_init_expr (instance, ctor);
   12223              :             }
   12224              :         }
   12225        39221 :       if (complain & tf_error)
   12226          683 :         complain_about_no_candidates_for_method_call (instance, candidates,
   12227              :                                                       explicit_targs, basetype,
   12228              :                                                       optype, name,
   12229              :                                                       skip_first_for_error,
   12230              :                                                       user_args);
   12231        39221 :       call = error_mark_node;
   12232              :     }
   12233              :   else
   12234              :     {
   12235    123093028 :       cand = tourney (candidates, complain);
   12236    123093028 :       if (cand == 0)
   12237              :         {
   12238          187 :           char *pretty_name;
   12239          187 :           bool free_p;
   12240          187 :           tree arglist;
   12241              : 
   12242          187 :           if (complain & tf_error)
   12243              :             {
   12244           91 :               pretty_name = name_as_c_string (name, basetype, &free_p);
   12245           91 :               arglist = build_tree_list_vec (user_args);
   12246           91 :               if (skip_first_for_error)
   12247            0 :                 arglist = TREE_CHAIN (arglist);
   12248           91 :               auto_diagnostic_group d;
   12249          182 :               if (!any_strictly_viable (candidates))
   12250           13 :                 error ("no matching function for call to %<%s(%A)%>",
   12251              :                        pretty_name, arglist);
   12252              :               else
   12253           78 :                 error ("call of overloaded %<%s(%A)%> is ambiguous",
   12254              :                        pretty_name, arglist);
   12255           91 :               print_z_candidates (location_of (name), candidates);
   12256           91 :               if (free_p)
   12257            0 :                 free (pretty_name);
   12258           91 :             }
   12259          187 :           call = error_mark_node;
   12260          187 :           if (fn_p)
   12261           84 :             *fn_p = error_mark_node;
   12262              :         }
   12263              :       else
   12264              :         {
   12265    123092841 :           fn = cand->fn;
   12266    123092841 :           call = NULL_TREE;
   12267              : 
   12268    123092841 :           if (!(flags & LOOKUP_NONVIRTUAL)
   12269     98821285 :               && DECL_PURE_VIRTUAL_P (fn)
   12270       261438 :               && instance == current_class_ref
   12271    123311981 :               && (complain & tf_warning))
   12272              :             {
   12273              :               /* This is not an error, it is runtime undefined
   12274              :                  behavior.  */
   12275       219140 :               if (!current_function_decl)
   12276            3 :                 warning (0, "pure virtual %q#D called from "
   12277              :                          "non-static data member initializer", fn);
   12278       219137 :               else if (DECL_CONSTRUCTOR_P (current_function_decl)
   12279       219137 :                        || DECL_DESTRUCTOR_P (current_function_decl))
   12280            9 :                 warning (0, (DECL_CONSTRUCTOR_P (current_function_decl)
   12281              :                              ? G_("pure virtual %q#D called from constructor")
   12282              :                              : G_("pure virtual %q#D called from destructor")),
   12283              :                          fn);
   12284              :             }
   12285              : 
   12286    138257233 :           if (DECL_OBJECT_MEMBER_FUNCTION_P (fn)
   12287    215858836 :               && !DECL_CONSTRUCTOR_P (fn)
   12288    197212466 :               && is_dummy_object (instance))
   12289              :             {
   12290        73763 :               instance = maybe_resolve_dummy (instance, true);
   12291        73763 :               if (instance == error_mark_node)
   12292              :                 call = error_mark_node;
   12293        73763 :               else if (!is_dummy_object (instance))
   12294              :                 {
   12295              :                   /* We captured 'this' in the current lambda now that
   12296              :                      we know we really need it.  */
   12297        73400 :                   cand->first_arg = instance;
   12298              :                 }
   12299          363 :               else if (current_class_ptr && any_dependent_bases_p ())
   12300              :                 /* We can't tell until instantiation time whether we can use
   12301              :                    *this as the implicit object argument.  */;
   12302              :               else
   12303              :                 {
   12304          325 :                   if (complain & tf_error)
   12305           60 :                     error ("cannot call member function %qD without object",
   12306              :                            fn);
   12307          325 :                   call = error_mark_node;
   12308              :                 }
   12309              :             }
   12310              : 
   12311    123092841 :           if (call != error_mark_node)
   12312              :             {
   12313              :               /* Now we know what function is being called.  */
   12314    123092516 :               if (fn_p)
   12315     31815285 :                 *fn_p = fn;
   12316              :               /* Build the actual CALL_EXPR.  */
   12317    123092516 :               call = build_over_call (cand, flags, complain);
   12318              : 
   12319              :               /* Suppress warnings for if (my_struct.operator= (x)) where
   12320              :                  my_struct is implicitly converted to bool. */
   12321    123092516 :               if (TREE_CODE (call) == MODIFY_EXPR)
   12322      3229917 :                 suppress_warning (call, OPT_Wparentheses);
   12323              : 
   12324              :               /* In an expression of the form `a->f()' where `f' turns
   12325              :                  out to be a static member function, `a' is
   12326              :                  none-the-less evaluated.  */
   12327    123092516 :               if (!is_dummy_object (instance))
   12328     97012593 :                 call = keep_unused_object_arg (call, instance, fn);
   12329    123092516 :               if (call != error_mark_node
   12330    243974872 :                   && DECL_DESTRUCTOR_P (cand->fn)
   12331    152698278 :                   && !VOID_TYPE_P (TREE_TYPE (call)))
   12332              :                 /* An explicit call of the form "x->~X()" has type
   12333              :                    "void".  However, on platforms where destructors
   12334              :                    return "this" (i.e., those where
   12335              :                    targetm.cxx.cdtor_returns_this is true), such calls
   12336              :                    will appear to have a return value of pointer type
   12337              :                    to the low-level call machinery.  We do not want to
   12338              :                    change the low-level machinery, since we want to be
   12339              :                    able to optimize "delete f()" on such platforms as
   12340              :                    "operator delete(~X(f()))" (rather than generating
   12341              :                    "t = f(), ~X(t), operator delete (t)").  */
   12342     17957726 :                 call = build_nop (void_type_node, call);
   12343              :             }
   12344              :         }
   12345              :     }
   12346              : 
   12347    123132249 :   if (processing_template_decl && call != error_mark_node)
   12348              :     {
   12349      7416813 :       bool cast_to_void = false;
   12350              : 
   12351      7416813 :       if (TREE_CODE (call) == COMPOUND_EXPR)
   12352            6 :         call = TREE_OPERAND (call, 1);
   12353      7416807 :       else if (TREE_CODE (call) == NOP_EXPR)
   12354              :         {
   12355            0 :           cast_to_void = true;
   12356            0 :           call = TREE_OPERAND (call, 0);
   12357              :         }
   12358      7416813 :       if (INDIRECT_REF_P (call))
   12359       586565 :         call = TREE_OPERAND (call, 0);
   12360              : 
   12361              :       /* Prune all but the selected function from the original overload
   12362              :          set so that we can avoid some duplicate work at instantiation time.  */
   12363      7416813 :       if (really_overloaded_fn (fns))
   12364              :         {
   12365      1805991 :           if (DECL_TEMPLATE_INFO (fn)
   12366      1805991 :               && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   12367              :             {
   12368              :               /* Use the selected template, not the specialization, so that
   12369              :                  this looks like an actual lookup result for sake of
   12370              :                  filter_memfn_lookup.  */
   12371              : 
   12372       263262 :               if (OVL_SINGLE_P (fns))
   12373              :                 /* If the original overload set consists of a single function
   12374              :                    template, this isn't beneficial.  */
   12375       225414 :                 goto skip_prune;
   12376              : 
   12377        37848 :               fn = ovl_make (DECL_TI_TEMPLATE (fn));
   12378        37848 :               if (template_only)
   12379        28643 :                 fn = lookup_template_function (fn, explicit_targs);
   12380              :             }
   12381      1580577 :           orig_fns = copy_node (orig_fns);
   12382      1580577 :           BASELINK_FUNCTIONS (orig_fns) = fn;
   12383      1580577 :           BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (orig_fns) = true;
   12384              :         }
   12385              : 
   12386      5610822 : skip_prune:
   12387      7416813 :       call = (build_min_non_dep_call_vec
   12388      7416813 :               (call,
   12389      7416813 :                build_min (COMPONENT_REF, TREE_TYPE (CALL_EXPR_FN (call)),
   12390              :                           orig_instance, orig_fns, NULL_TREE),
   12391              :                orig_args));
   12392      7416813 :       SET_EXPR_LOCATION (call, input_location);
   12393      7416813 :       call = convert_from_reference (call);
   12394      7416813 :       if (cast_to_void)
   12395            0 :         call = build_nop (void_type_node, call);
   12396              :     }
   12397              : 
   12398    123132249 :   if (orig_args != NULL)
   12399      7281574 :     release_tree_vector (orig_args);
   12400              : 
   12401              :   return call;
   12402    124641579 : }
   12403              : 
   12404              : /* Returns true iff standard conversion sequence ICS1 is a proper
   12405              :    subsequence of ICS2.  */
   12406              : 
   12407              : static bool
   12408    162392917 : is_subseq (conversion *ics1, conversion *ics2)
   12409              : {
   12410              :   /* We can assume that a conversion of the same code
   12411              :      between the same types indicates a subsequence since we only get
   12412              :      here if the types we are converting from are the same.  */
   12413              : 
   12414    162392917 :   while (ics1->kind == ck_rvalue
   12415    220058323 :          || ics1->kind == ck_lvalue)
   12416     57665406 :     ics1 = next_conversion (ics1);
   12417              : 
   12418              :   while (1)
   12419              :     {
   12420    237883129 :       while (ics2->kind == ck_rvalue
   12421    237883129 :              || ics2->kind == ck_lvalue)
   12422     57665406 :         ics2 = next_conversion (ics2);
   12423              : 
   12424    180217723 :       if (ics2->kind == ck_user
   12425    180217723 :           || !has_next (ics2->kind))
   12426              :         /* At this point, ICS1 cannot be a proper subsequence of
   12427              :            ICS2.  We can get a USER_CONV when we are comparing the
   12428              :            second standard conversion sequence of two user conversion
   12429              :            sequences.  */
   12430              :         return false;
   12431              : 
   12432     17829107 :       ics2 = next_conversion (ics2);
   12433              : 
   12434     17829107 :       while (ics2->kind == ck_rvalue
   12435     30511403 :              || ics2->kind == ck_lvalue)
   12436     12682296 :         ics2 = next_conversion (ics2);
   12437              : 
   12438     17829107 :       if (ics2->kind == ics1->kind
   12439         4346 :           && same_type_p (ics2->type, ics1->type)
   12440     17833408 :           && (ics1->kind == ck_identity
   12441         4301 :               || same_type_p (next_conversion (ics2)->type,
   12442              :                               next_conversion (ics1)->type)))
   12443         4301 :         return true;
   12444              :     }
   12445              : }
   12446              : 
   12447              : /* Returns nonzero iff DERIVED is derived from BASE.  The inputs may
   12448              :    be any _TYPE nodes.  */
   12449              : 
   12450              : bool
   12451    440583820 : is_properly_derived_from (tree derived, tree base)
   12452              : {
   12453    440583820 :   if (!CLASS_TYPE_P (derived) || !CLASS_TYPE_P (base))
   12454              :     return false;
   12455              : 
   12456              :   /* We only allow proper derivation here.  The DERIVED_FROM_P macro
   12457              :      considers every class derived from itself.  */
   12458    419566928 :   return (!same_type_ignoring_top_level_qualifiers_p (derived, base)
   12459    419566928 :           && DERIVED_FROM_P (base, derived));
   12460              : }
   12461              : 
   12462              : /* We build the ICS for an implicit object parameter as a pointer
   12463              :    conversion sequence.  However, such a sequence should be compared
   12464              :    as if it were a reference conversion sequence.  If ICS is the
   12465              :    implicit conversion sequence for an implicit object parameter,
   12466              :    modify it accordingly.  */
   12467              : 
   12468              : static void
   12469    263428598 : maybe_handle_implicit_object (conversion **ics)
   12470              : {
   12471    263428598 :   if ((*ics)->this_p)
   12472              :     {
   12473              :       /* [over.match.funcs]
   12474              : 
   12475              :          For non-static member functions, the type of the
   12476              :          implicit object parameter is "reference to cv X"
   12477              :          where X is the class of which the function is a
   12478              :          member and cv is the cv-qualification on the member
   12479              :          function declaration.  */
   12480     17070253 :       conversion *t = *ics;
   12481     17070253 :       tree reference_type;
   12482              : 
   12483              :       /* The `this' parameter is a pointer to a class type.  Make the
   12484              :          implicit conversion talk about a reference to that same class
   12485              :          type.  */
   12486     17070253 :       reference_type = TREE_TYPE (t->type);
   12487     17070253 :       reference_type = build_reference_type (reference_type);
   12488              : 
   12489     17070253 :       if (t->kind == ck_qual)
   12490      3836680 :         t = next_conversion (t);
   12491     17070253 :       if (t->kind == ck_ptr)
   12492       578103 :         t = next_conversion (t);
   12493     17070253 :       t = build_identity_conv (TREE_TYPE (t->type), NULL_TREE);
   12494     17070253 :       t = direct_reference_binding (reference_type, t);
   12495     17070253 :       t->this_p = 1;
   12496     17070253 :       t->rvaluedness_matches_p = 0;
   12497     17070253 :       *ics = t;
   12498              :     }
   12499    263428598 : }
   12500              : 
   12501              : /* If *ICS is a REF_BIND set *ICS to the remainder of the conversion,
   12502              :    and return the initial reference binding conversion. Otherwise,
   12503              :    leave *ICS unchanged and return NULL.  */
   12504              : 
   12505              : static conversion *
   12506    263428598 : maybe_handle_ref_bind (conversion **ics)
   12507              : {
   12508    263428598 :   if ((*ics)->kind == ck_ref_bind)
   12509              :     {
   12510     77629634 :       conversion *old_ics = *ics;
   12511     77629634 :       *ics = next_conversion (old_ics);
   12512     77629634 :       (*ics)->user_conv_p = old_ics->user_conv_p;
   12513     77629634 :       return old_ics;
   12514              :     }
   12515              : 
   12516              :   return NULL;
   12517              : }
   12518              : 
   12519              : /* Get the expression at the beginning of the conversion chain C.  */
   12520              : 
   12521              : static tree
   12522           51 : conv_get_original_expr (conversion *c)
   12523              : {
   12524           60 :   for (; c; c = next_conversion (c))
   12525           60 :     if (c->kind == ck_identity || c->kind == ck_ambig || c->kind == ck_aggr)
   12526           51 :       return c->u.expr;
   12527              :   return NULL_TREE;
   12528              : }
   12529              : 
   12530              : /* Return a tree representing the number of elements initialized by the
   12531              :    list-initialization C.  The caller must check that C converts to an
   12532              :    array type.  */
   12533              : 
   12534              : static tree
   12535          126 : nelts_initialized_by_list_init (conversion *c)
   12536              : {
   12537              :   /* If the array we're converting to has a dimension, we'll use that.  */
   12538          126 :   if (TYPE_DOMAIN (c->type))
   12539           84 :     return array_type_nelts_top (c->type);
   12540              :   else
   12541              :     {
   12542              :       /* Otherwise, we look at how many elements the constructor we're
   12543              :          initializing from has.  */
   12544           42 :       tree ctor = conv_get_original_expr (c);
   12545           72 :       return size_int (CONSTRUCTOR_NELTS (ctor));
   12546              :     }
   12547              : }
   12548              : 
   12549              : /* True iff C is a conversion that binds a reference or a pointer to
   12550              :    an array of unknown bound.  */
   12551              : 
   12552              : static inline bool
   12553     42488332 : conv_binds_to_array_of_unknown_bound (conversion *c)
   12554              : {
   12555              :   /* ck_ref_bind won't have the reference stripped.  */
   12556     42488332 :   tree type = non_reference (c->type);
   12557              :   /* ck_qual won't have the pointer stripped.  */
   12558     42488332 :   type = strip_pointer_operator (type);
   12559     42488332 :   return (TREE_CODE (type) == ARRAY_TYPE
   12560     42488332 :           && TYPE_DOMAIN (type) == NULL_TREE);
   12561              : }
   12562              : 
   12563              : /* Compare two implicit conversion sequences according to the rules set out in
   12564              :    [over.ics.rank].  Return values:
   12565              : 
   12566              :       1: ics1 is better than ics2
   12567              :      -1: ics2 is better than ics1
   12568              :       0: ics1 and ics2 are indistinguishable */
   12569              : 
   12570              : static int
   12571    131714340 : compare_ics (conversion *ics1, conversion *ics2)
   12572              : {
   12573    131714340 :   tree from_type1;
   12574    131714340 :   tree from_type2;
   12575    131714340 :   tree to_type1;
   12576    131714340 :   tree to_type2;
   12577    131714340 :   tree deref_from_type1 = NULL_TREE;
   12578    131714340 :   tree deref_from_type2 = NULL_TREE;
   12579    131714340 :   tree deref_to_type1 = NULL_TREE;
   12580    131714340 :   tree deref_to_type2 = NULL_TREE;
   12581    131714340 :   conversion_rank rank1, rank2;
   12582              : 
   12583              :   /* REF_BINDING is nonzero if the result of the conversion sequence
   12584              :      is a reference type.   In that case REF_CONV is the reference
   12585              :      binding conversion. */
   12586    131714340 :   conversion *ref_conv1;
   12587    131714340 :   conversion *ref_conv2;
   12588              : 
   12589              :   /* Compare badness before stripping the reference conversion.  */
   12590    131714340 :   if (ics1->bad_p > ics2->bad_p)
   12591              :     return -1;
   12592    131714326 :   else if (ics1->bad_p < ics2->bad_p)
   12593              :     return 1;
   12594              : 
   12595              :   /* Handle implicit object parameters.  */
   12596    131714299 :   maybe_handle_implicit_object (&ics1);
   12597    131714299 :   maybe_handle_implicit_object (&ics2);
   12598              : 
   12599              :   /* Handle reference parameters.  */
   12600    131714299 :   ref_conv1 = maybe_handle_ref_bind (&ics1);
   12601    131714299 :   ref_conv2 = maybe_handle_ref_bind (&ics2);
   12602              : 
   12603              :   /* List-initialization sequence L1 is a better conversion sequence than
   12604              :      list-initialization sequence L2 if L1 converts to
   12605              :      std::initializer_list<X> for some X and L2 does not.  */
   12606    131714299 :   if (ics1->kind == ck_list && ics2->kind != ck_list)
   12607              :     return 1;
   12608    131713798 :   if (ics2->kind == ck_list && ics1->kind != ck_list)
   12609              :     return -1;
   12610              : 
   12611              :   /* [over.ics.rank]
   12612              : 
   12613              :      When  comparing  the  basic forms of implicit conversion sequences (as
   12614              :      defined in _over.best.ics_)
   12615              : 
   12616              :      --a standard conversion sequence (_over.ics.scs_) is a better
   12617              :        conversion sequence than a user-defined conversion sequence
   12618              :        or an ellipsis conversion sequence, and
   12619              : 
   12620              :      --a user-defined conversion sequence (_over.ics.user_) is a
   12621              :        better conversion sequence than an ellipsis conversion sequence
   12622              :        (_over.ics.ellipsis_).  */
   12623              :   /* Use BAD_CONVERSION_RANK because we already checked for a badness
   12624              :      mismatch.  If both ICS are bad, we try to make a decision based on
   12625              :      what would have happened if they'd been good.  This is not an
   12626              :      extension, we'll still give an error when we build up the call; this
   12627              :      just helps us give a more helpful error message.  */
   12628    131713542 :   rank1 = BAD_CONVERSION_RANK (ics1);
   12629    131713542 :   rank2 = BAD_CONVERSION_RANK (ics2);
   12630              : 
   12631    131713542 :   if (rank1 > rank2)
   12632              :     return -1;
   12633    121118938 :   else if (rank1 < rank2)
   12634              :     return 1;
   12635              : 
   12636     81635920 :   if (ics1->ellipsis_p)
   12637              :     /* Both conversions are ellipsis conversions.  */
   12638              :     return 0;
   12639              : 
   12640              :   /* User-defined  conversion sequence U1 is a better conversion sequence
   12641              :      than another user-defined conversion sequence U2 if they contain the
   12642              :      same user-defined conversion operator or constructor and if the sec-
   12643              :      ond standard conversion sequence of U1 is  better  than  the  second
   12644              :      standard conversion sequence of U2.  */
   12645              : 
   12646              :   /* Handle list-conversion with the same code even though it isn't always
   12647              :      ranked as a user-defined conversion and it doesn't have a second
   12648              :      standard conversion sequence; it will still have the desired effect.
   12649              :      Specifically, we need to do the reference binding comparison at the
   12650              :      end of this function.  */
   12651              : 
   12652     81635874 :   if (ics1->user_conv_p || ics1->kind == ck_list
   12653     80953674 :       || ics1->kind == ck_aggr || ics2->kind == ck_aggr)
   12654              :     {
   12655       682269 :       conversion *t1 = strip_standard_conversion (ics1);
   12656       682269 :       conversion *t2 = strip_standard_conversion (ics2);
   12657              : 
   12658       682269 :       if (!t1 || !t2 || t1->kind != t2->kind)
   12659              :         return 0;
   12660       682250 :       else if (t1->kind == ck_user)
   12661              :         {
   12662       644331 :           tree f1 = t1->cand ? t1->cand->fn : t1->type;
   12663       644331 :           tree f2 = t2->cand ? t2->cand->fn : t2->type;
   12664       644331 :           if (f1 != f2)
   12665              :             return 0;
   12666              :         }
   12667              :       /* List-initialization sequence L1 is a better conversion sequence than
   12668              :          list-initialization sequence L2 if
   12669              : 
   12670              :          -- L1 and L2 convert to arrays of the same element type, and either
   12671              :          the number of elements n1 initialized by L1 is less than the number
   12672              :          of elements n2 initialized by L2, or n1=n2 and L2 converts to an array
   12673              :          of unknown bound and L1 does not.  (Added in CWG 1307 and extended by
   12674              :          P0388R4.)  */
   12675        37919 :       else if (t1->kind == ck_aggr
   12676        37126 :                && TREE_CODE (t1->type) == ARRAY_TYPE
   12677           66 :                && TREE_CODE (t2->type) == ARRAY_TYPE
   12678        37985 :                && same_type_p (TREE_TYPE (t1->type), TREE_TYPE (t2->type)))
   12679              :         {
   12680           63 :           tree n1 = nelts_initialized_by_list_init (t1);
   12681           63 :           tree n2 = nelts_initialized_by_list_init (t2);
   12682           63 :           if (tree_int_cst_lt (n1, n2))
   12683              :             return 1;
   12684           24 :           else if (tree_int_cst_lt (n2, n1))
   12685              :             return -1;
   12686              :           /* The n1 == n2 case.  */
   12687           24 :           bool c1 = conv_binds_to_array_of_unknown_bound (t1);
   12688           24 :           bool c2 = conv_binds_to_array_of_unknown_bound (t2);
   12689           24 :           if (c1 && !c2)
   12690              :             return -1;
   12691            6 :           else if (!c1 && c2)
   12692              :             return 1;
   12693              :           else
   12694              :             return 0;
   12695              :         }
   12696              :       else
   12697              :         {
   12698              :           /* For ambiguous or aggregate conversions, use the target type as
   12699              :              a proxy for the conversion function.  */
   12700        37856 :           if (!same_type_ignoring_top_level_qualifiers_p (t1->type, t2->type))
   12701              :             return 0;
   12702              :         }
   12703              : 
   12704              :       /* We can just fall through here, after setting up
   12705              :          FROM_TYPE1 and FROM_TYPE2.  */
   12706       679529 :       from_type1 = t1->type;
   12707       679529 :       from_type2 = t2->type;
   12708       679529 :     }
   12709              :   else
   12710              :     {
   12711              :       conversion *t1;
   12712              :       conversion *t2;
   12713              : 
   12714              :       /* We're dealing with two standard conversion sequences.
   12715              : 
   12716              :          [over.ics.rank]
   12717              : 
   12718              :          Standard conversion sequence S1 is a better conversion
   12719              :          sequence than standard conversion sequence S2 if
   12720              : 
   12721              :          --S1 is a proper subsequence of S2 (comparing the conversion
   12722              :            sequences in the canonical form defined by _over.ics.scs_,
   12723              :            excluding any Lvalue Transformation; the identity
   12724              :            conversion sequence is considered to be a subsequence of
   12725              :            any non-identity conversion sequence */
   12726              : 
   12727              :       t1 = ics1;
   12728    125148748 :       while (t1->kind != ck_identity)
   12729     44195143 :         t1 = next_conversion (t1);
   12730     80953605 :       from_type1 = t1->type;
   12731              : 
   12732     80953605 :       t2 = ics2;
   12733    125015567 :       while (t2->kind != ck_identity)
   12734     44061962 :         t2 = next_conversion (t2);
   12735     80953605 :       from_type2 = t2->type;
   12736              :     }
   12737              : 
   12738              :   /* One sequence can only be a subsequence of the other if they start with
   12739              :      the same type.  They can start with different types when comparing the
   12740              :      second standard conversion sequence in two user-defined conversion
   12741              :      sequences.  */
   12742     81633134 :   if (same_type_p (from_type1, from_type2))
   12743              :     {
   12744     81198580 :       if (is_subseq (ics1, ics2))
   12745              :         return 1;
   12746     81194337 :       if (is_subseq (ics2, ics1))
   12747              :         return -1;
   12748              :     }
   12749              : 
   12750              :   /* [over.ics.rank]
   12751              : 
   12752              :      Or, if not that,
   12753              : 
   12754              :      --the rank of S1 is better than the rank of S2 (by the rules
   12755              :        defined below):
   12756              : 
   12757              :     Standard conversion sequences are ordered by their ranks: an Exact
   12758              :     Match is a better conversion than a Promotion, which is a better
   12759              :     conversion than a Conversion.
   12760              : 
   12761              :     Two conversion sequences with the same rank are indistinguishable
   12762              :     unless one of the following rules applies:
   12763              : 
   12764              :     --A conversion that does not a convert a pointer, pointer to member,
   12765              :       or std::nullptr_t to bool is better than one that does.
   12766              : 
   12767              :     The ICS_STD_RANK automatically handles the pointer-to-bool rule,
   12768              :     so that we do not have to check it explicitly.  */
   12769     81628833 :   if (ics1->rank < ics2->rank)
   12770              :     return 1;
   12771     81628753 :   else if (ics2->rank < ics1->rank)
   12772              :     return -1;
   12773              : 
   12774     81628753 :   to_type1 = ics1->type;
   12775     81628753 :   to_type2 = ics2->type;
   12776              : 
   12777              :   /* A conversion from scalar arithmetic type to complex is worse than a
   12778              :      conversion between scalar arithmetic types.  */
   12779     81628753 :   if (same_type_p (from_type1, from_type2)
   12780     81194199 :       && ARITHMETIC_TYPE_P (from_type1)
   12781     20043841 :       && ARITHMETIC_TYPE_P (to_type1)
   12782     20043674 :       && ARITHMETIC_TYPE_P (to_type2)
   12783     81628753 :       && ((TREE_CODE (to_type1) == COMPLEX_TYPE)
   12784     20043632 :           != (TREE_CODE (to_type2) == COMPLEX_TYPE)))
   12785              :     {
   12786          106 :       if (TREE_CODE (to_type1) == COMPLEX_TYPE)
   12787              :         return -1;
   12788              :       else
   12789              :         return 1;
   12790              :     }
   12791              : 
   12792     81628647 :   {
   12793              :     /* A conversion in either direction between floating-point type FP1 and
   12794              :        floating-point type FP2 is better than a conversion in the same
   12795              :        direction between FP1 and arithmetic type T3 if
   12796              :        - the floating-point conversion rank of FP1 is equal to the rank of
   12797              :          FP2, and
   12798              :        - T3 is not a floating-point type, or T3 is a floating-point type
   12799              :          whose rank is not equal to the rank of FP1, or the floating-point
   12800              :          conversion subrank of FP2 is greater than the subrank of T3.  */
   12801     81628647 :     tree fp1 = from_type1;
   12802     81628647 :     tree fp2 = to_type1;
   12803     81628647 :     tree fp3 = from_type2;
   12804     81628647 :     tree t3 = to_type2;
   12805     81628647 :     int ret = 1;
   12806     81628647 :     if (TYPE_MAIN_VARIANT (fp2) == TYPE_MAIN_VARIANT (t3))
   12807              :       {
   12808     74124132 :         std::swap (fp1, fp2);
   12809     74124132 :         std::swap (fp3, t3);
   12810              :       }
   12811     81628647 :     if (TYPE_MAIN_VARIANT (fp1) == TYPE_MAIN_VARIANT (fp3)
   12812     81628562 :         && SCALAR_FLOAT_TYPE_P (fp1)
   12813              :         /* Only apply this rule if at least one of the 3 types is
   12814              :            extended floating-point type, otherwise keep them as
   12815              :            before for compatibility reasons with types like __float128.
   12816              :            float, double and long double alone have different conversion
   12817              :            ranks and so when just those 3 types are involved, this
   12818              :            rule doesn't trigger.  */
   12819     86307338 :         && (extended_float_type_p (fp1)
   12820      4567175 :             || (SCALAR_FLOAT_TYPE_P (fp2) && extended_float_type_p (fp2))
   12821      3978811 :             || (SCALAR_FLOAT_TYPE_P (t3) && extended_float_type_p (t3))))
   12822              :       {
   12823       699880 :         if (TREE_CODE (fp2) != REAL_TYPE)
   12824              :           {
   12825        23827 :             ret = -ret;
   12826        23827 :             std::swap (fp2, t3);
   12827              :           }
   12828       699880 :         if (SCALAR_FLOAT_TYPE_P (fp2))
   12829              :           {
   12830              :             /* cp_compare_floating_point_conversion_ranks returns -1, 0 or 1
   12831              :                if the conversion rank is equal (-1 or 1 if the subrank is
   12832              :                different).  */
   12833       686858 :             if (IN_RANGE (cp_compare_floating_point_conversion_ranks (fp1,
   12834              :                                                                       fp2),
   12835              :                           -1, 1))
   12836              :               {
   12837              :                 /* Conversion ranks of FP1 and FP2 are equal.  */
   12838       508492 :                 if (TREE_CODE (t3) != REAL_TYPE
   12839       508492 :                     || !IN_RANGE (cp_compare_floating_point_conversion_ranks
   12840              :                                                                 (fp1, t3),
   12841              :                                   -1, 1))
   12842              :                   /* FP1 <-> FP2 conversion is better.  */
   12843       508022 :                   return ret;
   12844          470 :                 int c = cp_compare_floating_point_conversion_ranks (fp2, t3);
   12845          470 :                 gcc_assert (IN_RANGE (c, -1, 1));
   12846          470 :                 if (c == 1)
   12847              :                   /* Conversion subrank of FP2 is greater than subrank of T3.
   12848              :                      FP1 <-> FP2 conversion is better.  */
   12849              :                   return ret;
   12850          470 :                 else if (c == -1)
   12851              :                   /* Conversion subrank of FP2 is less than subrank of T3.
   12852              :                      FP1 <-> T3 conversion is better.  */
   12853            0 :                   return -ret;
   12854              :               }
   12855       178366 :             else if (SCALAR_FLOAT_TYPE_P (t3)
   12856       178366 :                      && IN_RANGE (cp_compare_floating_point_conversion_ranks
   12857              :                                                                 (fp1, t3),
   12858              :                                   -1, 1))
   12859              :               /* Conversion ranks of FP1 and FP2 are not equal, conversion
   12860              :                  ranks of FP1 and T3 are equal.
   12861              :                  FP1 <-> T3 conversion is better.  */
   12862        15856 :               return -ret;
   12863              :           }
   12864              :       }
   12865              :   }
   12866              : 
   12867     81104769 :   if (TYPE_PTR_P (from_type1)
   12868     25895654 :       && TYPE_PTR_P (from_type2)
   12869     25895638 :       && TYPE_PTR_P (to_type1)
   12870     25895614 :       && TYPE_PTR_P (to_type2))
   12871              :     {
   12872     25895614 :       deref_from_type1 = TREE_TYPE (from_type1);
   12873     25895614 :       deref_from_type2 = TREE_TYPE (from_type2);
   12874     25895614 :       deref_to_type1 = TREE_TYPE (to_type1);
   12875     25895614 :       deref_to_type2 = TREE_TYPE (to_type2);
   12876              :     }
   12877              :   /* The rules for pointers to members A::* are just like the rules
   12878              :      for pointers A*, except opposite: if B is derived from A then
   12879              :      A::* converts to B::*, not vice versa.  For that reason, we
   12880              :      switch the from_ and to_ variables here.  */
   12881           58 :   else if ((TYPE_PTRDATAMEM_P (from_type1) && TYPE_PTRDATAMEM_P (from_type2)
   12882           58 :             && TYPE_PTRDATAMEM_P (to_type1) && TYPE_PTRDATAMEM_P (to_type2))
   12883     55209155 :            || (TYPE_PTRMEMFUNC_P (from_type1)
   12884          437 :                && TYPE_PTRMEMFUNC_P (from_type2)
   12885          437 :                && TYPE_PTRMEMFUNC_P (to_type1)
   12886          437 :                && TYPE_PTRMEMFUNC_P (to_type2)))
   12887              :     {
   12888          495 :       deref_to_type1 = TYPE_PTRMEM_CLASS_TYPE (from_type1);
   12889          495 :       deref_to_type2 = TYPE_PTRMEM_CLASS_TYPE (from_type2);
   12890          495 :       deref_from_type1 = TYPE_PTRMEM_CLASS_TYPE (to_type1);
   12891          495 :       deref_from_type2 = TYPE_PTRMEM_CLASS_TYPE (to_type2);
   12892              :     }
   12893              : 
   12894     25896109 :   if (deref_from_type1 != NULL_TREE
   12895     25896109 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type1))
   12896       289789 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type2)))
   12897              :     {
   12898              :       /* This was one of the pointer or pointer-like conversions.
   12899              : 
   12900              :          [over.ics.rank]
   12901              : 
   12902              :          --If class B is derived directly or indirectly from class A,
   12903              :            conversion of B* to A* is better than conversion of B* to
   12904              :            void*, and conversion of A* to void* is better than
   12905              :            conversion of B* to void*.  */
   12906       289789 :       if (VOID_TYPE_P (deref_to_type1)
   12907           57 :           && VOID_TYPE_P (deref_to_type2))
   12908              :         {
   12909           14 :           if (is_properly_derived_from (deref_from_type1,
   12910              :                                         deref_from_type2))
   12911              :             return -1;
   12912           14 :           else if (is_properly_derived_from (deref_from_type2,
   12913              :                                              deref_from_type1))
   12914              :             return 1;
   12915              :         }
   12916       289775 :       else if (VOID_TYPE_P (deref_to_type1)
   12917       289732 :                || VOID_TYPE_P (deref_to_type2))
   12918              :         {
   12919           47 :           if (same_type_p (deref_from_type1, deref_from_type2))
   12920              :             {
   12921           47 :               if (VOID_TYPE_P (deref_to_type2))
   12922              :                 {
   12923            4 :                   if (is_properly_derived_from (deref_from_type1,
   12924              :                                                 deref_to_type1))
   12925              :                     return 1;
   12926              :                 }
   12927              :               /* We know that DEREF_TO_TYPE1 is `void' here.  */
   12928           43 :               else if (is_properly_derived_from (deref_from_type1,
   12929              :                                                  deref_to_type2))
   12930              :                 return -1;
   12931              :             }
   12932              :         }
   12933       289728 :       else if (RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type1))
   12934       289728 :                && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type2)))
   12935              :         {
   12936              :           /* [over.ics.rank]
   12937              : 
   12938              :              --If class B is derived directly or indirectly from class A
   12939              :                and class C is derived directly or indirectly from B,
   12940              : 
   12941              :              --conversion of C* to B* is better than conversion of C* to
   12942              :                A*,
   12943              : 
   12944              :              --conversion of B* to A* is better than conversion of C* to
   12945              :                A*  */
   12946       289728 :           if (same_type_p (deref_from_type1, deref_from_type2))
   12947              :             {
   12948       289722 :               if (is_properly_derived_from (deref_to_type1,
   12949              :                                             deref_to_type2))
   12950              :                 return 1;
   12951       289722 :               else if (is_properly_derived_from (deref_to_type2,
   12952              :                                                  deref_to_type1))
   12953              :                 return -1;
   12954              :             }
   12955            6 :           else if (same_type_p (deref_to_type1, deref_to_type2))
   12956              :             {
   12957            6 :               if (is_properly_derived_from (deref_from_type2,
   12958              :                                             deref_from_type1))
   12959              :                 return 1;
   12960            0 :               else if (is_properly_derived_from (deref_from_type1,
   12961              :                                                  deref_from_type2))
   12962              :                 return -1;
   12963              :             }
   12964              :         }
   12965              :     }
   12966    161629960 :   else if (CLASS_TYPE_P (non_reference (from_type1))
   12967    113552662 :            && same_type_p (from_type1, from_type2))
   12968              :     {
   12969     32369116 :       tree from = non_reference (from_type1);
   12970              : 
   12971              :       /* [over.ics.rank]
   12972              : 
   12973              :          --binding of an expression of type C to a reference of type
   12974              :            B& is better than binding an expression of type C to a
   12975              :            reference of type A&
   12976              : 
   12977              :          --conversion of C to B is better than conversion of C to A,  */
   12978     32369116 :       if (is_properly_derived_from (from, to_type1)
   12979     32369116 :           && is_properly_derived_from (from, to_type2))
   12980              :         {
   12981       938051 :           if (is_properly_derived_from (to_type1, to_type2))
   12982              :             return 1;
   12983       934436 :           else if (is_properly_derived_from (to_type2, to_type1))
   12984              :             return -1;
   12985              :         }
   12986              :     }
   12987     96891728 :   else if (CLASS_TYPE_P (non_reference (to_type1))
   12988     48814430 :            && same_type_p (to_type1, to_type2))
   12989              :     {
   12990            6 :       tree to = non_reference (to_type1);
   12991              : 
   12992              :       /* [over.ics.rank]
   12993              : 
   12994              :          --binding of an expression of type B to a reference of type
   12995              :            A& is better than binding an expression of type C to a
   12996              :            reference of type A&,
   12997              : 
   12998              :          --conversion of B to A is better than conversion of C to A  */
   12999            6 :       if (is_properly_derived_from (from_type1, to)
   13000            6 :           && is_properly_derived_from (from_type2, to))
   13001              :         {
   13002            3 :           if (is_properly_derived_from (from_type2, from_type1))
   13003              :             return 1;
   13004            3 :           else if (is_properly_derived_from (from_type1, from_type2))
   13005              :             return -1;
   13006              :         }
   13007              :     }
   13008              : 
   13009              :   /* [over.ics.rank]
   13010              : 
   13011              :      --S1 and S2 differ only in their qualification conversion and  yield
   13012              :        similar  types  T1 and T2 (_conv.qual_), respectively, and the cv-
   13013              :        qualification signature of type T1 is a proper subset of  the  cv-
   13014              :        qualification signature of type T2  */
   13015     80995956 :   if (ics1->kind == ck_qual
   13016          351 :       && ics2->kind == ck_qual
   13017     80996307 :       && same_type_p (from_type1, from_type2))
   13018              :     {
   13019          351 :       int result = comp_cv_qual_signature (to_type1, to_type2);
   13020          351 :       if (result != 0)
   13021              :         return result;
   13022              :     }
   13023              : 
   13024              :   /* [over.ics.rank]
   13025              : 
   13026              :      --S1 and S2 are reference bindings (_dcl.init.ref_) and neither refers
   13027              :      to an implicit object parameter of a non-static member function
   13028              :      declared without a ref-qualifier, and either S1 binds an lvalue
   13029              :      reference to an lvalue and S2 binds an rvalue reference or S1 binds an
   13030              :      rvalue reference to an rvalue and S2 binds an lvalue reference (C++0x
   13031              :      draft standard, 13.3.3.2)
   13032              : 
   13033              :      --S1 and S2 are reference bindings (_dcl.init.ref_), and the
   13034              :      types to which the references refer are the same type except for
   13035              :      top-level cv-qualifiers, and the type to which the reference
   13036              :      initialized by S2 refers is more cv-qualified than the type to
   13037              :      which the reference initialized by S1 refers.
   13038              : 
   13039              :      DR 1328 [over.match.best]: the context is an initialization by
   13040              :      conversion function for direct reference binding (13.3.1.6) of a
   13041              :      reference to function type, the return type of F1 is the same kind of
   13042              :      reference (i.e. lvalue or rvalue) as the reference being initialized,
   13043              :      and the return type of F2 is not.  */
   13044              : 
   13045     80995870 :   if (ref_conv1 && ref_conv2)
   13046              :     {
   13047     24425446 :       if (!ref_conv1->this_p && !ref_conv2->this_p
   13048     24204999 :           && (ref_conv1->rvaluedness_matches_p
   13049     24204999 :               != ref_conv2->rvaluedness_matches_p)
   13050     44532906 :           && (same_type_p (ref_conv1->type, ref_conv2->type)
   13051     11644419 :               || (TYPE_REF_IS_RVALUE (ref_conv1->type)
   13052     11644419 :                   != TYPE_REF_IS_RVALUE (ref_conv2->type))))
   13053              :         {
   13054     11644147 :           if (ref_conv1->bad_p
   13055     11644147 :               && !same_type_p (TREE_TYPE (ref_conv1->type),
   13056              :                                TREE_TYPE (ref_conv2->type)))
   13057              :             /* Don't prefer a bad conversion that drops cv-quals to a bad
   13058              :                conversion with the wrong rvalueness.  */
   13059              :             return 0;
   13060     11642688 :           return (ref_conv1->rvaluedness_matches_p
   13061     11642688 :                   - ref_conv2->rvaluedness_matches_p);
   13062              :         }
   13063              : 
   13064     21244337 :       if (same_type_ignoring_top_level_qualifiers_p (to_type1, to_type2))
   13065              :         {
   13066              :           /* Per P0388R4:
   13067              : 
   13068              :             void f (int(&)[]),     // (1)
   13069              :                  f (int(&)[1]),    // (2)
   13070              :                  f (int*);         // (3)
   13071              : 
   13072              :             (2) is better than (1), but (3) should be equal to (1) and to
   13073              :             (2).  For that reason we don't use ck_qual for (1) which would
   13074              :             give it the cr_exact rank while (3) remains ck_identity.
   13075              :             Therefore we compare (1) and (2) here.  For (1) we'll have
   13076              : 
   13077              :               ck_ref_bind <- ck_identity
   13078              :                 int[] &            int[1]
   13079              : 
   13080              :             so to handle this we must look at ref_conv.  */
   13081     21243906 :           bool c1 = conv_binds_to_array_of_unknown_bound (ref_conv1);
   13082     21243906 :           bool c2 = conv_binds_to_array_of_unknown_bound (ref_conv2);
   13083     21243906 :           if (c1 && !c2)
   13084              :             return -1;
   13085     21243900 :           else if (!c1 && c2)
   13086              :             return 1;
   13087              : 
   13088     21243900 :           int q1 = cp_type_quals (TREE_TYPE (ref_conv1->type));
   13089     21243900 :           int q2 = cp_type_quals (TREE_TYPE (ref_conv2->type));
   13090     21243900 :           if (ref_conv1->bad_p)
   13091              :             {
   13092              :               /* Prefer the one that drops fewer cv-quals.  */
   13093         1606 :               tree ftype = next_conversion (ref_conv1)->type;
   13094         1606 :               int fquals = cp_type_quals (ftype);
   13095         1606 :               q1 ^= fquals;
   13096         1606 :               q2 ^= fquals;
   13097              :             }
   13098     21243900 :           return comp_cv_qualification (q2, q1);
   13099              :         }
   13100              :     }
   13101              : 
   13102              :   /* [over.ics.rank]
   13103              : 
   13104              :      Per CWG 1601:
   13105              :      -- A conversion that promotes an enumeration whose underlying type
   13106              :      is fixed to its underlying type is better than one that promotes to
   13107              :      the promoted underlying type, if the two are different.  */
   13108     48107817 :   if (ics1->rank == cr_promotion
   13109          143 :       && ics2->rank == cr_promotion
   13110          143 :       && UNSCOPED_ENUM_P (from_type1)
   13111           27 :       && ENUM_FIXED_UNDERLYING_TYPE_P (from_type1)
   13112     48107841 :       && same_type_p (from_type1, from_type2))
   13113              :     {
   13114           24 :       tree utype = ENUM_UNDERLYING_TYPE (from_type1);
   13115           24 :       tree prom = type_promotes_to (from_type1);
   13116           24 :       if (!same_type_p (utype, prom))
   13117              :         {
   13118           12 :           if (same_type_p (to_type1, utype)
   13119           12 :               && same_type_p (to_type2, prom))
   13120              :             return 1;
   13121            6 :           else if (same_type_p (to_type2, utype)
   13122            6 :                    && same_type_p (to_type1, prom))
   13123              :             return -1;
   13124              :         }
   13125              :     }
   13126              : 
   13127              :   /* Neither conversion sequence is better than the other.  */
   13128              :   return 0;
   13129              : }
   13130              : 
   13131              : /* The source type for this standard conversion sequence.  */
   13132              : 
   13133              : static tree
   13134            9 : source_type (conversion *t)
   13135              : {
   13136            9 :   return strip_standard_conversion (t)->type;
   13137              : }
   13138              : 
   13139              : /* Note a warning about preferring WINNER to LOSER.  We do this by storing
   13140              :    a pointer to LOSER and re-running joust to produce the warning if WINNER
   13141              :    is actually used.  */
   13142              : 
   13143              : static void
   13144          446 : add_warning (struct z_candidate *winner, struct z_candidate *loser)
   13145              : {
   13146          446 :   candidate_warning *cw = (candidate_warning *)
   13147            0 :     conversion_obstack_alloc (sizeof (candidate_warning));
   13148          446 :   cw->loser = loser;
   13149          446 :   cw->next = winner->warnings;
   13150          446 :   winner->warnings = cw;
   13151          446 : }
   13152              : 
   13153              : /* CAND is a constructor candidate in joust in C++17 and up.  If it copies a
   13154              :    prvalue returned from a conversion function, return true.  Otherwise, return
   13155              :    false.  */
   13156              : 
   13157              : static bool
   13158      1576260 : joust_maybe_elide_copy (z_candidate *cand)
   13159              : {
   13160      1576260 :   tree fn = cand->fn;
   13161      3948566 :   if (!DECL_COPY_CONSTRUCTOR_P (fn) && !DECL_MOVE_CONSTRUCTOR_P (fn))
   13162       795965 :     return false;
   13163       780295 :   conversion *conv = cand->convs[0];
   13164       780295 :   if (conv->kind == ck_ambig)
   13165              :     return false;
   13166       780293 :   gcc_checking_assert (conv->kind == ck_ref_bind);
   13167       780293 :   conv = next_conversion (conv);
   13168       780293 :   if (conv->kind == ck_user && !TYPE_REF_P (conv->type))
   13169              :     {
   13170          122 :       gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p
   13171              :                            (conv->type, DECL_CONTEXT (fn)));
   13172          122 :       z_candidate *uc = conv->cand;
   13173          122 :       if (DECL_CONV_FN_P (uc->fn))
   13174              :         return true;
   13175              :     }
   13176              :   return false;
   13177              : }
   13178              : 
   13179              : /* Return the class that CAND's implicit object parameter refers to.  */
   13180              : 
   13181              : static tree
   13182       279849 : class_of_implicit_object (z_candidate *cand)
   13183              : {
   13184       279849 :   if (!DECL_IOBJ_MEMBER_FUNCTION_P (cand->fn))
   13185              :     return NULL_TREE;
   13186              : 
   13187              :   /* "For conversion functions that are implicit object member functions,
   13188              :      the function is considered to be a member of the class of the implied
   13189              :      object argument for the purpose of defining the type of the implicit
   13190              :      object parameter."  */
   13191       279849 :   if (DECL_CONV_FN_P (cand->fn))
   13192            0 :     return TYPE_MAIN_VARIANT (TREE_TYPE (cand->first_arg));
   13193              : 
   13194              :   /* "For non-conversion functions that are implicit object member
   13195              :      functions nominated by a using-declaration in a derived class, the
   13196              :      function is considered to be a member of the derived class for the
   13197              :      purpose of defining the type of the implicit object parameter."
   13198              : 
   13199              :      That derived class is reflected in the conversion_path binfo.  */
   13200       279849 :   return BINFO_TYPE (cand->conversion_path);
   13201              : }
   13202              : 
   13203              : /* Return whether the first parameter of C1 matches the second parameter
   13204              :    of C2.  */
   13205              : 
   13206              : static bool
   13207       522733 : reversed_match (z_candidate *c1, z_candidate *c2)
   13208              : {
   13209       522733 :   tree fn1 = c1->fn;
   13210       522733 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (c2->fn));
   13211       522733 :   tree parm2 = TREE_VALUE (TREE_CHAIN (parms2));
   13212       522733 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn1))
   13213              :     {
   13214       279849 :       tree ctx = class_of_implicit_object (c1);
   13215       279849 :       return iobj_parm_corresponds_to (fn1, parm2, ctx);
   13216              :     }
   13217              :   else
   13218              :     {
   13219       242884 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13220       242884 :       tree parm1 = TREE_VALUE (parms1);
   13221       242884 :       return same_type_p (parm1, parm2);
   13222              :     }
   13223              : }
   13224              : 
   13225              : /* True if the defining declarations of the two candidates have equivalent
   13226              :    parameters.  MATCH_KIND controls whether we're trying to compare the
   13227              :    original declarations (for a warning) or the actual candidates.  */
   13228              : 
   13229              : enum class pmatch { original, current };
   13230              : 
   13231              : static bool
   13232      7061696 : cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
   13233              : {
   13234      7061696 :   tree fn1 = c1->fn;
   13235      7061696 :   tree fn2 = c2->fn;
   13236      7061696 :   bool reversed = (match_kind == pmatch::current
   13237      7061696 :                    && c1->reversed () != c2->reversed ());
   13238      7061696 :   if (fn1 == fn2 && !reversed)
   13239              :     return true;
   13240      7061447 :   if (identifier_p (fn1) || identifier_p (fn2))
   13241              :     return false;
   13242      7061430 :   if (match_kind == pmatch::original)
   13243              :     {
   13244              :       /* We don't look at c1->template_decl because that's only set for
   13245              :          primary templates, not e.g. non-template member functions of
   13246              :          class templates.  */
   13247           22 :       tree t1 = most_general_template (fn1);
   13248           22 :       tree t2 = most_general_template (fn2);
   13249           22 :       if (t1 || t2)
   13250              :         {
   13251           15 :           if (!t1 || !t2)
   13252              :             return false;
   13253           15 :           if (t1 == t2)
   13254              :             return true;
   13255            3 :           fn1 = DECL_TEMPLATE_RESULT (t1);
   13256            3 :           fn2 = DECL_TEMPLATE_RESULT (t2);
   13257              :         }
   13258              :     }
   13259              : 
   13260      7061418 :   tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13261      7061418 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2));
   13262              : 
   13263     13918298 :   if (DECL_FUNCTION_MEMBER_P (fn1)
   13264      7061831 :       && DECL_FUNCTION_MEMBER_P (fn2))
   13265              :     {
   13266       204937 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (fn1));
   13267       204937 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (fn2));
   13268       204937 :       if (base1 != base2)
   13269       140384 :         return false;
   13270              : 
   13271       204760 :       if (reversed)
   13272       140207 :         return (reversed_match (c1, c2)
   13273       140207 :                 && reversed_match (c2, c1));
   13274              : 
   13275              :       /* Use object_parms_correspond to simplify comparing iobj/xobj/static
   13276              :          member functions.  */
   13277        64553 :       if (!object_parms_correspond (fn1, fn2, base1))
   13278              :         return false;
   13279              : 
   13280              :       /* We just compared the object parameters, if they don't correspond
   13281              :          we already returned false.  */
   13282       193659 :       auto skip_parms = [] (tree fn, tree parms)
   13283              :         {
   13284       129106 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   13285          680 :             return TREE_CHAIN (parms);
   13286              :           else
   13287       128426 :             return skip_artificial_parms_for (fn, parms);
   13288              :         };
   13289        64553 :       parms1 = skip_parms (fn1, parms1);
   13290        64553 :       parms2 = skip_parms (fn2, parms2);
   13291              :     }
   13292      6856481 :   else if (reversed)
   13293       121423 :     return (reversed_match (c1, c2)
   13294       121423 :             && reversed_match (c2, c1));
   13295      6799611 :   return compparms (parms1, parms2);
   13296              : }
   13297              : 
   13298              : /* True iff FN is a copy or move constructor or assignment operator.  */
   13299              : 
   13300              : static bool
   13301     30353034 : sfk_copy_or_move (tree fn)
   13302              : {
   13303     30353034 :   if (TREE_CODE (fn) != FUNCTION_DECL)
   13304              :     return false;
   13305     30352944 :   special_function_kind sfk = special_function_p (fn);
   13306     30352944 :   return sfk >= sfk_copy_constructor && sfk <= sfk_move_assignment;
   13307              : }
   13308              : 
   13309              : /* Compare two candidates for overloading as described in
   13310              :    [over.match.best].  Return values:
   13311              : 
   13312              :       1: cand1 is better than cand2
   13313              :      -1: cand2 is better than cand1
   13314              :       0: cand1 and cand2 are indistinguishable */
   13315              : 
   13316              : static int
   13317     95981344 : joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn,
   13318              :        tsubst_flags_t complain)
   13319              : {
   13320     95981344 :   int winner = 0;
   13321     95981344 :   int off1 = 0, off2 = 0;
   13322     95981344 :   size_t i;
   13323     95981344 :   size_t len;
   13324              : 
   13325              :   /* Candidates that involve bad conversions are always worse than those
   13326              :      that don't.  */
   13327     95981344 :   if (cand1->viable > cand2->viable)
   13328              :     return 1;
   13329     77610148 :   if (cand1->viable < cand2->viable)
   13330              :     return -1;
   13331              : 
   13332              :   /* If we have two pseudo-candidates for conversions to the same type,
   13333              :      or two candidates for the same function, arbitrarily pick one.  */
   13334     77610148 :   if (cand1->fn == cand2->fn
   13335      2637407 :       && cand1->reversed () == cand2->reversed ()
   13336     78599625 :       && (IS_TYPE_OR_DECL_P (cand1->fn)))
   13337              :     return 1;
   13338              : 
   13339              :   /* Prefer a non-deleted function over an implicitly deleted move
   13340              :      constructor or assignment operator.  This differs slightly from the
   13341              :      wording for issue 1402 (which says the move op is ignored by overload
   13342              :      resolution), but this way produces better error messages.  */
   13343     77610148 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13344     73306439 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13345    150909612 :       && DECL_DELETED_FN (cand1->fn) != DECL_DELETED_FN (cand2->fn))
   13346              :     {
   13347      3389194 :       if (DECL_DELETED_FN (cand1->fn) && DECL_DEFAULTED_FN (cand1->fn)
   13348      2849777 :           && move_fn_p (cand1->fn))
   13349              :         return -1;
   13350      5152972 :       if (DECL_DELETED_FN (cand2->fn) && DECL_DEFAULTED_FN (cand2->fn)
   13351      3777078 :           && move_fn_p (cand2->fn))
   13352              :         return 1;
   13353              :     }
   13354              : 
   13355              :   /* a viable function F1
   13356              :      is defined to be a better function than another viable function F2  if
   13357              :      for  all arguments i, ICSi(F1) is not a worse conversion sequence than
   13358              :      ICSi(F2), and then */
   13359              : 
   13360              :   /* for some argument j, ICSj(F1) is a better conversion  sequence  than
   13361              :      ICSj(F2) */
   13362              : 
   13363              :   /* For comparing static and non-static member functions, we ignore
   13364              :      the implicit object parameter of the non-static function.  The
   13365              :      standard says to pretend that the static function has an object
   13366              :      parm, but that won't work with operator overloading.  */
   13367     77580137 :   len = cand1->num_convs;
   13368     77580137 :   if (len != cand2->num_convs)
   13369              :     {
   13370          378 :       int static_1 = (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13371          378 :                       && DECL_STATIC_FUNCTION_P (cand1->fn));
   13372          378 :       int static_2 = (TREE_CODE (cand2->fn) == FUNCTION_DECL
   13373          378 :                       && DECL_STATIC_FUNCTION_P (cand2->fn));
   13374              : 
   13375          378 :       if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13376          139 :           && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13377          139 :           && DECL_CONSTRUCTOR_P (cand1->fn)
   13378          384 :           && is_list_ctor (cand1->fn) != is_list_ctor (cand2->fn))
   13379              :         /* We're comparing a near-match list constructor and a near-match
   13380              :            non-list constructor.  Just treat them as unordered.  */
   13381              :         return 0;
   13382              : 
   13383          372 :       gcc_assert (static_1 != static_2);
   13384              : 
   13385          372 :       if (static_1)
   13386              :         {
   13387              :           /* C++23 [over.best.ics.general] says:
   13388              :              When the parameter is the implicit object parameter of a static
   13389              :              member function, the implicit conversion sequence is a standard
   13390              :              conversion sequence that is neither better nor worse than any
   13391              :              other standard conversion sequence.  */
   13392           46 :           if (CONVERSION_RANK (cand2->convs[0]) >= cr_user)
   13393            0 :             winner = 1;
   13394              :           off2 = 1;
   13395              :         }
   13396              :       else
   13397              :         {
   13398          326 :           if (CONVERSION_RANK (cand1->convs[0]) >= cr_user)
   13399          239 :             winner = -1;
   13400          326 :           off1 = 1;
   13401          326 :           --len;
   13402              :         }
   13403              :     }
   13404              : 
   13405    209243147 :   for (i = 0; i < len; ++i)
   13406              :     {
   13407    131664257 :       conversion *t1 = cand1->convs[i + off1];
   13408    131664257 :       conversion *t2 = cand2->convs[i + off2];
   13409    131664257 :       int comp = compare_ics (t1, t2);
   13410              : 
   13411    131664257 :       if (comp != 0)
   13412              :         {
   13413     66474925 :           if ((complain & tf_warning)
   13414     54705634 :               && warn_sign_promo
   13415           82 :               && (CONVERSION_RANK (t1) + CONVERSION_RANK (t2)
   13416              :                   == cr_std + cr_promotion)
   13417           50 :               && t1->kind == ck_std
   13418           31 :               && t2->kind == ck_std
   13419           31 :               && TREE_CODE (t1->type) == INTEGER_TYPE
   13420           31 :               && TREE_CODE (t2->type) == INTEGER_TYPE
   13421           31 :               && (TYPE_PRECISION (t1->type)
   13422           31 :                   == TYPE_PRECISION (t2->type))
   13423     66474956 :               && (TYPE_UNSIGNED (next_conversion (t1)->type)
   13424            0 :                   || (TREE_CODE (next_conversion (t1)->type)
   13425              :                       == ENUMERAL_TYPE)))
   13426              :             {
   13427           31 :               tree type = next_conversion (t1)->type;
   13428           31 :               tree type1, type2;
   13429           31 :               struct z_candidate *w, *l;
   13430           31 :               if (comp > 0)
   13431              :                 type1 = t1->type, type2 = t2->type,
   13432              :                   w = cand1, l = cand2;
   13433              :               else
   13434            8 :                 type1 = t2->type, type2 = t1->type,
   13435            8 :                   w = cand2, l = cand1;
   13436              : 
   13437           31 :               if (warn)
   13438              :                 {
   13439            9 :                   warning (OPT_Wsign_promo, "passing %qT chooses %qT over %qT",
   13440              :                            type, type1, type2);
   13441            9 :                   warning (OPT_Wsign_promo, "  in call to %qD", w->fn);
   13442              :                 }
   13443              :               else
   13444           22 :                 add_warning (w, l);
   13445              :             }
   13446              : 
   13447     66474925 :           if (winner && comp != winner)
   13448              :             {
   13449              :               /* Ambiguity between normal and reversed comparison operators
   13450              :                  with the same parameter types.  P2468 decided not to go with
   13451              :                  this approach to resolving the ambiguity, so pedwarn.  */
   13452         1241 :               if ((complain & tf_warning_or_error)
   13453          690 :                   && (cand1->reversed () != cand2->reversed ())
   13454         1529 :                   && cand_parms_match (cand1, cand2, pmatch::original))
   13455              :                 {
   13456          273 :                   struct z_candidate *w, *l;
   13457          273 :                   if (cand2->reversed ())
   13458              :                     winner = 1, w = cand1, l = cand2;
   13459              :                   else
   13460          251 :                     winner = -1, w = cand2, l = cand1;
   13461          273 :                   if (warn)
   13462              :                     {
   13463           22 :                       auto_diagnostic_group d;
   13464           22 :                       if (pedwarn (input_location, 0,
   13465              :                                    "C++20 says that these are ambiguous, "
   13466              :                                    "even though the second is reversed:"))
   13467              :                         {
   13468           22 :                           print_z_candidate (input_location,
   13469              :                                              N_("candidate 1:"), w);
   13470           22 :                           print_z_candidate (input_location,
   13471              :                                              N_("candidate 2:"), l);
   13472           22 :                           if (w->fn == l->fn
   13473           17 :                               && DECL_IOBJ_MEMBER_FUNCTION_P (w->fn)
   13474           37 :                               && (type_memfn_quals (TREE_TYPE (w->fn))
   13475           15 :                                   & TYPE_QUAL_CONST) == 0)
   13476              :                             {
   13477              :                               /* Suggest adding const to
   13478              :                                  struct A { bool operator==(const A&); }; */
   13479           12 :                               tree parmtype
   13480           12 :                                 = FUNCTION_FIRST_USER_PARMTYPE (w->fn);
   13481           12 :                               parmtype = TREE_VALUE (parmtype);
   13482           12 :                               if (TYPE_REF_P (parmtype)
   13483           12 :                                   && TYPE_READONLY (TREE_TYPE (parmtype))
   13484           24 :                                   && (same_type_ignoring_top_level_qualifiers_p
   13485           12 :                                       (TREE_TYPE (parmtype),
   13486           12 :                                        DECL_CONTEXT (w->fn))))
   13487           12 :                                 inform (DECL_SOURCE_LOCATION (w->fn),
   13488              :                                         "try making the operator a %<const%> "
   13489              :                                         "member function");
   13490              :                             }
   13491              :                         }
   13492           22 :                     }
   13493              :                   else
   13494          251 :                     add_warning (w, l);
   13495          273 :                   return winner;
   13496              :                 }
   13497              : 
   13498          968 :               winner = 0;
   13499          968 :               goto tweak;
   13500              :             }
   13501              :           winner = comp;
   13502              :         }
   13503              :     }
   13504              : 
   13505              :   /* warn about confusing overload resolution for user-defined conversions,
   13506              :      either between a constructor and a conversion op, or between two
   13507              :      conversion ops.  */
   13508     77578890 :   if ((complain & tf_warning)
   13509              :       /* In C++17, the constructor might have been elided, which means that
   13510              :          an originally null ->second_conv could become non-null.  */
   13511     62589032 :       && winner && warn_conversion && cand1->second_conv && cand2->second_conv
   13512           54 :       && (!DECL_CONSTRUCTOR_P (cand1->fn) || !DECL_CONSTRUCTOR_P (cand2->fn))
   13513     77578917 :       && winner != compare_ics (cand1->second_conv, cand2->second_conv))
   13514              :     {
   13515           27 :       struct z_candidate *w, *l;
   13516           27 :       bool give_warning = false;
   13517              : 
   13518           27 :       if (winner == 1)
   13519              :         w = cand1, l = cand2;
   13520              :       else
   13521            6 :         w = cand2, l = cand1;
   13522              : 
   13523              :       /* We don't want to complain about `X::operator T1 ()'
   13524              :          beating `X::operator T2 () const', when T2 is a no less
   13525              :          cv-qualified version of T1.  */
   13526           27 :       if (DECL_CONTEXT (w->fn) == DECL_CONTEXT (l->fn)
   13527           39 :           && !DECL_CONSTRUCTOR_P (w->fn) && !DECL_CONSTRUCTOR_P (l->fn))
   13528              :         {
   13529            6 :           tree t = TREE_TYPE (TREE_TYPE (l->fn));
   13530            6 :           tree f = TREE_TYPE (TREE_TYPE (w->fn));
   13531              : 
   13532            6 :           if (TREE_CODE (t) == TREE_CODE (f) && INDIRECT_TYPE_P (t))
   13533              :             {
   13534            6 :               t = TREE_TYPE (t);
   13535            6 :               f = TREE_TYPE (f);
   13536              :             }
   13537            6 :           if (!comp_ptr_ttypes (t, f))
   13538              :             give_warning = true;
   13539              :         }
   13540              :       else
   13541              :         give_warning = true;
   13542              : 
   13543              :       if (!give_warning)
   13544              :         /*NOP*/;
   13545           21 :       else if (warn)
   13546              :         {
   13547            9 :           tree source = source_type (w->convs[0]);
   13548            9 :           if (INDIRECT_TYPE_P (source))
   13549            6 :             source = TREE_TYPE (source);
   13550            9 :           auto_diagnostic_group d;
   13551            9 :           if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn)
   13552           18 :               && warning (OPT_Wconversion, "  for conversion from %qH to %qI",
   13553            9 :                           source, w->second_conv->type))
   13554              :             {
   13555            9 :               inform (input_location, "  because conversion sequence "
   13556              :                       "for the argument is better");
   13557              :             }
   13558            9 :         }
   13559              :       else
   13560           12 :         add_warning (w, l);
   13561              :     }
   13562              : 
   13563     77578890 :   if (winner)
   13564              :     return winner;
   13565              : 
   13566              :   /* DR 495 moved this tiebreaker above the template ones.  */
   13567              :   /* or, if not that,
   13568              :      the  context  is  an  initialization by user-defined conversion (see
   13569              :      _dcl.init_  and  _over.match.user_)  and  the  standard   conversion
   13570              :      sequence  from  the return type of F1 to the destination type (i.e.,
   13571              :      the type of the entity being initialized)  is  a  better  conversion
   13572              :      sequence  than the standard conversion sequence from the return type
   13573              :      of F2 to the destination type.  */
   13574              : 
   13575     15176657 :   if (cand1->second_conv)
   13576              :     {
   13577        50056 :       winner = compare_ics (cand1->second_conv, cand2->second_conv);
   13578        50056 :       if (winner)
   13579              :         return winner;
   13580              :     }
   13581              : 
   13582              :   /* CWG2735 (PR109247): A copy/move ctor/op= for which its operand uses an
   13583              :      explicit conversion (due to list-initialization) is worse.  */
   13584     15176517 :   {
   13585     15176517 :     z_candidate *sp = nullptr;
   13586     15176517 :     if (sfk_copy_or_move (cand1->fn))
   13587          492 :       sp = cand1;
   13588     15176517 :     if (sfk_copy_or_move (cand2->fn))
   13589      1967495 :       sp = sp ? nullptr : cand2;
   13590     15176468 :     if (sp)
   13591              :       {
   13592      3935778 :         conversion *conv = sp->convs[!DECL_CONSTRUCTOR_P (sp->fn)];
   13593      1967889 :         if (conv->user_conv_p)
   13594         1242 :           for (; conv; conv = next_conversion (conv))
   13595         1108 :             if (conv->kind == ck_user
   13596          487 :                 && DECL_P (conv->cand->fn)
   13597         1595 :                 && DECL_NONCONVERTING_P (conv->cand->fn))
   13598          359 :               return (sp == cand1) ? -1 : 1;
   13599              :       }
   13600              :   }
   13601              : 
   13602              :   /* DR2327: C++17 copy elision in [over.match.ctor] (direct-init) context.
   13603              :      The standard currently says that only constructors are candidates, but if
   13604              :      one copies a prvalue returned by a conversion function we prefer that.
   13605              : 
   13606              :      Clang does something similar, as discussed at
   13607              :      http://lists.isocpp.org/core/2017/10/3166.php
   13608              :      http://lists.isocpp.org/core/2019/03/5721.php  */
   13609      7843744 :   if (len == 1 && cxx_dialect >= cxx17
   13610      7829930 :       && DECL_P (cand1->fn)
   13611      7829930 :       && DECL_COMPLETE_CONSTRUCTOR_P (cand1->fn)
   13612     17077024 :       && !(cand1->flags & LOOKUP_ONLYCONVERTING))
   13613              :     {
   13614       788130 :       bool elided1 = joust_maybe_elide_copy (cand1);
   13615       788130 :       bool elided2 = joust_maybe_elide_copy (cand2);
   13616       788130 :       winner = elided1 - elided2;
   13617       788130 :       if (winner)
   13618              :         return winner;
   13619              :     }
   13620              : 
   13621              :   /* or, if not that,
   13622              :      F1 is a non-template function and F2 is a template function
   13623              :      specialization.  */
   13624              : 
   13625     15176147 :   if (!cand1->template_decl && cand2->template_decl)
   13626              :     return 1;
   13627     15013388 :   else if (cand1->template_decl && !cand2->template_decl)
   13628              :     return -1;
   13629              : 
   13630              :   /* or, if not that,
   13631              :      F1 and F2 are template functions and the function template for F1 is
   13632              :      more specialized than the template for F2 according to the partial
   13633              :      ordering rules.  */
   13634              : 
   13635     12549792 :   if (cand1->template_decl && cand2->template_decl)
   13636              :     {
   13637      5476192 :       winner = more_specialized_fn
   13638      5476192 :         (TI_TEMPLATE (cand1->template_decl),
   13639      5476192 :          TI_TEMPLATE (cand2->template_decl),
   13640              :          /* [temp.func.order]: The presence of unused ellipsis and default
   13641              :             arguments has no effect on the partial ordering of function
   13642              :             templates.   add_function_candidate() will not have
   13643              :             counted the "this" argument for constructors.  */
   13644     10952384 :          cand1->num_convs + DECL_CONSTRUCTOR_P (cand1->fn));
   13645      5476192 :       if (winner)
   13646              :         return winner;
   13647              :     }
   13648              : 
   13649              :   /* F1 and F2 are non-template functions and
   13650              :      - they have the same non-object-parameter-type-lists ([dcl.fct]), and
   13651              :      - if they are member functions, both are direct members of the same
   13652              :        class, and
   13653              :      - if both are non-static member functions, they have the same types for
   13654              :        their object parameters, and
   13655              :      - F1 is more constrained than F2 according to the partial ordering of
   13656              :        constraints described in [temp.constr.order].  */
   13657      8942539 :   if (flag_concepts && DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13658      8942491 :       && !cand1->template_decl && !cand2->template_decl
   13659     16016452 :       && cand_parms_match (cand1, cand2, pmatch::current))
   13660              :     {
   13661       374931 :       winner = more_constrained (cand1->fn, cand2->fn);
   13662       374931 :       if (winner)
   13663              :         return winner;
   13664              :     }
   13665              : 
   13666              :   /* F2 is a rewritten candidate (12.4.1.2) and F1 is not, or F1 and F2 are
   13667              :      rewritten candidates, and F2 is a synthesized candidate with reversed
   13668              :      order of parameters and F1 is not.  */
   13669      8948778 :   if (cand1->rewritten ())
   13670              :     {
   13671      1874580 :       if (!cand2->rewritten ())
   13672              :         return -1;
   13673      1287833 :       if (!cand1->reversed () && cand2->reversed ())
   13674              :         return 1;
   13675      1287833 :       if (cand1->reversed () && !cand2->reversed ())
   13676              :         return -1;
   13677              :     }
   13678      7074198 :   else if (cand2->rewritten ())
   13679              :     return 1;
   13680              : 
   13681      7012665 :   if (deduction_guide_p (cand1->fn))
   13682              :     {
   13683        19535 :       gcc_assert (deduction_guide_p (cand2->fn));
   13684              : 
   13685              :       /* F1 and F2 are generated from class template argument deduction for a
   13686              :          class D, and F2 is generated from inheriting constructors from a base
   13687              :          class of D while F1 is not, and for each explicit function argument,
   13688              :          the corresponding parameters of F1 and F2 are either both ellipses or
   13689              :          have the same type.  */
   13690        19535 :       bool inherited1 = inherited_guide_p (cand1->fn);
   13691        19535 :       bool inherited2 = inherited_guide_p (cand2->fn);
   13692        19535 :       if (int diff = inherited2 - inherited1)
   13693              :         {
   13694           52 :           for (i = 0; i < len; ++i)
   13695              :             {
   13696           15 :               conversion *t1 = cand1->convs[i + off1];
   13697           15 :               conversion *t2 = cand2->convs[i + off2];
   13698              :               /* ??? It seems the ellipses part of this tiebreaker isn't
   13699              :                  needed since a mismatch should have broken the tie earlier
   13700              :                  during ICS comparison.  */
   13701           15 :               gcc_checking_assert (t1->ellipsis_p == t2->ellipsis_p);
   13702           15 :               if (!same_type_p (t1->type, t2->type))
   13703              :                 break;
   13704              :             }
   13705           39 :           if (i == len)
   13706              :             return diff;
   13707              :         }
   13708              : 
   13709              :       /* F1 is generated from a deduction-guide (13.3.1.8) and F2 is not */
   13710              :       /* We distinguish between candidates from an explicit deduction guide and
   13711              :          candidates built from a constructor based on DECL_ARTIFICIAL.  */
   13712        19498 :       int art1 = DECL_ARTIFICIAL (cand1->fn);
   13713        19498 :       int art2 = DECL_ARTIFICIAL (cand2->fn);
   13714        19498 :       if (art1 != art2)
   13715         1047 :         return art2 - art1;
   13716              : 
   13717        18451 :       if (art1)
   13718              :         {
   13719              :           /* Prefer the special copy guide over a declared copy/move
   13720              :              constructor.  */
   13721        18448 :           if (copy_guide_p (cand1->fn))
   13722              :             return 1;
   13723           81 :           if (copy_guide_p (cand2->fn))
   13724              :             return -1;
   13725              : 
   13726              :           /* Prefer a candidate generated from a non-template constructor.  */
   13727           26 :           int tg1 = template_guide_p (cand1->fn);
   13728           26 :           int tg2 = template_guide_p (cand2->fn);
   13729           26 :           if (tg1 != tg2)
   13730            6 :             return tg2 - tg1;
   13731              :         }
   13732              :     }
   13733              : 
   13734              :   /* F1 is a constructor for a class D, F2 is a constructor for a base class B
   13735              :      of D, and for all arguments the corresponding parameters of F1 and F2 have
   13736              :      the same type (CWG 2273/2277).  */
   13737     20979304 :   if (DECL_INHERITED_CTOR (cand1->fn) || DECL_INHERITED_CTOR (cand2->fn))
   13738              :     {
   13739           87 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (cand1->fn));
   13740           87 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (cand2->fn));
   13741              : 
   13742           87 :       bool used1 = false;
   13743           87 :       bool used2 = false;
   13744           87 :       if (base1 == base2)
   13745              :         /* No difference.  */;
   13746           87 :       else if (DERIVED_FROM_P (base1, base2))
   13747              :         used1 = true;
   13748           18 :       else if (DERIVED_FROM_P (base2, base1))
   13749              :         used2 = true;
   13750              : 
   13751           78 :       if (int diff = used2 - used1)
   13752              :         {
   13753          105 :           for (i = 0; i < len; ++i)
   13754              :             {
   13755           36 :               conversion *t1 = cand1->convs[i + off1];
   13756           36 :               conversion *t2 = cand2->convs[i + off2];
   13757           36 :               if (!same_type_p (t1->type, t2->type))
   13758              :                 break;
   13759              :             }
   13760           78 :           if (i == len)
   13761              :             return diff;
   13762              :         }
   13763              :     }
   13764              : 
   13765              :   /* Check whether we can discard a builtin candidate, either because we
   13766              :      have two identical ones or matching builtin and non-builtin candidates.
   13767              : 
   13768              :      (Pedantically in the latter case the builtin which matched the user
   13769              :      function should not be added to the overload set, but we spot it here.
   13770              : 
   13771              :      [over.match.oper]
   13772              :      ... the builtin candidates include ...
   13773              :      - do not have the same parameter type list as any non-template
   13774              :        non-member candidate.  */
   13775              : 
   13776      6993084 :   if (identifier_p (cand1->fn) || identifier_p (cand2->fn))
   13777              :     {
   13778           93 :       for (i = 0; i < len; ++i)
   13779           69 :         if (!same_type_p (cand1->convs[i]->type,
   13780              :                           cand2->convs[i]->type))
   13781              :           break;
   13782           43 :       if (i == cand1->num_convs)
   13783              :         {
   13784           24 :           if (cand1->fn == cand2->fn)
   13785              :             /* Two built-in candidates; arbitrarily pick one.  */
   13786              :             return 1;
   13787     22983056 :           else if (identifier_p (cand1->fn))
   13788              :             /* cand1 is built-in; prefer cand2.  */
   13789              :             return -1;
   13790              :           else
   13791              :             /* cand2 is built-in; prefer cand1.  */
   13792              :             return 1;
   13793              :         }
   13794              :     }
   13795              : 
   13796              :   /* For candidates of a multi-versioned function,  make the version with
   13797              :      the highest priority win.  This version will be checked for dispatching
   13798              :      first.  If this version can be inlined into the caller, the front-end
   13799              :      will simply make a direct call to this function.  */
   13800              : 
   13801      6993060 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13802      6993038 :       && DECL_FUNCTION_VERSIONED (cand1->fn)
   13803          902 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13804      6993962 :       && DECL_FUNCTION_VERSIONED (cand2->fn))
   13805              :     {
   13806          902 :       tree f1 = TREE_TYPE (cand1->fn);
   13807          902 :       tree f2 = TREE_TYPE (cand2->fn);
   13808          902 :       tree p1 = TYPE_ARG_TYPES (f1);
   13809          902 :       tree p2 = TYPE_ARG_TYPES (f2);
   13810              : 
   13811              :       /* Check if cand1->fn and cand2->fn are versions of the same function.  It
   13812              :          is possible that cand1->fn and cand2->fn are function versions but of
   13813              :          different functions.  Check types to see if they are versions of the same
   13814              :          function.  */
   13815          902 :       if (compparms (p1, p2)
   13816          902 :           && same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
   13817              :         {
   13818              :           /* Always make the version with the higher priority, more
   13819              :              specialized, win.  */
   13820          902 :           gcc_assert (targetm.compare_version_priority);
   13821          902 :           if (targetm.compare_version_priority (cand1->fn, cand2->fn) >= 0)
   13822              :             return 1;
   13823              :           else
   13824              :             return -1;
   13825              :         }
   13826              :     }
   13827              : 
   13828              :   /* If the two function declarations represent the same function (this can
   13829              :      happen with declarations in multiple scopes and arg-dependent lookup),
   13830              :      arbitrarily choose one.  But first make sure the default args we're
   13831              :      using match.  */
   13832      6992136 :   if (DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13833     13984294 :       && equal_functions (cand1->fn, cand2->fn))
   13834              :     {
   13835           33 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (cand1->fn));
   13836           33 :       tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (cand2->fn));
   13837              : 
   13838           66 :       gcc_assert (!DECL_CONSTRUCTOR_P (cand1->fn));
   13839              : 
   13840           47 :       for (i = 0; i < len; ++i)
   13841              :         {
   13842              :           /* Don't crash if the fn is variadic.  */
   13843           14 :           if (!parms1)
   13844              :             break;
   13845           14 :           parms1 = TREE_CHAIN (parms1);
   13846           14 :           parms2 = TREE_CHAIN (parms2);
   13847              :         }
   13848              : 
   13849           33 :       if (off1)
   13850            0 :         parms1 = TREE_CHAIN (parms1);
   13851           33 :       else if (off2)
   13852            0 :         parms2 = TREE_CHAIN (parms2);
   13853              : 
   13854           64 :       for (; parms1; ++i)
   13855              :         {
   13856           74 :           if (!cp_tree_equal (TREE_PURPOSE (parms1),
   13857           37 :                               TREE_PURPOSE (parms2)))
   13858              :             {
   13859            6 :               if (warn)
   13860              :                 {
   13861            3 :                   if (complain & tf_error)
   13862              :                     {
   13863            3 :                       auto_diagnostic_group d;
   13864            3 :                       if (permerror (input_location,
   13865              :                                      "default argument mismatch in "
   13866              :                                      "overload resolution"))
   13867              :                         {
   13868            3 :                           inform (DECL_SOURCE_LOCATION (cand1->fn),
   13869              :                                   " candidate 1: %q#F", cand1->fn);
   13870            3 :                           inform (DECL_SOURCE_LOCATION (cand2->fn),
   13871              :                                   " candidate 2: %q#F", cand2->fn);
   13872              :                         }
   13873            3 :                     }
   13874              :                   else
   13875              :                     return 0;
   13876              :                 }
   13877              :               else
   13878            3 :                 add_warning (cand1, cand2);
   13879              :               break;
   13880              :             }
   13881           31 :           parms1 = TREE_CHAIN (parms1);
   13882           31 :           parms2 = TREE_CHAIN (parms2);
   13883              :         }
   13884              : 
   13885           33 :       return 1;
   13886              :     }
   13887              : 
   13888      6993093 : tweak:
   13889              : 
   13890              :   /* Extension: If the worst conversion for one candidate is better than the
   13891              :      worst conversion for the other, take the first.  */
   13892      6993093 :   if (!pedantic && (complain & tf_warning_or_error))
   13893              :     {
   13894              :       conversion_rank rank1 = cr_identity, rank2 = cr_identity;
   13895     20939228 :       struct z_candidate *w = 0, *l = 0;
   13896              : 
   13897     20939228 :       for (i = 0; i < len; ++i)
   13898              :         {
   13899     14393484 :           if (CONVERSION_RANK (cand1->convs[i+off1]) > rank1)
   13900      6399135 :             rank1 = CONVERSION_RANK (cand1->convs[i+off1]);
   13901     14393484 :           if (CONVERSION_RANK (cand2->convs[i + off2]) > rank2)
   13902      6399152 :             rank2 = CONVERSION_RANK (cand2->convs[i + off2]);
   13903              :         }
   13904      6545744 :       if (rank1 < rank2)
   13905           56 :         winner = 1, w = cand1, l = cand2;
   13906      6545744 :       if (rank1 > rank2)
   13907              :         winner = -1, w = cand2, l = cand1;
   13908      6545636 :       if (winner)
   13909              :         {
   13910              :           /* Don't choose a deleted function over ambiguity.  */
   13911          164 :           if (DECL_P (w->fn) && DECL_DELETED_FN (w->fn))
   13912              :             return 0;
   13913          164 :           if (warn)
   13914              :             {
   13915            6 :               auto_diagnostic_group d;
   13916            6 :               if (pedwarn (input_location, 0,
   13917              :                            "ISO C++ says that these are ambiguous, even "
   13918              :                            "though the worst conversion for the first is "
   13919              :                            "better than the worst conversion for the second:"))
   13920              :                 {
   13921            3 :                   print_z_candidate (input_location, N_("candidate 1:"), w);
   13922            3 :                   print_z_candidate (input_location, N_("candidate 2:"), l);
   13923              :                 }
   13924            6 :             }
   13925              :           else
   13926          158 :             add_warning (w, l);
   13927          164 :           return winner;
   13928              :         }
   13929              :     }
   13930              : 
   13931              :   gcc_assert (!winner);
   13932              :   return 0;
   13933              : }
   13934              : 
   13935              : /* Given a list of candidates for overloading, find the best one, if any.
   13936              :    This algorithm has a worst case of O(2n) (winner is last), and a best
   13937              :    case of O(n/2) (totally ambiguous); much better than a sorting
   13938              :    algorithm.  The candidates list is assumed to be sorted according
   13939              :    to viability (via splice_viable).  */
   13940              : 
   13941              : static struct z_candidate *
   13942    306829681 : tourney (struct z_candidate *candidates, tsubst_flags_t complain)
   13943              : {
   13944    306829681 :   struct z_candidate **champ = &candidates, **challenger;
   13945    306829681 :   int fate;
   13946    306829681 :   struct z_candidate *previous_worse_champ = nullptr;
   13947              : 
   13948              :   /* Walk through the list once, comparing each current champ to the next
   13949              :      candidate, knocking out a candidate or two with each comparison.  */
   13950              : 
   13951    387493832 :   for (challenger = &candidates->next; *challenger && (*challenger)->viable; )
   13952              :     {
   13953     80748542 :       fate = joust (*champ, *challenger, 0, complain);
   13954     80748542 :       if (fate == 1)
   13955     51188339 :         challenger = &(*challenger)->next;
   13956     29560203 :       else if (fate == -1)
   13957              :         {
   13958     22568974 :           previous_worse_champ = *champ;
   13959     22568974 :           champ = challenger;
   13960     22568974 :           challenger = &(*challenger)->next;
   13961              :         }
   13962              :       else
   13963              :         {
   13964      6991229 :           previous_worse_champ = nullptr;
   13965      6991229 :           champ = &(*challenger)->next;
   13966      6991229 :           if (!*champ || !(*champ)->viable
   13967      6906932 :               || (*champ)->viable < (*challenger)->viable)
   13968              :             {
   13969              :               champ = nullptr;
   13970              :               break;
   13971              :             }
   13972      6906838 :           challenger = &(*champ)->next;
   13973              :         }
   13974              :     }
   13975              : 
   13976              :   /* Make sure the champ is better than all the candidates it hasn't yet
   13977              :      been compared to.  */
   13978              : 
   13979    306829681 :   if (champ)
   13980     36516242 :     for (challenger = &candidates;
   13981    343261532 :          challenger != champ;
   13982     36516242 :          challenger = &(*challenger)->next)
   13983              :       {
   13984     36518142 :         if (*challenger == previous_worse_champ)
   13985              :           /* We already know this candidate is worse than the champ.  */
   13986     21285389 :           continue;
   13987     15232753 :         fate = joust (*champ, *challenger, 0, complain);
   13988     15232753 :         if (fate != 1)
   13989              :           {
   13990              :             champ = nullptr;
   13991              :             break;
   13992              :           }
   13993              :       }
   13994              : 
   13995    306745290 :   if (!champ)
   13996        86291 :     return nullptr;
   13997              : 
   13998              :   /* Move the champ to the front of the candidate list.  */
   13999              : 
   14000    306743390 :   if (champ != &candidates)
   14001              :     {
   14002     23591053 :       z_candidate *saved_champ = *champ;
   14003     23591053 :       *champ = saved_champ->next;
   14004     23591053 :       saved_champ->next = candidates;
   14005     23591053 :       candidates = saved_champ;
   14006              :     }
   14007              : 
   14008    306743390 :   return candidates;
   14009              : }
   14010              : 
   14011              : /* Returns nonzero if things of type FROM can be converted to TO.  */
   14012              : 
   14013              : bool
   14014      5264189 : can_convert (tree to, tree from, tsubst_flags_t complain)
   14015              : {
   14016      5264189 :   tree arg = NULL_TREE;
   14017              :   /* implicit_conversion only considers user-defined conversions
   14018              :      if it has an expression for the call argument list.  */
   14019      5264189 :   if (CLASS_TYPE_P (from) || CLASS_TYPE_P (to))
   14020          107 :     arg = build_stub_object (from);
   14021      5264189 :   return can_convert_arg (to, from, arg, LOOKUP_IMPLICIT, complain);
   14022              : }
   14023              : 
   14024              : /* Returns nonzero if things of type FROM can be converted to TO with a
   14025              :    standard conversion.  */
   14026              : 
   14027              : bool
   14028          255 : can_convert_standard (tree to, tree from, tsubst_flags_t complain)
   14029              : {
   14030          255 :   return can_convert_arg (to, from, NULL_TREE, LOOKUP_IMPLICIT, complain);
   14031              : }
   14032              : 
   14033              : /* Returns nonzero if ARG (of type FROM) can be converted to TO.  */
   14034              : 
   14035              : bool
   14036      6112391 : can_convert_arg (tree to, tree from, tree arg, int flags,
   14037              :                  tsubst_flags_t complain)
   14038              : {
   14039      6112391 :   conversion *t;
   14040      6112391 :   bool ok_p;
   14041              : 
   14042      6112391 :   conversion_obstack_sentinel cos;
   14043              :   /* We want to discard any access checks done for this test,
   14044              :      as we might not be in the appropriate access context and
   14045              :      we'll do the check again when we actually perform the
   14046              :      conversion.  */
   14047      6112391 :   push_deferring_access_checks (dk_deferred);
   14048              : 
   14049              :   /* Handle callers like check_local_shadow forgetting to
   14050              :      convert_from_reference.  */
   14051      6112391 :   if (TYPE_REF_P (from) && arg)
   14052              :     {
   14053           52 :       arg = convert_from_reference (arg);
   14054           52 :       from = TREE_TYPE (arg);
   14055              :     }
   14056              : 
   14057      6112391 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   14058              :                             flags, complain);
   14059      6112391 :   ok_p = (t && !t->bad_p);
   14060              : 
   14061              :   /* Discard the access checks now.  */
   14062      6112391 :   pop_deferring_access_checks ();
   14063              : 
   14064     12224782 :   return ok_p;
   14065      6112391 : }
   14066              : 
   14067              : /* Like can_convert_arg, but allows dubious conversions as well.  */
   14068              : 
   14069              : bool
   14070    191650348 : can_convert_arg_bad (tree to, tree from, tree arg, int flags,
   14071              :                      tsubst_flags_t complain)
   14072              : {
   14073    191650348 :   conversion *t;
   14074              : 
   14075    191650348 :   conversion_obstack_sentinel cos;
   14076              :   /* Try to perform the conversion.  */
   14077    191650348 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   14078              :                             flags, complain);
   14079              : 
   14080    383300696 :   return t != NULL;
   14081    191650348 : }
   14082              : 
   14083              : /* Return an IMPLICIT_CONV_EXPR from EXPR to TYPE with bits set from overload
   14084              :    resolution FLAGS.  */
   14085              : 
   14086              : tree
   14087     13540989 : build_implicit_conv_flags (tree type, tree expr, int flags)
   14088              : {
   14089              :   /* In a template, we are only concerned about determining the
   14090              :      type of non-dependent expressions, so we do not have to
   14091              :      perform the actual conversion.  But for initializers, we
   14092              :      need to be able to perform it at instantiation
   14093              :      (or instantiate_non_dependent_expr) time.  */
   14094     13540989 :   expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14095     13540989 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   14096      3895418 :     IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14097     13540989 :   if (flags & LOOKUP_NO_NARROWING)
   14098        21587 :     IMPLICIT_CONV_EXPR_BRACED_INIT (expr) = true;
   14099     13540989 :   return expr;
   14100              : }
   14101              : 
   14102              : /* Convert EXPR to TYPE.  Return the converted expression.
   14103              : 
   14104              :    Note that we allow bad conversions here because by the time we get to
   14105              :    this point we are committed to doing the conversion.  If we end up
   14106              :    doing a bad conversion, convert_like will complain.  */
   14107              : 
   14108              : tree
   14109    316521468 : perform_implicit_conversion_flags (tree type, tree expr,
   14110              :                                    tsubst_flags_t complain, int flags)
   14111              : {
   14112    316521468 :   conversion *conv;
   14113    316521468 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14114              : 
   14115    316521468 :   if (error_operand_p (expr))
   14116          442 :     return error_mark_node;
   14117              : 
   14118    316521026 :   conversion_obstack_sentinel cos;
   14119              : 
   14120    316521026 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14121              :                               /*c_cast_p=*/false,
   14122              :                               flags, complain);
   14123              : 
   14124    316521026 :   if (!conv)
   14125              :     {
   14126       319412 :       if (complain & tf_error)
   14127          479 :         implicit_conversion_error (loc, type, expr, flags);
   14128       319412 :       expr = error_mark_node;
   14129              :     }
   14130    316201614 :   else if (processing_template_decl && conv->kind != ck_identity)
   14131     13522982 :     expr = build_implicit_conv_flags (type, expr, flags);
   14132              :   else
   14133              :     {
   14134              :       /* Give a conversion call the same location as expr.  */
   14135    302678632 :       iloc_sentinel il (loc);
   14136    302678632 :       expr = convert_like (conv, expr, complain);
   14137    302678632 :     }
   14138              : 
   14139    316521026 :   return expr;
   14140    316521026 : }
   14141              : 
   14142              : tree
   14143     32320825 : perform_implicit_conversion (tree type, tree expr, tsubst_flags_t complain)
   14144              : {
   14145     32320825 :   return perform_implicit_conversion_flags (type, expr, complain,
   14146     32320825 :                                             LOOKUP_IMPLICIT);
   14147              : }
   14148              : 
   14149              : /* Convert EXPR to TYPE (as a direct-initialization) if that is
   14150              :    permitted.  If the conversion is valid, the converted expression is
   14151              :    returned.  Otherwise, NULL_TREE is returned, except in the case
   14152              :    that TYPE is a class type; in that case, an error is issued.  If
   14153              :    C_CAST_P is true, then this direct-initialization is taking
   14154              :    place as part of a static_cast being attempted as part of a C-style
   14155              :    cast.  */
   14156              : 
   14157              : tree
   14158     48971448 : perform_direct_initialization_if_possible (tree type,
   14159              :                                            tree expr,
   14160              :                                            bool c_cast_p,
   14161              :                                            tsubst_flags_t complain)
   14162              : {
   14163     48971448 :   conversion *conv;
   14164              : 
   14165     48971448 :   if (type == error_mark_node || error_operand_p (expr))
   14166              :     return error_mark_node;
   14167              :   /* [dcl.init]
   14168              : 
   14169              :      If the destination type is a (possibly cv-qualified) class type:
   14170              : 
   14171              :      -- If the initialization is direct-initialization ...,
   14172              :      constructors are considered.
   14173              : 
   14174              :        -- If overload resolution is successful, the selected constructor
   14175              :        is called to initialize the object, with the initializer expression
   14176              :        or expression-list as its argument(s).
   14177              : 
   14178              :        -- Otherwise, if no constructor is viable, the destination type is
   14179              :        a (possibly cv-qualified) aggregate class A, and the initializer is
   14180              :        a parenthesized expression-list, the object is initialized as
   14181              :        follows...  */
   14182     48971448 :   if (CLASS_TYPE_P (type))
   14183              :     {
   14184      3583818 :       releasing_vec args (make_tree_vector_single (expr));
   14185      3583818 :       expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
   14186              :                                         &args, type, LOOKUP_NORMAL, complain);
   14187      3583818 :       return build_cplus_new (type, expr, complain);
   14188      3583818 :     }
   14189              : 
   14190     45387630 :   conversion_obstack_sentinel cos;
   14191              : 
   14192     45387630 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14193              :                               c_cast_p,
   14194              :                               LOOKUP_NORMAL, complain);
   14195     45387630 :   if (!conv || conv->bad_p)
   14196              :     expr = NULL_TREE;
   14197     40815161 :   else if (processing_template_decl && conv->kind != ck_identity)
   14198              :     {
   14199              :       /* In a template, we are only concerned about determining the
   14200              :          type of non-dependent expressions, so we do not have to
   14201              :          perform the actual conversion.  But for initializers, we
   14202              :          need to be able to perform it at instantiation
   14203              :          (or instantiate_non_dependent_expr) time.  */
   14204       649240 :       expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14205       649240 :       IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14206              :     }
   14207              :   else
   14208     40165921 :     expr = convert_like (conv, expr, NULL_TREE, 0,
   14209              :                          /*issue_conversion_warnings=*/false,
   14210              :                          c_cast_p, /*nested_p=*/false, complain);
   14211              : 
   14212     45387630 :   return expr;
   14213     45387630 : }
   14214              : 
   14215              : /* When initializing a reference that lasts longer than a full-expression,
   14216              :    this special rule applies:
   14217              : 
   14218              :      [class.temporary]
   14219              : 
   14220              :      The temporary to which the reference is bound or the temporary
   14221              :      that is the complete object to which the reference is bound
   14222              :      persists for the lifetime of the reference.
   14223              : 
   14224              :      The temporaries created during the evaluation of the expression
   14225              :      initializing the reference, except the temporary to which the
   14226              :      reference is bound, are destroyed at the end of the
   14227              :      full-expression in which they are created.
   14228              : 
   14229              :    In that case, we store the converted expression into a new
   14230              :    VAR_DECL in a new scope.
   14231              : 
   14232              :    However, we want to be careful not to create temporaries when
   14233              :    they are not required.  For example, given:
   14234              : 
   14235              :      struct B {};
   14236              :      struct D : public B {};
   14237              :      D f();
   14238              :      const B& b = f();
   14239              : 
   14240              :    there is no need to copy the return value from "f"; we can just
   14241              :    extend its lifetime.  Similarly, given:
   14242              : 
   14243              :      struct S {};
   14244              :      struct T { operator S(); };
   14245              :      T t;
   14246              :      const S& s = t;
   14247              : 
   14248              :   we can extend the lifetime of the return value of the conversion
   14249              :   operator.
   14250              : 
   14251              :   The next several functions are involved in this lifetime extension.  */
   14252              : 
   14253              : /* DECL is a VAR_DECL or FIELD_DECL whose type is a REFERENCE_TYPE.  The
   14254              :    reference is being bound to a temporary.  Create and return a new
   14255              :    VAR_DECL with the indicated TYPE; this variable will store the value to
   14256              :    which the reference is bound.  */
   14257              : 
   14258              : tree
   14259        24375 : make_temporary_var_for_ref_to_temp (tree decl, tree type)
   14260              : {
   14261        24375 :   tree var = create_temporary_var (type);
   14262              : 
   14263              :   /* Register the variable.  */
   14264        24375 :   if (VAR_P (decl)
   14265        24375 :       && (TREE_STATIC (decl) || CP_DECL_THREAD_LOCAL_P (decl)))
   14266              :     {
   14267              :       /* Namespace-scope or local static; give it a mangled name.  */
   14268              : 
   14269              :       /* If an initializer is visible to multiple translation units, those
   14270              :          translation units must agree on the addresses of the
   14271              :          temporaries. Therefore the temporaries must be given a consistent name
   14272              :          and vague linkage. The mangled name of a temporary is the name of the
   14273              :          non-temporary object in whose initializer they appear, prefixed with
   14274              :          GR and suffixed with a sequence number mangled using the usual rules
   14275              :          for a seq-id. Temporaries are numbered with a pre-order, depth-first,
   14276              :          left-to-right walk of the complete initializer.  */
   14277          811 :       copy_linkage (var, decl);
   14278              : 
   14279          811 :       tree name = mangle_ref_init_variable (decl);
   14280          811 :       DECL_NAME (var) = name;
   14281          811 :       SET_DECL_ASSEMBLER_NAME (var, name);
   14282              : 
   14283              :       /* Set the context to make the variable mergeable in modules.  */
   14284          811 :       DECL_CONTEXT (var) = current_scope ();
   14285              :     }
   14286              :   else
   14287              :     /* Create a new cleanup level if necessary.  */
   14288        23564 :     maybe_push_cleanup_level (type);
   14289              : 
   14290        24375 :   return pushdecl (var);
   14291              : }
   14292              : 
   14293              : static tree extend_temps_r (tree *, int *, void *);
   14294              : 
   14295              : /* EXPR is the initializer for a variable DECL of reference or
   14296              :    std::initializer_list type.  Create, push and return a new VAR_DECL
   14297              :    for the initializer so that it will live as long as DECL.  Any
   14298              :    cleanup for the new variable is returned through CLEANUP, and the
   14299              :    code to initialize the new variable is returned through INITP.  */
   14300              : 
   14301              : static tree
   14302        24375 : set_up_extended_ref_temp (tree decl, tree expr, vec<tree, va_gc> **cleanups,
   14303              :                           tree *initp, tree *cond_guard,
   14304              :                           void *walk_data)
   14305              : {
   14306        24375 :   tree init;
   14307        24375 :   tree type;
   14308        24375 :   tree var;
   14309              : 
   14310              :   /* Create the temporary variable.  */
   14311        24375 :   type = TREE_TYPE (expr);
   14312        24375 :   var = make_temporary_var_for_ref_to_temp (decl, type);
   14313        24375 :   layout_decl (var, 0);
   14314              :   /* If the rvalue is the result of a function call it will be
   14315              :      a TARGET_EXPR.  If it is some other construct (such as a
   14316              :      member access expression where the underlying object is
   14317              :      itself the result of a function call), turn it into a
   14318              :      TARGET_EXPR here.  It is important that EXPR be a
   14319              :      TARGET_EXPR below since otherwise the INIT_EXPR will
   14320              :      attempt to make a bitwise copy of EXPR to initialize
   14321              :      VAR.  */
   14322        24375 :   if (TREE_CODE (expr) != TARGET_EXPR)
   14323            0 :     expr = get_target_expr (expr);
   14324              :   else
   14325              :     {
   14326        24375 :       if (TREE_ADDRESSABLE (expr))
   14327        24301 :         TREE_ADDRESSABLE (var) = 1;
   14328        24375 :       if (DECL_MERGEABLE (TARGET_EXPR_SLOT (expr)))
   14329          535 :         DECL_MERGEABLE (var) = true;
   14330              :     }
   14331              : 
   14332        24375 :   if (TREE_CODE (decl) == FIELD_DECL
   14333        24375 :       && extra_warnings && !warning_suppressed_p (decl))
   14334              :     {
   14335            3 :       warning (OPT_Wextra, "a temporary bound to %qD only persists "
   14336              :                "until the constructor exits", decl);
   14337            3 :       suppress_warning (decl);
   14338              :     }
   14339              : 
   14340              :   /* Recursively extend temps in this initializer.  The recursion needs to come
   14341              :      after creating the variable to conform to the mangling ABI, and before
   14342              :      maybe_constant_init because the extension might change its result.  */
   14343        24375 :   if (walk_data)
   14344         1466 :     cp_walk_tree (&TARGET_EXPR_INITIAL (expr), extend_temps_r,
   14345              :                   walk_data, nullptr);
   14346              :   else
   14347        22909 :     TARGET_EXPR_INITIAL (expr)
   14348        45818 :       = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups,
   14349              :                                cond_guard);
   14350              : 
   14351              :   /* Any reference temp has a non-trivial initializer.  */
   14352        24375 :   DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
   14353              : 
   14354              :   /* Don't output reflection variables.  */
   14355        24375 :   if (consteval_only_p (var))
   14356           20 :     DECL_EXTERNAL (var) = true;
   14357              : 
   14358              :   /* If the initializer is constant, put it in DECL_INITIAL so we get
   14359              :      static initialization and use in constant expressions.  */
   14360        24375 :   init = maybe_constant_init (expr, var, /*manifestly_const_eval=*/true);
   14361              :   /* As in store_init_value.  */
   14362        24375 :   init = cp_fully_fold (init);
   14363        24375 :   if (TREE_CONSTANT (init))
   14364              :     {
   14365         1078 :       if (literal_type_p (type)
   14366         1052 :           && CP_TYPE_CONST_NON_VOLATILE_P (type)
   14367         1710 :           && !TYPE_HAS_MUTABLE_P (type))
   14368              :         {
   14369              :           /* 5.19 says that a constant expression can include an
   14370              :              lvalue-rvalue conversion applied to "a glvalue of literal type
   14371              :              that refers to a non-volatile temporary object initialized
   14372              :              with a constant expression".  Rather than try to communicate
   14373              :              that this VAR_DECL is a temporary, just mark it constexpr.  */
   14374          629 :           DECL_DECLARED_CONSTEXPR_P (var) = true;
   14375          629 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = true;
   14376          629 :           TREE_CONSTANT (var) = true;
   14377          629 :           TREE_READONLY (var) = true;
   14378              :         }
   14379         1078 :       DECL_INITIAL (var) = init;
   14380         1078 :       init = NULL_TREE;
   14381              :     }
   14382              :   else
   14383              :     /* Create the INIT_EXPR that will initialize the temporary
   14384              :        variable.  */
   14385        23297 :     init = split_nonconstant_init (var, expr);
   14386        24375 :   if (at_function_scope_p ())
   14387              :     {
   14388        23686 :       add_decl_expr (var);
   14389              : 
   14390        23686 :       if (TREE_STATIC (var))
   14391          122 :         init = add_stmt_to_compound (init, register_dtor_fn (var));
   14392              :       else
   14393              :         {
   14394              :           /* ??? Instead of rebuilding the cleanup, we could replace the slot
   14395              :              with var in TARGET_EXPR_CLEANUP (expr).  */
   14396        23564 :           tree cleanup = cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14397        23564 :           if (cleanup)
   14398              :             {
   14399        19359 :               if (cond_guard && cleanup != error_mark_node)
   14400              :                 {
   14401           23 :                   if (*cond_guard == NULL_TREE)
   14402              :                     {
   14403           23 :                       *cond_guard = build_local_temp (boolean_type_node);
   14404           23 :                       add_decl_expr (*cond_guard);
   14405           23 :                       tree set = cp_build_modify_expr (UNKNOWN_LOCATION,
   14406              :                                                        *cond_guard, NOP_EXPR,
   14407              :                                                        boolean_false_node,
   14408              :                                                        tf_warning_or_error);
   14409           23 :                       finish_expr_stmt (set);
   14410              :                     }
   14411           23 :                   cleanup = build3 (COND_EXPR, void_type_node,
   14412              :                                     *cond_guard, cleanup, NULL_TREE);
   14413              :                 }
   14414        19359 :               if (flag_exceptions && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE)
   14415              :                 {
   14416              :                   /* The normal cleanup for this extended variable isn't pushed
   14417              :                      until cp_finish_decl, so we need to retain a TARGET_EXPR
   14418              :                      to clean it up in case a later initializer throws
   14419              :                      (g++.dg/eh/ref-temp3.C).
   14420              : 
   14421              :                      We don't do this for array temporaries because they have
   14422              :                      the array cleanup region from build_vec_init.
   14423              : 
   14424              :                      Unlike maybe_push_temp_cleanup, we don't actually need a
   14425              :                      flag, but a TARGET_EXPR needs a TARGET_EXPR_SLOT.
   14426              :                      Perhaps this could use WITH_CLEANUP_EXPR instead, but
   14427              :                      gimplify.cc doesn't handle that, and front-end handling
   14428              :                      was removed in r8-1725 and r8-1818.
   14429              : 
   14430              :                      Alternately it might be preferable to flatten an
   14431              :                      initialization with extended temps into a sequence of
   14432              :                      (non-full-expression) statements, so we could immediately
   14433              :                      push_cleanup here for only a single cleanup region, but we
   14434              :                      don't have a mechanism for that in the front-end, only the
   14435              :                      gimplifier.  */
   14436        19249 :                   tree targ = get_internal_target_expr (boolean_true_node);
   14437        19249 :                   TARGET_EXPR_CLEANUP (targ) = cleanup;
   14438        19249 :                   CLEANUP_EH_ONLY (targ) = true;
   14439              :                   /* Don't actually initialize the bool.  */
   14440        19249 :                   init = (!init ? void_node
   14441        19223 :                           : convert_to_void (init, ICV_STATEMENT, tf_none));
   14442        19249 :                   TARGET_EXPR_INITIAL (targ) = init;
   14443        19249 :                   init = targ;
   14444              :                 }
   14445        19359 :               vec_safe_push (*cleanups, cleanup);
   14446              :             }
   14447              :         }
   14448              : 
   14449              :       /* We must be careful to destroy the temporary only
   14450              :          after its initialization has taken place.  If the
   14451              :          initialization throws an exception, then the
   14452              :          destructor should not be run.  We cannot simply
   14453              :          transform INIT into something like:
   14454              : 
   14455              :          (INIT, ({ CLEANUP_STMT; }))
   14456              : 
   14457              :          because emit_local_var always treats the
   14458              :          initializer as a full-expression.  Thus, the
   14459              :          destructor would run too early; it would run at the
   14460              :          end of initializing the reference variable, rather
   14461              :          than at the end of the block enclosing the
   14462              :          reference variable.
   14463              : 
   14464              :          The solution is to pass back a cleanup expression
   14465              :          which the caller is responsible for attaching to
   14466              :          the statement tree.  */
   14467              :     }
   14468              :   else
   14469              :     {
   14470          689 :       rest_of_decl_compilation (var, /*toplev=*/1, at_eof);
   14471          689 :       if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
   14472              :         {
   14473           88 :           if (CP_DECL_THREAD_LOCAL_P (var))
   14474           36 :             tls_aggregates = tree_cons (NULL_TREE, var,
   14475              :                                         tls_aggregates);
   14476              :           else
   14477           52 :             static_aggregates = tree_cons (NULL_TREE, var,
   14478              :                                            static_aggregates);
   14479              :         }
   14480              :       else
   14481              :         /* Check whether the dtor is callable.  */
   14482          601 :         cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14483              :     }
   14484              :   /* Avoid -Wunused-variable warning (c++/38958).  */
   14485        24375 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   14486        24375 :       && VAR_P (decl))
   14487        19414 :     TREE_USED (decl) = DECL_READ_P (decl) = true;
   14488              : 
   14489        24375 :   *initp = init;
   14490        24375 :   return var;
   14491              : }
   14492              : 
   14493              : /* Convert EXPR to the indicated reference TYPE, in a way suitable for
   14494              :    initializing a variable of that TYPE.  */
   14495              : 
   14496              : tree
   14497      7760726 : initialize_reference (tree type, tree expr,
   14498              :                       int flags, tsubst_flags_t complain)
   14499              : {
   14500      7760726 :   conversion *conv;
   14501      7760726 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14502              : 
   14503      7760726 :   if (type == error_mark_node || error_operand_p (expr))
   14504              :     return error_mark_node;
   14505              : 
   14506      7760658 :   conversion_obstack_sentinel cos;
   14507              : 
   14508      7760658 :   conv = reference_binding (type, TREE_TYPE (expr), expr, /*c_cast_p=*/false,
   14509              :                             flags, complain);
   14510              :   /* If this conversion failed, we're in C++20, and we have something like
   14511              :      A& a(b) where A is an aggregate, try again, this time as A& a{b}.  */
   14512      7760658 :   if ((!conv || conv->bad_p)
   14513          670 :       && (flags & LOOKUP_AGGREGATE_PAREN_INIT))
   14514              :     {
   14515            4 :       tree e = build_constructor_single (init_list_type_node, NULL_TREE, expr);
   14516            4 :       CONSTRUCTOR_IS_DIRECT_INIT (e) = true;
   14517            4 :       CONSTRUCTOR_IS_PAREN_INIT (e) = true;
   14518            4 :       conversion *c = reference_binding (type, TREE_TYPE (e), e,
   14519              :                                          /*c_cast_p=*/false, flags, complain);
   14520              :       /* If this worked, use it.  */
   14521            4 :       if (c && !c->bad_p)
   14522              :         expr = e, conv = c;
   14523              :     }
   14524      7761249 :   if (!conv || conv->bad_p)
   14525              :     {
   14526          667 :       if (complain & tf_error)
   14527              :         {
   14528          349 :           if (conv)
   14529          303 :             convert_like (conv, expr, complain);
   14530           46 :           else if (!CP_TYPE_CONST_P (TREE_TYPE (type))
   14531           14 :                    && !TYPE_REF_IS_RVALUE (type)
   14532           60 :                    && !lvalue_p (expr))
   14533            6 :             error_at (loc, "invalid initialization of non-const reference of "
   14534              :                       "type %qH from an rvalue of type %qI",
   14535            6 :                       type, TREE_TYPE (expr));
   14536              :           else
   14537           40 :             error_at (loc, "invalid initialization of reference of type "
   14538              :                       "%qH from expression of type %qI", type,
   14539           40 :                       TREE_TYPE (expr));
   14540              :         }
   14541          667 :       return error_mark_node;
   14542              :     }
   14543              : 
   14544      7759991 :   if (conv->kind == ck_ref_bind)
   14545              :     /* Perform the conversion.  */
   14546      7759988 :     expr = convert_like (conv, expr, complain);
   14547            3 :   else if (conv->kind == ck_ambig)
   14548              :     /* We gave an error in build_user_type_conversion_1.  */
   14549            3 :     expr = error_mark_node;
   14550              :   else
   14551            0 :     gcc_unreachable ();
   14552              : 
   14553              :   return expr;
   14554      7760658 : }
   14555              : 
   14556              : /* Return true if T is std::pair<const T&, const T&>.  */
   14557              : 
   14558              : static bool
   14559       573508 : std_pair_ref_ref_p (tree t)
   14560              : {
   14561              :   /* First, check if we have std::pair.  */
   14562        53594 :   if (!NON_UNION_CLASS_TYPE_P (t)
   14563       626660 :       || !CLASSTYPE_TEMPLATE_INSTANTIATION (t))
   14564              :     return false;
   14565        19181 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (t));
   14566        19181 :   if (!decl_in_std_namespace_p (tdecl))
   14567              :     return false;
   14568        14136 :   tree name = DECL_NAME (tdecl);
   14569        14136 :   if (!name || !id_equal (name, "pair"))
   14570              :     return false;
   14571              : 
   14572              :   /* Now see if the template arguments are both const T&.  */
   14573          343 :   tree args = CLASSTYPE_TI_ARGS (t);
   14574          343 :   if (TREE_VEC_LENGTH (args) != 2)
   14575              :     return false;
   14576          403 :   for (int i = 0; i < 2; i++)
   14577          433 :     if (!TYPE_REF_OBJ_P (TREE_VEC_ELT (args, i))
   14578          433 :         || !CP_TYPE_CONST_P (TREE_TYPE (TREE_VEC_ELT (args, i))))
   14579          313 :       return false;
   14580              : 
   14581              :   return true;
   14582              : }
   14583              : 
   14584              : /* Return true if a class T has a reference member.  */
   14585              : 
   14586              : static bool
   14587          216 : class_has_reference_member_p (tree t)
   14588              : {
   14589          216 :   for (tree fields = TYPE_FIELDS (t);
   14590         3380 :        fields;
   14591         3164 :        fields = DECL_CHAIN (fields))
   14592         3227 :     if (TREE_CODE (fields) == FIELD_DECL
   14593          196 :         && !DECL_ARTIFICIAL (fields)
   14594         3394 :         && TYPE_REF_P (TREE_TYPE (fields)))
   14595              :       return true;
   14596              :   return false;
   14597              : }
   14598              : 
   14599              : /* A wrapper for the above suitable as a callback for dfs_walk_once.  */
   14600              : 
   14601              : static tree
   14602          216 : class_has_reference_member_p_r (tree binfo, void *)
   14603              : {
   14604          216 :   return (class_has_reference_member_p (BINFO_TYPE (binfo))
   14605          216 :           ? integer_one_node : NULL_TREE);
   14606              : }
   14607              : 
   14608              : 
   14609              : /* Return true if T (either a class or a function) has been marked as
   14610              :    not-dangling.  */
   14611              : 
   14612              : static bool
   14613         1526 : no_dangling_p (tree t)
   14614              : {
   14615         1526 :   t = lookup_attribute ("no_dangling", TYPE_ATTRIBUTES (t));
   14616         1526 :   if (!t)
   14617              :     return false;
   14618              : 
   14619           75 :   t = TREE_VALUE (t);
   14620           75 :   if (!t)
   14621              :     return true;
   14622              : 
   14623           51 :   t = build_converted_constant_bool_expr (TREE_VALUE (t), tf_warning_or_error);
   14624           51 :   t = cxx_constant_value (t);
   14625           51 :   return t == boolean_true_node;
   14626              : }
   14627              : 
   14628              : /* Return true if a class CTYPE is either std::reference_wrapper or
   14629              :    std::ref_view, or a reference wrapper class.  We consider a class
   14630              :    a reference wrapper class if it has a reference member.  We no
   14631              :    longer check that it has a constructor taking the same reference type
   14632              :    since that approach still generated too many false positives.  */
   14633              : 
   14634              : static bool
   14635          446 : reference_like_class_p (tree ctype)
   14636              : {
   14637          446 :   if (!CLASS_TYPE_P (ctype))
   14638              :     return false;
   14639              : 
   14640          314 :   if (no_dangling_p (ctype))
   14641              :     return true;
   14642              : 
   14643              :   /* Also accept a std::pair<const T&, const T&>.  */
   14644          290 :   if (std_pair_ref_ref_p (ctype))
   14645              :     return true;
   14646              : 
   14647          275 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (ctype));
   14648          275 :   if (decl_in_std_namespace_p (tdecl))
   14649              :     {
   14650           38 :       tree name = DECL_NAME (tdecl);
   14651           38 :       if (name
   14652           38 :           && (id_equal (name, "reference_wrapper")
   14653           26 :               || id_equal (name, "span")
   14654           11 :               || id_equal (name, "ref_view")))
   14655              :         return true;
   14656              :     }
   14657              : 
   14658              :   /* Avoid warning if CTYPE looks like std::span: it has a T* member and
   14659              :      a trivial destructor.  For example,
   14660              : 
   14661              :       template<typename T>
   14662              :       struct Span {
   14663              :         T* data_;
   14664              :         std::size len_;
   14665              :       };
   14666              : 
   14667              :      is considered std::span-like.  */
   14668          248 :   if (NON_UNION_CLASS_TYPE_P (ctype) && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
   14669          228 :     for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
   14670          367 :          field; field = next_aggregate_field (DECL_CHAIN (field)))
   14671          199 :       if (TYPE_PTR_P (TREE_TYPE (field)))
   14672              :         return true;
   14673              : 
   14674              :   /* Some classes, such as std::tuple, have the reference member in its
   14675              :      (non-direct) base class.  */
   14676          188 :   if (dfs_walk_once (TYPE_BINFO (ctype), class_has_reference_member_p_r,
   14677              :                      nullptr, nullptr))
   14678              :     return true;
   14679              : 
   14680              :   return false;
   14681              : }
   14682              : 
   14683              : /* Helper for maybe_warn_dangling_reference to find a problematic temporary
   14684              :    in EXPR (as outlined in maybe_warn_dangling_reference), or NULL_TREE
   14685              :    if none found.  For instance:
   14686              : 
   14687              :      const S& s = S().self(); // S()
   14688              :      const int& r = (42, f(1)); // temporary for passing 1 to f
   14689              :      const int& t = b ? f(1) : f(2); // temporary for 1
   14690              :      const int& u = b ? f(1) : f(g); // temporary for 1
   14691              :      const int& v = b ? f(g) : f(2); // temporary for 2
   14692              :      const int& w = b ? f(g) : f(g); // NULL_TREE
   14693              :      const int& y = (f(1), 42); // NULL_TREE
   14694              :      const int& z = f(f(1)); // temporary for 1
   14695              : 
   14696              :    EXPR is the initializer.  If ARG_P is true, we're processing an argument
   14697              :    to a function; the point is to distinguish between, for example,
   14698              : 
   14699              :      Ref::inner (&TARGET_EXPR <D.2839, F::foo (fm)>)
   14700              : 
   14701              :    where we shouldn't warn, and
   14702              : 
   14703              :      Ref::inner (&TARGET_EXPR <D.2908, F::foo (&TARGET_EXPR <...>)>)
   14704              : 
   14705              :    where we should warn (Ref is a reference_like_class_p so we see through
   14706              :    it.  */
   14707              : 
   14708              : static tree
   14709         3794 : do_warn_dangling_reference (tree expr, bool arg_p)
   14710              : {
   14711         3794 :   STRIP_NOPS (expr);
   14712              : 
   14713         3794 :   if (arg_p && expr_represents_temporary_p (expr))
   14714              :     {
   14715              :       /* An attempt to reduce the number of -Wdangling-reference
   14716              :          false positives concerning reference wrappers (c++/107532).
   14717              :          When we encounter a reference_like_class_p, we don't warn
   14718              :          just yet; instead, we keep recursing to see if there were
   14719              :          any temporaries behind the reference-wrapper class.  */
   14720              :       tree e = expr;
   14721          354 :       while (handled_component_p (e))
   14722           15 :         e = TREE_OPERAND (e, 0);
   14723          339 :       tree type = TREE_TYPE (e);
   14724              :       /* If the temporary represents a lambda, we don't really know
   14725              :          what's going on here.  */
   14726          461 :       if (!reference_like_class_p (type) && !LAMBDA_TYPE_P (type))
   14727              :         return expr;
   14728              :     }
   14729              : 
   14730         3562 :   switch (TREE_CODE (expr))
   14731              :     {
   14732         1779 :     case CALL_EXPR:
   14733         1779 :       {
   14734         1779 :         tree fndecl = cp_get_callee_fndecl_nofold (expr);
   14735         1779 :         if (!fndecl
   14736         1779 :             || warning_suppressed_p (fndecl, OPT_Wdangling_reference)
   14737         1768 :             || !warning_enabled_at (DECL_SOURCE_LOCATION (fndecl),
   14738         1768 :                                     OPT_Wdangling_reference)
   14739              :             /* Don't emit a false positive for:
   14740              :                 std::vector<int> v = ...;
   14741              :                 std::vector<int>::const_iterator it = v.begin();
   14742              :                 const int &r = *it++;
   14743              :                because R refers to one of the int elements of V, not to
   14744              :                a temporary object.  Member operator* may return a reference
   14745              :                but probably not to one of its arguments.  */
   14746         1409 :             || (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   14747          835 :                 && DECL_OVERLOADED_OPERATOR_P (fndecl)
   14748          306 :                 && DECL_OVERLOADED_OPERATOR_IS (fndecl, INDIRECT_REF))
   14749         2991 :             || no_dangling_p (TREE_TYPE (fndecl)))
   14750          591 :           return NULL_TREE;
   14751              : 
   14752         1188 :         tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
   14753              :         /* If the function doesn't return a reference, don't warn.  This
   14754              :            can be e.g.
   14755              :              const int& z = std::min({1, 2, 3, 4, 5, 6, 7});
   14756              :            which doesn't dangle: std::min here returns an int.
   14757              : 
   14758              :            If the function returns a std::pair<const T&, const T&>, we
   14759              :            warn, to detect e.g.
   14760              :              std::pair<const int&, const int&> v = std::minmax(1, 2);
   14761              :            which also creates a dangling reference, because std::minmax
   14762              :            returns std::pair<const T&, const T&>(b, a).  */
   14763         1188 :         if (!(TYPE_REF_OBJ_P (rettype) || reference_like_class_p (rettype)))
   14764              :           return NULL_TREE;
   14765              : 
   14766              :         /* Here we're looking to see if any of the arguments is a temporary
   14767              :            initializing a reference parameter.  */
   14768         1592 :         for (int i = 0; i < call_expr_nargs (expr); ++i)
   14769              :           {
   14770         1210 :             tree arg = CALL_EXPR_ARG (expr, i);
   14771              :             /* Check that this argument initializes a reference, except for
   14772              :                the argument initializing the object of a member function.  */
   14773         1210 :             if (!DECL_IOBJ_MEMBER_FUNCTION_P (fndecl)
   14774         1210 :                 && !TYPE_REF_P (TREE_TYPE (arg)))
   14775          130 :               continue;
   14776         1080 :             STRIP_NOPS (arg);
   14777         1080 :             if (TREE_CODE (arg) == ADDR_EXPR)
   14778          699 :               arg = TREE_OPERAND (arg, 0);
   14779              :             /* Recurse to see if the argument is a temporary.  It could also
   14780              :                be another call taking a temporary and returning it and
   14781              :                initializing this reference parameter.  */
   14782         1080 :             if ((arg = do_warn_dangling_reference (arg, /*arg_p=*/true)))
   14783              :               {
   14784              :                 /* If we know the temporary could not bind to the return type,
   14785              :                    don't warn.  This is for scalars and empty classes only
   14786              :                    because for other classes we can't be sure we are not
   14787              :                    returning its sub-object.  */
   14788          277 :                 if ((SCALAR_TYPE_P (TREE_TYPE (arg))
   14789          152 :                      || is_empty_class (TREE_TYPE (arg)))
   14790          152 :                     && TYPE_REF_P (rettype)
   14791          137 :                     && !reference_related_p (TREE_TYPE (rettype),
   14792          137 :                                              TREE_TYPE (arg)))
   14793           21 :                   continue;
   14794          256 :                 return arg;
   14795              :               }
   14796              :           /* Don't warn about member functions like:
   14797              :               std::any a(...);
   14798              :               S& s = a.emplace<S>({0}, 0);
   14799              :              which construct a new object and return a reference to it, but
   14800              :              we still want to detect:
   14801              :                struct S { const S& self () { return *this; } };
   14802              :                const S& s = S().self();
   14803              :              where 's' dangles.  If we've gotten here, the object this function
   14804              :              is invoked on is not a temporary.  */
   14805          803 :             if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl))
   14806              :               break;
   14807              :           }
   14808              :         return NULL_TREE;
   14809              :       }
   14810           28 :     case COMPOUND_EXPR:
   14811           28 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 1), arg_p);
   14812           31 :     case COND_EXPR:
   14813           31 :       if (tree t = do_warn_dangling_reference (TREE_OPERAND (expr, 1), arg_p))
   14814              :         return t;
   14815           16 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 2), arg_p);
   14816            0 :     case PAREN_EXPR:
   14817            0 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 0), arg_p);
   14818          122 :     case TARGET_EXPR:
   14819          122 :       return do_warn_dangling_reference (TARGET_EXPR_INITIAL (expr), arg_p);
   14820              :     default:
   14821              :       return NULL_TREE;
   14822              :     }
   14823              : }
   14824              : 
   14825              : /* Implement -Wdangling-reference, to detect cases like
   14826              : 
   14827              :      int n = 1;
   14828              :      const int& r = std::max(n - 1, n + 1); // r is dangling
   14829              : 
   14830              :    This creates temporaries from the arguments, returns a reference to
   14831              :    one of the temporaries, but both temporaries are destroyed at the end
   14832              :    of the full expression.
   14833              : 
   14834              :    This works by checking if a reference is initialized with a function
   14835              :    that returns a reference, and at least one parameter of the function
   14836              :    is a reference that is bound to a temporary.  It assumes that such a
   14837              :    function actually returns one of its arguments.
   14838              : 
   14839              :    DECL is the reference being initialized, INIT is the initializer.  */
   14840              : 
   14841              : static void
   14842    119306004 : maybe_warn_dangling_reference (const_tree decl, tree init)
   14843              : {
   14844    119306004 :   if (!warn_dangling_reference)
   14845              :     return;
   14846       575720 :   tree type = TREE_TYPE (decl);
   14847              :   /* Only warn if what we're initializing has type T&& or const T&, or
   14848              :      std::pair<const T&, const T&>.  (A non-const lvalue reference can't
   14849              :      bind to a temporary.)  */
   14850      1148938 :   if (!((TYPE_REF_OBJ_P (type)
   14851         5342 :          && (TYPE_REF_IS_RVALUE (type)
   14852         4934 :              || CP_TYPE_CONST_P (TREE_TYPE (type))))
   14853       573218 :         || std_pair_ref_ref_p (type)))
   14854              :     return;
   14855              :   /* Don't suppress the diagnostic just because the call comes from
   14856              :      a system header.  If the DECL is not in a system header, or if
   14857              :      -Wsystem-headers was provided, warn.  */
   14858         2517 :   auto wsh
   14859         2517 :     = make_temp_override (global_dc->m_warn_system_headers,
   14860         2517 :                           (!in_system_header_at (DECL_SOURCE_LOCATION (decl))
   14861         2517 :                            || global_dc->m_warn_system_headers));
   14862         2517 :   if (tree call = do_warn_dangling_reference (init, /*arg_p=*/false))
   14863              :     {
   14864          211 :       auto_diagnostic_group d;
   14865          211 :       if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wdangling_reference,
   14866              :                       "possibly dangling reference to a temporary"))
   14867          211 :         inform (EXPR_LOCATION (call), "%qT temporary created here",
   14868          211 :                 TREE_TYPE (call));
   14869          211 :     }
   14870         2517 : }
   14871              : 
   14872              : /* If *P is an xvalue expression, prevent temporary lifetime extension if it
   14873              :    gets used to initialize a reference.  */
   14874              : 
   14875              : static tree
   14876           89 : prevent_lifetime_extension (tree t)
   14877              : {
   14878           89 :   tree *p = &t;
   14879           89 :   while (TREE_CODE (*p) == COMPOUND_EXPR)
   14880            0 :     p = &TREE_OPERAND (*p, 1);
   14881           98 :   while (handled_component_p (*p))
   14882            9 :     p = &TREE_OPERAND (*p, 0);
   14883              :   /* Change a TARGET_EXPR from prvalue to xvalue.  */
   14884           89 :   if (TREE_CODE (*p) == TARGET_EXPR)
   14885            3 :     *p = build2 (COMPOUND_EXPR, TREE_TYPE (*p), *p,
   14886            3 :                  move (TARGET_EXPR_SLOT (*p)));
   14887           89 :   return t;
   14888              : }
   14889              : 
   14890              : /* Subroutine of extend_ref_init_temps.  Possibly extend one initializer,
   14891              :    which is bound either to a reference or a std::initializer_list.  */
   14892              : 
   14893              : static tree
   14894      1679410 : extend_ref_init_temps_1 (tree decl, tree init, vec<tree, va_gc> **cleanups,
   14895              :                          tree *cond_guard)
   14896              : {
   14897              :   /* CWG1299 (C++20): The temporary object to which the reference is bound or
   14898              :      the temporary object that is the complete object of a subobject to which
   14899              :      the reference is bound persists for the lifetime of the reference if the
   14900              :      glvalue to which the reference is bound was obtained through one of the
   14901              :      following:
   14902              :      - a temporary materialization conversion ([conv.rval]),
   14903              :      - ( expression ), where expression is one of these expressions,
   14904              :      - subscripting ([expr.sub]) of an array operand, where that operand is one
   14905              :        of these expressions,
   14906              :      - a class member access ([expr.ref]) using the . operator where the left
   14907              :        operand is one of these expressions and the right operand designates a
   14908              :        non-static data member of non-reference type,
   14909              :      - a pointer-to-member operation ([expr.mptr.oper]) using the .* operator
   14910              :        where the left operand is one of these expressions and the right operand
   14911              :        is a pointer to data member of non-reference type,
   14912              :      - a const_cast ([expr.const.cast]), static_cast ([expr.static.cast]),
   14913              :        dynamic_cast ([expr.dynamic.cast]), or reinterpret_cast
   14914              :        ([expr.reinterpret.cast]) converting, without a user-defined conversion,
   14915              :        a glvalue operand that is one of these expressions to a glvalue that
   14916              :        refers to the object designated by the operand, or to its complete
   14917              :        object or a subobject thereof,
   14918              :      - a conditional expression ([expr.cond]) that is a glvalue where the
   14919              :        second or third operand is one of these expressions, or
   14920              :      - a comma expression ([expr.comma]) that is a glvalue where the right
   14921              :        operand is one of these expressions.  */
   14922              : 
   14923              :   /* FIXME several cases are still handled wrong (101572, 81420).  */
   14924              : 
   14925      1679410 :   tree sub = init;
   14926      1679410 :   tree *p;
   14927      1679410 :   STRIP_NOPS (sub);
   14928      1679410 :   if (TREE_CODE (sub) == COMPOUND_EXPR)
   14929              :     {
   14930          242 :       TREE_OPERAND (sub, 1)
   14931          242 :         = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   14932              :                                    cond_guard);
   14933          242 :       return init;
   14934              :     }
   14935      1679168 :   if (TREE_CODE (sub) == POINTER_PLUS_EXPR
   14936      1679168 :       && TYPE_PTRDATAMEM_P (TREE_TYPE (tree_strip_nop_conversions
   14937              :                                        (TREE_OPERAND (sub, 1)))))
   14938              :     {
   14939              :       /* A pointer-to-member operation.  */
   14940            6 :       TREE_OPERAND (sub, 0)
   14941            6 :         = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 0), cleanups,
   14942              :                                    cond_guard);
   14943            6 :       return init;
   14944              :     }
   14945      1679162 :   if (TREE_CODE (sub) == COND_EXPR)
   14946              :     {
   14947        21758 :       tree cur_cond_guard = NULL_TREE;
   14948        21758 :       if (TREE_OPERAND (sub, 1))
   14949        21758 :         TREE_OPERAND (sub, 1)
   14950        43516 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   14951              :                                      &cur_cond_guard);
   14952        21758 :       if (cur_cond_guard)
   14953              :         {
   14954            9 :           tree set = cp_build_modify_expr (UNKNOWN_LOCATION, cur_cond_guard,
   14955              :                                            NOP_EXPR, boolean_true_node,
   14956              :                                            tf_warning_or_error);
   14957            9 :           TREE_OPERAND (sub, 1)
   14958           18 :             = cp_build_compound_expr (set, TREE_OPERAND (sub, 1),
   14959              :                                       tf_warning_or_error);
   14960              :         }
   14961        21758 :       cur_cond_guard = NULL_TREE;
   14962        21758 :       if (TREE_OPERAND (sub, 2))
   14963        21758 :         TREE_OPERAND (sub, 2)
   14964        43516 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 2), cleanups,
   14965              :                                      &cur_cond_guard);
   14966        21758 :       if (cur_cond_guard)
   14967              :         {
   14968           12 :           tree set = cp_build_modify_expr (UNKNOWN_LOCATION, cur_cond_guard,
   14969              :                                            NOP_EXPR, boolean_true_node,
   14970              :                                            tf_warning_or_error);
   14971           12 :           TREE_OPERAND (sub, 2)
   14972           24 :             = cp_build_compound_expr (set, TREE_OPERAND (sub, 2),
   14973              :                                       tf_warning_or_error);
   14974              :         }
   14975        21758 :       return init;
   14976              :     }
   14977      1657404 :   if (TREE_CODE (sub) != ADDR_EXPR)
   14978              :     return init;
   14979              :   /* Deal with binding to a subobject.  */
   14980      1053505 :   for (p = &TREE_OPERAND (sub, 0);
   14981      1066974 :        TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   14982        13469 :     p = &TREE_OPERAND (*p, 0);
   14983      1053505 :   if (TREE_CODE (*p) == TARGET_EXPR)
   14984              :     {
   14985        22909 :       tree subinit = NULL_TREE;
   14986        22909 :       *p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit,
   14987              :                                      cond_guard, nullptr);
   14988        22909 :       recompute_tree_invariant_for_addr_expr (sub);
   14989        22909 :       if (init != sub)
   14990        22891 :         init = fold_convert (TREE_TYPE (init), sub);
   14991        22909 :       if (subinit)
   14992        21963 :         init = build2 (COMPOUND_EXPR, TREE_TYPE (init), subinit, init);
   14993              :     }
   14994              :   return init;
   14995              : }
   14996              : 
   14997              : /* Data for extend_temps_r, mostly matching the parameters of
   14998              :    extend_ref_init_temps.  */
   14999              : 
   15000              : struct extend_temps_data
   15001              : {
   15002              :   tree decl;
   15003              :   tree init;
   15004              :   vec<tree, va_gc> **cleanups;
   15005              :   tree* cond_guard;
   15006              :   hash_set<tree> *pset;            // For avoiding redundant walk_tree.
   15007              :   hash_map<tree, tree> *var_map; // For remapping extended temps.
   15008              : };
   15009              : 
   15010              : /* Tree walk function for extend_all_temps.  Generally parallel to
   15011              :    extend_ref_init_temps_1, but adapted for walk_tree.  */
   15012              : 
   15013              : tree
   15014        69187 : extend_temps_r (tree *tp, int *walk_subtrees, void *data)
   15015              : {
   15016        69187 :   extend_temps_data *d = (extend_temps_data *)data;
   15017              : 
   15018        69187 :   if (TREE_CODE (*tp) == VAR_DECL)
   15019              :     {
   15020         8831 :       if (tree *r = d->var_map->get (*tp))
   15021            0 :         *tp = *r;
   15022         8831 :       return NULL_TREE;
   15023              :     }
   15024              : 
   15025        60341 :   if (TYPE_P (*tp) || TREE_CODE (*tp) == CLEANUP_POINT_EXPR
   15026       120696 :       || d->pset->add (*tp))
   15027              :     {
   15028         3540 :       *walk_subtrees = 0;
   15029         3540 :       return NULL_TREE;
   15030              :     }
   15031              : 
   15032        56816 :   if (TREE_CODE (*tp) == COND_EXPR)
   15033              :     {
   15034            8 :       cp_walk_tree (&TREE_OPERAND (*tp, 0), extend_temps_r, d, nullptr);
   15035              : 
   15036           24 :       auto walk_arm = [d](tree &op)
   15037              :       {
   15038           16 :         tree cur_cond_guard = NULL_TREE;
   15039           16 :         auto ov = make_temp_override (d->cond_guard, &cur_cond_guard);
   15040           16 :         cp_walk_tree (&op, extend_temps_r, d, nullptr);
   15041           16 :         if (cur_cond_guard)
   15042              :           {
   15043            2 :             tree set = build2 (MODIFY_EXPR, boolean_type_node,
   15044              :                                cur_cond_guard, boolean_true_node);
   15045            2 :             op = cp_build_compound_expr (set, op, tf_none);
   15046              :           }
   15047           24 :       };
   15048            8 :       walk_arm (TREE_OPERAND (*tp, 1));
   15049            8 :       walk_arm (TREE_OPERAND (*tp, 2));
   15050              : 
   15051            8 :       *walk_subtrees = 0;
   15052            8 :       return NULL_TREE;
   15053              :     }
   15054              : 
   15055        56808 :   tree *p = tp;
   15056              : 
   15057        56808 :   if (TREE_CODE (*tp) == ADDR_EXPR)
   15058        12951 :     for (p = &TREE_OPERAND (*tp, 0);
   15059        14019 :          TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   15060         1068 :       p = &TREE_OPERAND (*p, 0);
   15061              : 
   15062        56808 :   if (TREE_CODE (*p) == TARGET_EXPR
   15063              :       /* An eliding TARGET_EXPR isn't a temporary at all.  */
   15064         2328 :       && !TARGET_EXPR_ELIDING_P (*p)
   15065              :       /* A TARGET_EXPR with TARGET_EXPR_INTERNAL_P is an artificial variable
   15066              :          used during initialization that need not be extended.  */
   15067        58575 :       && !TARGET_EXPR_INTERNAL_P (*p))
   15068              :     {
   15069              :       /* A CLEANUP_EH_ONLY expr should also have TARGET_EXPR_INTERNAL_P.  */
   15070         1466 :       gcc_checking_assert (!CLEANUP_EH_ONLY (*p));
   15071              : 
   15072         1466 :       tree subinit = NULL_TREE;
   15073         1466 :       tree slot = TARGET_EXPR_SLOT (*p);
   15074         1466 :       *p = set_up_extended_ref_temp (d->decl, *p, d->cleanups, &subinit,
   15075              :                                      d->cond_guard, d);
   15076         1466 :       if (TREE_CODE (*tp) == ADDR_EXPR)
   15077         1452 :         recompute_tree_invariant_for_addr_expr (*tp);
   15078         1466 :       if (subinit)
   15079         1360 :         *tp = cp_build_compound_expr (subinit, *tp, tf_none);
   15080         1466 :       d->var_map->put (slot, *p);
   15081              :     }
   15082              : 
   15083              :   return NULL_TREE;
   15084              : }
   15085              : 
   15086              : /* Extend all the temporaries in a for-range-initializer.  */
   15087              : 
   15088              : static tree
   15089        13908 : extend_all_temps (tree decl, tree init, vec<tree, va_gc> **cleanups)
   15090              : {
   15091        13908 :   hash_set<tree> pset;
   15092        13908 :   hash_map<tree, tree> map;
   15093        13908 :   gcc_assert (!TREE_STATIC (decl));
   15094        13908 :   extend_temps_data d = { decl, init, cleanups, nullptr, &pset, &map };
   15095        13908 :   cp_walk_tree (&init, extend_temps_r, &d, nullptr);
   15096        13908 :   return init;
   15097        13908 : }
   15098              : 
   15099              : /* INIT is part of the initializer for DECL.  If there are any
   15100              :    reference or initializer lists being initialized, extend their
   15101              :    lifetime to match that of DECL.  */
   15102              : 
   15103              : tree
   15104    121567507 : extend_ref_init_temps (tree decl, tree init, vec<tree, va_gc> **cleanups,
   15105              :                        tree *cond_guard)
   15106              : {
   15107    121567507 :   tree type = TREE_TYPE (init);
   15108    121567507 :   if (processing_template_decl)
   15109              :     return init;
   15110              : 
   15111              :   /* P2718R0 - in C++23 for-range-initializer, extend all temps.  */
   15112    119319912 :   if (DECL_NAME (decl) == for_range__identifier
   15113       112202 :       && flag_range_for_ext_temps
   15114              :       /* Iterating expansion statement decl is static right now, but that
   15115              :          could change depending on CWG3044 and CWG3043.  */
   15116    119333856 :       && !TREE_STATIC (decl))
   15117              :     {
   15118        13908 :       gcc_checking_assert (!cond_guard);
   15119        13908 :       return extend_all_temps (decl, init, cleanups);
   15120              :     }
   15121              : 
   15122    119306004 :   maybe_warn_dangling_reference (decl, init);
   15123              : 
   15124    119306004 :   if (TYPE_REF_P (type))
   15125      1635067 :     init = extend_ref_init_temps_1 (decl, init, cleanups, cond_guard);
   15126              :   else
   15127              :     {
   15128    117670937 :       tree ctor = init;
   15129    117670937 :       if (TREE_CODE (ctor) == TARGET_EXPR)
   15130      2295007 :         ctor = TARGET_EXPR_INITIAL (ctor);
   15131    117670937 :       if (TREE_CODE (ctor) == CONSTRUCTOR)
   15132              :         {
   15133              :           /* [dcl.init] When initializing an aggregate from a parenthesized list
   15134              :              of values... a temporary object bound to a reference does not have
   15135              :              its lifetime extended.  */
   15136      6827674 :           if (CONSTRUCTOR_IS_PAREN_INIT (ctor))
   15137              :             return init;
   15138              : 
   15139      6827310 :           if (is_std_init_list (type))
   15140              :             {
   15141              :               /* The temporary array underlying a std::initializer_list
   15142              :                  is handled like a reference temporary.  */
   15143          579 :               tree array = CONSTRUCTOR_ELT (ctor, 0)->value;
   15144          579 :               array = extend_ref_init_temps_1 (decl, array, cleanups,
   15145              :                                                cond_guard);
   15146          579 :               CONSTRUCTOR_ELT (ctor, 0)->value = array;
   15147              :             }
   15148              :           else
   15149              :             {
   15150      6826731 :               unsigned i;
   15151      6826731 :               constructor_elt *p;
   15152      6826731 :               vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (ctor);
   15153     67327876 :               FOR_EACH_VEC_SAFE_ELT (elts, i, p)
   15154     60501145 :                 p->value = extend_ref_init_temps (decl, p->value, cleanups,
   15155              :                                                   cond_guard);
   15156              :             }
   15157      6827310 :           recompute_constructor_flags (ctor);
   15158      6827310 :           if (decl_maybe_constant_var_p (decl) && TREE_CONSTANT (ctor))
   15159      2686754 :             DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
   15160              :         }
   15161              :     }
   15162              : 
   15163              :   return init;
   15164              : }
   15165              : 
   15166              : /* Returns true iff an initializer for TYPE could contain temporaries that
   15167              :    need to be extended because they are bound to references or
   15168              :    std::initializer_list.  */
   15169              : 
   15170              : bool
   15171         5256 : type_has_extended_temps (tree type)
   15172              : {
   15173         5256 :   type = strip_array_types (type);
   15174         5256 :   if (TYPE_REF_P (type))
   15175              :     return true;
   15176         5199 :   if (CLASS_TYPE_P (type))
   15177              :     {
   15178         2828 :       if (is_std_init_list (type))
   15179              :         return true;
   15180         2825 :       for (tree f = next_aggregate_field (TYPE_FIELDS (type));
   15181         6665 :            f; f = next_aggregate_field (DECL_CHAIN (f)))
   15182         3969 :         if (type_has_extended_temps (TREE_TYPE (f)))
   15183              :           return true;
   15184              :     }
   15185              :   return false;
   15186              : }
   15187              : 
   15188              : /* Returns true iff TYPE is some variant of std::initializer_list.  */
   15189              : 
   15190              : bool
   15191    186526862 : is_std_init_list (tree type)
   15192              : {
   15193    186526862 :   if (!TYPE_P (type))
   15194              :     return false;
   15195    186526839 :   if (cxx_dialect == cxx98)
   15196              :     return false;
   15197              :   /* Look through typedefs.  */
   15198    186166525 :   type = TYPE_MAIN_VARIANT (type);
   15199    150810967 :   return (CLASS_TYPE_P (type)
   15200    150676215 :           && CP_TYPE_CONTEXT (type) == std_node
   15201    268085365 :           && init_list_identifier == DECL_NAME (TYPE_NAME (type)));
   15202              : }
   15203              : 
   15204              : /* Returns true iff DECL is a list constructor: i.e. a constructor which
   15205              :    will accept an argument list of a single std::initializer_list<T>.  */
   15206              : 
   15207              : bool
   15208    159998597 : is_list_ctor (tree decl)
   15209              : {
   15210    159998597 :   tree args = FUNCTION_FIRST_USER_PARMTYPE (decl);
   15211    159998597 :   tree arg;
   15212              : 
   15213    159998597 :   if (!args || args == void_list_node)
   15214              :     return false;
   15215              : 
   15216    128331538 :   arg = non_reference (TREE_VALUE (args));
   15217    128331538 :   if (!is_std_init_list (arg))
   15218              :     return false;
   15219              : 
   15220      2163715 :   args = TREE_CHAIN (args);
   15221              : 
   15222      3667267 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   15223              :     /* There are more non-defaulted parms.  */
   15224              :     return false;
   15225              : 
   15226              :   return true;
   15227              : }
   15228              : 
   15229              : /* We know that can_convert_arg_bad already said "no" when trying to convert
   15230              :    FROM to TO with ARG and FLAGS.  Try to figure out if it was because
   15231              :    an explicit conversion function was skipped when looking for a way to
   15232              :    perform the conversion.  At this point we've already printed an error.  */
   15233              : 
   15234              : void
   15235         2055 : maybe_show_nonconverting_candidate (tree to, tree from, tree arg, int flags)
   15236              : {
   15237         2055 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   15238          287 :     return;
   15239              : 
   15240         1768 :   conversion_obstack_sentinel cos;
   15241         1768 :   conversion *c = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   15242              :                                        flags & ~LOOKUP_ONLYCONVERTING, tf_none);
   15243         1768 :   if (c && !c->bad_p && c->user_conv_p)
   15244              :     /* Ay, the conversion would have worked in direct-init context.  */
   15245          778 :     for (; c; c = next_conversion (c))
   15246          521 :       if (c->kind == ck_user
   15247          254 :           && DECL_P (c->cand->fn)
   15248          775 :           && DECL_NONCONVERTING_P (c->cand->fn))
   15249          250 :         inform (DECL_SOURCE_LOCATION (c->cand->fn), "explicit conversion "
   15250              :                 "function was not considered");
   15251         1768 : }
   15252              : 
   15253              : /* We're converting EXPR to TYPE.  If that conversion involves a conversion
   15254              :    function and we're binding EXPR to a reference parameter of that function,
   15255              :    return true.  */
   15256              : 
   15257              : bool
   15258          171 : conv_binds_to_reference_parm_p (tree type, tree expr)
   15259              : {
   15260          171 :   conversion_obstack_sentinel cos;
   15261          171 :   conversion *c = implicit_conversion (type, TREE_TYPE (expr), expr,
   15262              :                                        /*c_cast_p=*/false, LOOKUP_NORMAL,
   15263              :                                        tf_none);
   15264          171 :   if (c && !c->bad_p && c->user_conv_p)
   15265          117 :     for (; c; c = next_conversion (c))
   15266           81 :       if (c->kind == ck_user)
   15267          244 :         for (z_candidate *cand = c->cand; cand; cand = cand->next)
   15268          208 :           if (cand->viable == 1)
   15269           81 :             for (size_t i = 0; i < cand->num_convs; ++i)
   15270           45 :               if (cand->convs[i]->kind == ck_ref_bind
   15271           45 :                   && conv_get_original_expr (cand->convs[i]) == expr)
   15272              :                 return true;
   15273              : 
   15274              :   return false;
   15275          171 : }
   15276              : 
   15277              : #include "gt-cp-call.h"
        

Generated by: LCOV version 2.4-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.