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-04-20 14:57:17 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      3062313 : check_dtor_name (tree basetype, tree name)
     236              : {
     237              :   /* Just accept something we've already complained about.  */
     238      3062313 :   if (name == error_mark_node)
     239              :     return true;
     240              : 
     241      3062313 :   if (TREE_CODE (name) == TYPE_DECL)
     242           84 :     name = TREE_TYPE (name);
     243      3062229 :   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      3062287 :   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    328661141 : build_addr_func (tree function, tsubst_flags_t complain)
     282              : {
     283    328661141 :   tree type = TREE_TYPE (function);
     284              : 
     285              :   /* We have to do these by hand to avoid real pointer to member
     286              :      functions.  */
     287    328661141 :   if (TREE_CODE (type) == METHOD_TYPE)
     288              :     {
     289     52265320 :       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     52265249 :       function = build_address (function);
     297              :     }
     298    276395821 :   else if (TREE_CODE (function) == FUNCTION_DECL
     299    393542414 :            && DECL_IMMEDIATE_FUNCTION_P (function))
     300      1607903 :     function = build_address (function);
     301              :   else
     302    274787918 :     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       162843 : build_call_n (tree function, int n, ...)
     315              : {
     316       162843 :   if (n == 0)
     317            0 :     return build_call_a (function, 0, NULL);
     318              :   else
     319              :     {
     320       162843 :       tree *argarray = XALLOCAVEC (tree, n);
     321       162843 :       va_list ap;
     322       162843 :       int i;
     323              : 
     324       162843 :       va_start (ap, n);
     325       326420 :       for (i = 0; i < n; i++)
     326       163577 :         argarray[i] = va_arg (ap, tree);
     327       162843 :       va_end (ap);
     328       162843 :       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    157941041 : set_flags_from_callee (tree call)
     337              : {
     338              :   /* Handle both CALL_EXPRs and AGGR_INIT_EXPRs.  */
     339    157941041 :   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    157941041 :   bool nothrow = decl && TREE_NOTHROW (decl);
     344    157941041 :   tree callee = cp_get_callee (call);
     345    157941041 :   if (callee)
     346    157941033 :     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    157941041 :   if (cfun && cp_function_chain && !cp_unevaluated_operand)
     352              :     {
     353     94379484 :       if (!nothrow && at_function_scope_p ())
     354     23137865 :         cp_function_chain->can_throw = 1;
     355              : 
     356     94379484 :       if (decl && TREE_THIS_VOLATILE (decl))
     357      2863193 :         current_function_returns_abnormally = 1;
     358              :     }
     359              : 
     360    157941041 :   TREE_NOTHROW (call) = nothrow;
     361    157941041 : }
     362              : 
     363              : tree
     364    154384495 : build_call_a (tree function, int n, tree *argarray)
     365              : {
     366    154384495 :   tree decl;
     367    154384495 :   tree result_type;
     368    154384495 :   tree fntype;
     369    154384495 :   int i;
     370              : 
     371    154384495 :   function = build_addr_func (function, tf_warning_or_error);
     372              : 
     373    154384495 :   gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
     374    154384495 :   fntype = TREE_TYPE (TREE_TYPE (function));
     375    154384495 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     376    154384495 :   result_type = TREE_TYPE (fntype);
     377              :   /* An rvalue has no cv-qualifiers.  */
     378    154384495 :   if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
     379     90995115 :     result_type = cv_unqualified (result_type);
     380              : 
     381    154384495 :   function = build_call_array_loc (input_location,
     382              :                                    result_type, function, n, argarray);
     383    154384495 :   set_flags_from_callee (function);
     384              : 
     385    154384495 :   decl = get_callee_fndecl (function);
     386              : 
     387    154384495 :   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       190972 :       gcc_assert (DECL_ARTIFICIAL (decl)
     394              :                   || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
     395              :                                "__", 2));
     396       190972 :       mark_used (decl);
     397              :     }
     398              : 
     399    154384495 :   require_complete_eh_spec_types (fntype, decl);
     400              : 
     401    444101324 :   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    154384495 :   if (!decl || !fndecl_built_in_p (decl))
     407    313699932 :     for (i = 0; i < n; i++)
     408              :       {
     409    166646478 :         tree arg = CALL_EXPR_ARG (function, i);
     410    166646478 :         if (is_empty_class (TREE_TYPE (arg))
     411    166646478 :             && simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
     412              :           {
     413      5332230 :             while (TREE_CODE (arg) == TARGET_EXPR)
     414              :               /* We're disconnecting the initializer from its target,
     415              :                  don't create a temporary.  */
     416      2665162 :               arg = TARGET_EXPR_INITIAL (arg);
     417      2667068 :             suppress_warning (arg, OPT_Wunused_result);
     418      2667068 :             tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
     419      2667068 :             arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
     420      2667068 :             CALL_EXPR_ARG (function, i) = arg;
     421              :           }
     422              :       }
     423              : 
     424    154384495 :   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     66180579 :   bool rewritten () const { return (flags & LOOKUP_REWRITTEN); }
     543   1042943568 :   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    124474778 : null_ptr_cst_p (tree t)
     551              : {
     552    124474778 :   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    124474778 :   if (NULLPTR_TYPE_P (type))
     559              :     return true;
     560              : 
     561    115683631 :   if (cxx_dialect >= cxx11)
     562              :     {
     563    115292071 :       STRIP_ANY_LOCATION_WRAPPER (t);
     564              : 
     565              :       /* Core issue 903 says only literal 0 is a null pointer constant.  */
     566    115292071 :       if (TREE_CODE (t) == INTEGER_CST
     567     13333769 :           && !TREE_OVERFLOW (t)
     568     13333769 :           && TREE_CODE (type) == INTEGER_TYPE
     569     12793514 :           && integer_zerop (t)
     570    123950303 :           && !char_type_p (type))
     571              :         return true;
     572              :     }
     573       391560 :   else if (CP_INTEGRAL_TYPE_P (type))
     574              :     {
     575        75453 :       t = fold_non_dependent_expr (t, tf_none);
     576        75453 :       STRIP_NOPS (t);
     577        75453 :       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     95564478 : null_member_pointer_value_p (tree t)
     588              : {
     589     95564478 :   tree type = TREE_TYPE (t);
     590     95564478 :   if (!type)
     591              :     return false;
     592     95384185 :   else if (TYPE_PTRMEMFUNC_P (type))
     593         1264 :     return (TREE_CODE (t) == CONSTRUCTOR
     594          688 :             && CONSTRUCTOR_NELTS (t)
     595         1949 :             && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
     596     95382921 :   else if (TYPE_PTRDATAMEM_P (type))
     597         5980 :     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    698506670 : sufficient_parms_p (const_tree parmlist)
     607              : {
     608    707638749 :   for (; parmlist && parmlist != void_list_node;
     609      9132079 :        parmlist = TREE_CHAIN (parmlist))
     610    211971092 :     if (!TREE_PURPOSE (parmlist)
     611    211971092 :         && !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   7764083046 : conversion_obstack_alloc (size_t n)
     621              : {
     622   7764083046 :   void *p;
     623   7764083046 :   if (!conversion_obstack_initialized)
     624              :     {
     625        84315 :       gcc_obstack_init (&conversion_obstack);
     626        84315 :       conversion_obstack_initialized = true;
     627              :     }
     628   7764083046 :   p = obstack_alloc (&conversion_obstack, n);
     629   7764083046 :   memset (p, 0, n);
     630   7764083046 :   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   2424646620 :   conversion_obstack_sentinel (): p (conversion_obstack_alloc (0)) {}
     639   1212309756 :   ~conversion_obstack_sentinel () { obstack_free (&conversion_obstack, p); }
     640              : };
     641              : 
     642              : /* Allocate rejection reasons.  */
     643              : 
     644              : static struct rejection_reason *
     645    770883266 : alloc_rejection (enum rejection_reason_code code)
     646              : {
     647    770883266 :   struct rejection_reason *p;
     648            0 :   p = (struct rejection_reason *) conversion_obstack_alloc (sizeof *p);
     649    770883266 :   p->code = code;
     650    770883266 :   return p;
     651              : }
     652              : 
     653              : static struct rejection_reason *
     654    187687656 : arity_rejection (tree first_arg, int expected, int actual, bool least_p = false)
     655              : {
     656    149092518 :   struct rejection_reason *r = alloc_rejection (rr_arity);
     657    187687656 :   int adjust = first_arg != NULL_TREE;
     658    187687656 :   r->u.arity.expected = expected - adjust;
     659    187687656 :   r->u.arity.actual = actual - adjust;
     660    187687656 :   r->u.arity.least_p = least_p;
     661    187687656 :   return r;
     662              : }
     663              : 
     664              : static struct rejection_reason *
     665    162613956 : arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     666              :                           location_t loc)
     667              : {
     668      7066970 :   struct rejection_reason *r = alloc_rejection (rr_arg_conversion);
     669    162613956 :   int adjust = first_arg != NULL_TREE;
     670    162613956 :   r->u.conversion.n_arg = n_arg - adjust;
     671    162613956 :   r->u.conversion.from = from;
     672    162613956 :   r->u.conversion.to_type = to;
     673    162613956 :   r->u.conversion.loc = loc;
     674    162613956 :   return r;
     675              : }
     676              : 
     677              : static struct rejection_reason *
     678     21160314 : 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     21160314 :   int adjust = first_arg != NULL_TREE;
     683     21160314 :   r->u.bad_conversion.n_arg = n_arg - adjust;
     684     21160314 :   r->u.bad_conversion.from = from;
     685     21160314 :   r->u.bad_conversion.to_type = to;
     686     21160314 :   r->u.bad_conversion.loc = loc;
     687     21160314 :   return r;
     688              : }
     689              : 
     690              : static struct rejection_reason *
     691         2633 : explicit_conversion_rejection (tree from, tree to)
     692              : {
     693         2633 :   struct rejection_reason *r = alloc_rejection (rr_explicit_conversion);
     694         2633 :   r->u.conversion.n_arg = 0;
     695         2633 :   r->u.conversion.from = from;
     696         2633 :   r->u.conversion.to_type = to;
     697         2633 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     698         2633 :   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    398005028 : 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    398005028 :   size_t args_n_bytes = sizeof (*args) * nargs;
     719    398005028 :   tree *args1 = (tree *) conversion_obstack_alloc (args_n_bytes);
     720    398005028 :   struct rejection_reason *r = alloc_rejection (rr_template_unification);
     721    398005028 :   r->u.template_unification.tmpl = tmpl;
     722    398005028 :   r->u.template_unification.explicit_targs = explicit_targs;
     723    398005028 :   r->u.template_unification.num_targs = TREE_VEC_LENGTH (targs);
     724              :   /* Copy args to our own storage.  */
     725    398005028 :   memcpy (args1, args, args_n_bytes);
     726    398005028 :   r->u.template_unification.args = args1;
     727    398005028 :   r->u.template_unification.nargs = nargs;
     728    398005028 :   r->u.template_unification.return_type = return_type;
     729    398005028 :   r->u.template_unification.strict = strict;
     730    398005028 :   r->u.template_unification.flags = flags;
     731    398005028 :   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       663721 : invalid_copy_with_fn_template_rejection (void)
     742              : {
     743            0 :   struct rejection_reason *r = alloc_rejection (rr_invalid_copy);
     744       663721 :   return r;
     745              : }
     746              : 
     747              : static struct rejection_reason *
     748       598652 : inherited_ctor_rejection (void)
     749              : {
     750            0 :   struct rejection_reason *r = alloc_rejection (rr_inherited_ctor);
     751       598652 :   return r;
     752              : }
     753              : 
     754              : /* Build a constraint failure record.  */
     755              : 
     756              : static struct rejection_reason *
     757       151175 : constraint_failure (void)
     758              : {
     759            0 :   struct rejection_reason *r = alloc_rejection (rr_constraint_failure);
     760       151175 :   return r;
     761              : }
     762              : 
     763              : /* Dynamically allocate a conversion.  */
     764              : 
     765              : static conversion *
     766   2631485525 : alloc_conversion (conversion_kind kind)
     767              : {
     768   2631485525 :   conversion *c;
     769            0 :   c = (conversion *) conversion_obstack_alloc (sizeof (conversion));
     770   2631485525 :   c->kind = kind;
     771   2631485525 :   return c;
     772              : }
     773              : 
     774              : /* Make sure that all memory on the conversion obstack has been
     775              :    freed.  */
     776              : 
     777              : void
     778        96451 : validate_conversion_obstack (void)
     779              : {
     780        96451 :   if (conversion_obstack_initialized)
     781        83984 :     gcc_assert ((obstack_next_free (&conversion_obstack)
     782              :                  == obstack_base (&conversion_obstack)));
     783        96451 : }
     784              : 
     785              : /* Dynamically allocate an array of N conversions.  */
     786              : 
     787              : static conversion **
     788   1013538138 : 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   1438184033 : has_next (conversion_kind code)
     797              : {
     798   1351671859 :   return !(code == ck_identity
     799   1438184033 :            || code == ck_ambig
     800              :            || code == ck_list
     801   1351733752 :            || code == ck_aggr
     802   1438184033 :            || code == ck_deferred_bad);
     803              : }
     804              : 
     805              : static conversion *
     806    777238053 : build_conv (conversion_kind code, tree type, conversion *from)
     807              : {
     808    777238053 :   conversion *t;
     809    777238053 :   conversion_rank rank = CONVERSION_RANK (from);
     810              : 
     811              :   /* Only call this function for conversions that use u.next.  */
     812    777238053 :   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    777238053 :   t = alloc_conversion (code);
     817    777238053 :   t->type = type;
     818    777238053 :   t->u.next = from;
     819              : 
     820    777238053 :   switch (code)
     821              :     {
     822    225888316 :     case ck_ptr:
     823    225888316 :     case ck_pmem:
     824    225888316 :     case ck_base:
     825    225888316 :     case ck_std:
     826    225888316 :       if (rank < cr_std)
     827    777238053 :         rank = cr_std;
     828              :       break;
     829              : 
     830     53338385 :     case ck_qual:
     831     53338385 :     case ck_fnptr:
     832     53338385 :       if (rank < cr_exact)
     833    777238053 :         rank = cr_exact;
     834              :       break;
     835              : 
     836              :     default:
     837              :       break;
     838              :     }
     839    777238053 :   t->rank = rank;
     840    777238053 :   t->user_conv_p = (code == ck_user || from->user_conv_p);
     841    777238053 :   t->bad_p = from->bad_p;
     842    777238053 :   t->base_p = false;
     843    777238053 :   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        82223 : build_list_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     852              : {
     853        82223 :   tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (type), 0);
     854        82223 :   unsigned len = CONSTRUCTOR_NELTS (ctor);
     855        82223 :   conversion **subconvs = alloc_conversions (len);
     856        82223 :   conversion *t;
     857        82223 :   unsigned i;
     858        82223 :   tree val;
     859              : 
     860              :   /* Within a list-initialization we can have more user-defined
     861              :      conversions.  */
     862        82223 :   flags &= ~LOOKUP_NO_CONVERSION;
     863              :   /* But no narrowing conversions.  */
     864        82223 :   flags |= LOOKUP_NO_NARROWING;
     865              : 
     866              :   /* Can't make an array of these types.  */
     867        82223 :   if (TYPE_REF_P (elttype)
     868        82214 :       || TREE_CODE (elttype) == FUNCTION_TYPE
     869        82214 :       || VOID_TYPE_P (elttype))
     870              :     return NULL;
     871              : 
     872       284169 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
     873              :     {
     874       213370 :       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       213319 :       conversion *sub
     936       213319 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
     937              :                                false, flags, complain);
     938       213319 :       if (sub == NULL)
     939              :         return NULL;
     940              : 
     941       201904 :       subconvs[i] = sub;
     942              :     }
     943              : 
     944        70799 :   t = alloc_conversion (ck_list);
     945        70799 :   t->type = type;
     946        70799 :   t->u.list = subconvs;
     947        70799 :   t->rank = cr_exact;
     948              : 
     949       254596 :   for (i = 0; i < len; ++i)
     950              :     {
     951       183797 :       conversion *sub = subconvs[i];
     952       183797 :       if (sub->rank > t->rank)
     953        58866 :         t->rank = sub->rank;
     954       183797 :       if (sub->user_conv_p)
     955         9728 :         t->user_conv_p = true;
     956       183797 :       if (sub->bad_p)
     957        58881 :         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    574731366 : next_conversion (conversion *conv)
     969              : {
     970    574731366 :   if (conv == NULL
     971    574731366 :       || !has_next (conv->kind))
     972              :     return NULL;
     973    563075681 :   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      1368031 : strip_standard_conversion (conversion *conv)
     981              : {
     982      1368031 :   while (conv
     983      1375441 :          && conv->kind != ck_user
     984      1409501 :          && has_next (conv->kind))
     985         7410 :     conv = next_conversion (conv);
     986      1368031 :   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        25118 : can_convert_array (tree atype, tree from, int flags, tsubst_flags_t complain)
     994              : {
     995        25118 :   tree elttype = TREE_TYPE (atype);
     996        25118 :   unsigned i;
     997              : 
     998        25118 :   if (TREE_CODE (from) == CONSTRUCTOR)
     999              :     {
    1000        28117 :       for (i = 0; i < CONSTRUCTOR_NELTS (from); ++i)
    1001              :         {
    1002         3044 :           tree val = CONSTRUCTOR_ELT (from, i)->value;
    1003         3044 :           bool ok;
    1004         3044 :           if (TREE_CODE (elttype) == ARRAY_TYPE)
    1005           18 :             ok = can_convert_array (elttype, val, flags, complain);
    1006              :           else
    1007         3026 :             ok = can_convert_arg (elttype, TREE_TYPE (val), val, flags,
    1008              :                                   complain);
    1009         3044 :           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       774281 : field_in_pset (hash_set<tree, true> &pset, tree field)
    1029              : {
    1030       774281 :   if (pset.contains (field))
    1031              :     return true;
    1032         1342 :   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      1238454 : build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1050              : {
    1051      1238454 :   unsigned HOST_WIDE_INT i = 0;
    1052      1238454 :   conversion *c;
    1053      1238454 :   tree field = next_aggregate_field (TYPE_FIELDS (type));
    1054      1238454 :   tree empty_ctor = NULL_TREE;
    1055      1238454 :   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      1238454 :   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      1238454 :   tree idx, val;
    1069      2011393 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
    1070              :     {
    1071       773014 :       if (!idx)
    1072              :         break;
    1073              : 
    1074       772971 :       gcc_checking_assert (TREE_CODE (idx) == FIELD_DECL);
    1075              : 
    1076       772971 :       tree ftype = TREE_TYPE (idx);
    1077       772971 :       bool ok;
    1078              : 
    1079       772971 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1080         1078 :         ok = can_convert_array (ftype, val, flags, complain);
    1081              :       else
    1082       771893 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1083              :                               complain);
    1084              : 
    1085       772971 :       if (!ok)
    1086              :         return NULL;
    1087              : 
    1088              :       /* For unions, there should be just one initializer.  */
    1089       772962 :       if (TREE_CODE (type) == UNION_TYPE)
    1090              :         {
    1091              :           field = NULL_TREE;
    1092              :           i = 1;
    1093              :           break;
    1094              :         }
    1095       772939 :       pset.add (idx);
    1096              :     }
    1097              : 
    1098      2077350 :   for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
    1099              :     {
    1100       839162 :       tree ftype = TREE_TYPE (field);
    1101       839162 :       bool ok;
    1102              : 
    1103       839162 :       if (!pset.is_empty () && field_in_pset (pset, field))
    1104       772939 :         continue;
    1105        66223 :       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        66194 :       else if (DECL_INITIAL (field))
    1113        14483 :         val = get_nsdmi (field, /*ctor*/false, complain);
    1114        51711 :       else if (TYPE_REF_P (ftype))
    1115              :         /* Value-initialization of reference is ill-formed.  */
    1116              :         return NULL;
    1117              :       else
    1118              :         {
    1119        51705 :           if (empty_ctor == NULL_TREE)
    1120        38251 :             empty_ctor = build_constructor (init_list_type_node, NULL);
    1121              :           val = empty_ctor;
    1122              :         }
    1123              : 
    1124        66217 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1125        24022 :         ok = can_convert_array (ftype, val, flags, complain);
    1126              :       else
    1127        42195 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1128              :                               complain);
    1129              : 
    1130        66217 :       if (!ok)
    1131              :         return NULL;
    1132              : 
    1133        66206 :       if (TREE_CODE (type) == UNION_TYPE)
    1134              :         break;
    1135              :     }
    1136              : 
    1137      1238428 :   if (i < CONSTRUCTOR_NELTS (ctor))
    1138              :     return NULL;
    1139              : 
    1140      1238409 :   c = alloc_conversion (ck_aggr);
    1141      1238409 :   c->type = type;
    1142      1238409 :   c->rank = cr_exact;
    1143      1238409 :   c->user_conv_p = true;
    1144      1238409 :   c->check_narrowing = true;
    1145      1238409 :   c->u.expr = ctor;
    1146      1238409 :   return c;
    1147      1238454 : }
    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         1663 : build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1154              : {
    1155         1663 :   conversion *c;
    1156         1663 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1157         1663 :   tree elttype = TREE_TYPE (type);
    1158         1663 :   bool bad = false;
    1159         1663 :   bool user = false;
    1160         1663 :   enum conversion_rank rank = cr_exact;
    1161              : 
    1162              :   /* We might need to propagate the size from the element to the array.  */
    1163         1663 :   complete_type (type);
    1164              : 
    1165         1663 :   if (TYPE_DOMAIN (type)
    1166         1663 :       && !variably_modified_type_p (TYPE_DOMAIN (type), NULL_TREE))
    1167              :     {
    1168         1589 :       unsigned HOST_WIDE_INT alen = tree_to_uhwi (array_type_nelts_top (type));
    1169         1589 :       if (alen < len)
    1170              :         return NULL;
    1171              :     }
    1172              : 
    1173         1626 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1174              : 
    1175         6971 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1176              :     {
    1177         2768 :       conversion *sub
    1178         2768 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1179              :                                false, flags, complain);
    1180         2768 :       if (sub == NULL)
    1181              :         return NULL;
    1182              : 
    1183         2179 :       if (sub->rank > rank)
    1184          264 :         rank = sub->rank;
    1185         2179 :       if (sub->user_conv_p)
    1186           23 :         user = true;
    1187         2179 :       if (sub->bad_p)
    1188          195 :         bad = true;
    1189              :     }
    1190              : 
    1191         1037 :   c = alloc_conversion (ck_aggr);
    1192         1037 :   c->type = type;
    1193         1037 :   c->rank = rank;
    1194         1037 :   c->user_conv_p = user;
    1195         1037 :   c->bad_p = bad;
    1196         1037 :   c->u.expr = ctor;
    1197         1037 :   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        54964 : build_complex_conv (tree type, tree ctor, int flags,
    1205              :                     tsubst_flags_t complain)
    1206              : {
    1207        54964 :   conversion *c;
    1208        54964 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1209        54964 :   tree elttype = TREE_TYPE (type);
    1210        54964 :   bool bad = false;
    1211        54964 :   bool user = false;
    1212        54964 :   enum conversion_rank rank = cr_exact;
    1213              : 
    1214        54964 :   if (len != 2)
    1215              :     return NULL;
    1216              : 
    1217        54924 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1218              : 
    1219       274620 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1220              :     {
    1221       109848 :       conversion *sub
    1222       109848 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1223              :                                false, flags, complain);
    1224       109848 :       if (sub == NULL)
    1225              :         return NULL;
    1226              : 
    1227       109848 :       if (sub->rank > rank)
    1228           44 :         rank = sub->rank;
    1229       109848 :       if (sub->user_conv_p)
    1230            0 :         user = true;
    1231       109848 :       if (sub->bad_p)
    1232            0 :         bad = true;
    1233              :     }
    1234              : 
    1235        54924 :   c = alloc_conversion (ck_aggr);
    1236        54924 :   c->type = type;
    1237        54924 :   c->rank = rank;
    1238        54924 :   c->user_conv_p = user;
    1239        54924 :   c->bad_p = bad;
    1240        54924 :   c->u.expr = ctor;
    1241        54924 :   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   1845519674 : build_identity_conv (tree type, tree expr)
    1249              : {
    1250   1845519674 :   conversion *c;
    1251              : 
    1252            0 :   c = alloc_conversion (ck_identity);
    1253   1845519674 :   c->type = type;
    1254   1845519674 :   c->u.expr = expr;
    1255              : 
    1256   1845519674 :   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   3293481188 : strip_top_quals (tree t)
    1277              : {
    1278   3293481188 :   if (TREE_CODE (t) == ARRAY_TYPE)
    1279              :     return t;
    1280   3287476974 :   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   1471523038 : standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
    1290              :                      int flags, tsubst_flags_t complain)
    1291              : {
    1292   1471523038 :   enum tree_code fcode, tcode;
    1293   1471523038 :   conversion *conv;
    1294   1471523038 :   bool fromref = false;
    1295   1471523038 :   tree qualified_to;
    1296              : 
    1297   1471523038 :   to = non_reference (to);
    1298   1471523038 :   if (TYPE_REF_P (from))
    1299              :     {
    1300        76886 :       fromref = true;
    1301        76886 :       from = TREE_TYPE (from);
    1302              :     }
    1303   1471523038 :   qualified_to = to;
    1304   1471523038 :   to = strip_top_quals (to);
    1305   1471523038 :   from = strip_top_quals (from);
    1306              : 
    1307   1471523038 :   if (expr && type_unknown_p (expr))
    1308              :     {
    1309       338188 :       if (TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
    1310              :         {
    1311        36085 :           tsubst_flags_t tflags = tf_conv;
    1312        36085 :           expr = instantiate_type (to, expr, tflags);
    1313        36085 :           if (expr == error_mark_node)
    1314              :             return NULL;
    1315        21689 :           from = TREE_TYPE (expr);
    1316              :         }
    1317       302103 :       else if (TREE_CODE (to) == BOOLEAN_TYPE)
    1318              :         {
    1319              :           /* Necessary for eg, TEMPLATE_ID_EXPRs (c++/50961).  */
    1320         6997 :           expr = resolve_nondeduced_context (expr, complain);
    1321         6997 :           from = TREE_TYPE (expr);
    1322              :         }
    1323              :     }
    1324              : 
    1325   1471508642 :   fcode = TREE_CODE (from);
    1326   1471508642 :   tcode = TREE_CODE (to);
    1327              : 
    1328   1471508642 :   conv = build_identity_conv (from, expr);
    1329   1471508642 :   if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
    1330              :     {
    1331      6024394 :       from = type_decays_to (from);
    1332      6024394 :       fcode = TREE_CODE (from);
    1333              :       /* Tell convert_like that we're using the address.  */
    1334      6024394 :       conv->rvaluedness_matches_p = true;
    1335      6024394 :       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   1465484248 :   else if (fromref || (expr && obvalue_p (expr)))
    1341              :     {
    1342    348441552 :       if (expr)
    1343              :         {
    1344    348364691 :           tree bitfield_type;
    1345    348364691 :           bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1346    348364691 :           if (bitfield_type)
    1347              :             {
    1348      2232646 :               from = strip_top_quals (bitfield_type);
    1349      2232646 :               fcode = TREE_CODE (from);
    1350              :             }
    1351              :         }
    1352    348441552 :       conv = build_conv (ck_rvalue, from, conv);
    1353              :       /* If we're performing copy-initialization, remember to skip
    1354              :          explicit constructors.  */
    1355    348441552 :       if (flags & LOOKUP_ONLYCONVERTING)
    1356    299266128 :         conv->copy_init_p = true;
    1357              :     }
    1358              : 
    1359              :    /* Allow conversion between `__complex__' data types.  */
    1360   1471508642 :   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      2225728 :       conversion *part_conv = standard_conversion
    1366      2225728 :         (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, c_cast_p, flags,
    1367              :          complain);
    1368              : 
    1369      2225728 :       if (!part_conv)
    1370              :         conv = NULL;
    1371      2225728 :       else if (part_conv->kind == ck_identity)
    1372              :         /* Leave conv alone.  */;
    1373              :       else
    1374              :         {
    1375       226408 :           conv = build_conv (part_conv->kind, to, conv);
    1376       226408 :           conv->rank = part_conv->rank;
    1377              :         }
    1378              : 
    1379      2225728 :       return conv;
    1380              :     }
    1381              : 
    1382   1469282914 :   if (same_type_p (from, to))
    1383              :     {
    1384    883906648 :       if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
    1385     16721400 :         conv->type = qualified_to;
    1386    867185248 :       else if (from != to)
    1387              :         /* Use TO in order to not lose TO in diagnostics.  */
    1388     77960509 :         conv->type = to;
    1389    883906648 :       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    374602145 :   if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
    1397    374514981 :        || NULLPTR_TYPE_P (to))
    1398    590999911 :       && ((expr && null_ptr_cst_p (expr))
    1399    210762464 :           || NULLPTR_TYPE_P (from)))
    1400      5635306 :     conv = build_conv (ck_std, to, conv);
    1401    579740960 :   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
    1402    579180790 :            || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
    1403              :     {
    1404              :       /* For backwards brain damage compatibility, allow interconversion of
    1405              :          pointers and integers with a pedwarn.  */
    1406      2067211 :       conv = build_conv (ck_std, to, conv);
    1407      2067211 :       conv->bad_p = true;
    1408              :     }
    1409    577673749 :   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       350531 :       conv = build_conv (ck_std, to, conv);
    1414       350531 :       conv->bad_p = true;
    1415              :     }
    1416    577323218 :   else if ((tcode == POINTER_TYPE && fcode == POINTER_TYPE)
    1417    378328506 :            || (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    198994712 :           to_pointee = TREE_TYPE (to);
    1425    198994712 :           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    198994712 :           if (TREE_CODE (to_pointee) == FUNCTION_TYPE
    1431    198994712 :               && TYPE_QUALS (to_pointee))
    1432            9 :             to_pointee = build_qualified_type (to_pointee, TYPE_UNQUALIFIED);
    1433    198994712 :           if (TREE_CODE (from_pointee) == FUNCTION_TYPE
    1434    198994712 :               && 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    198996412 :       if (tcode == POINTER_TYPE
    1444    198996412 :           && same_type_ignoring_top_level_qualifiers_p (from_pointee,
    1445              :                                                         to_pointee))
    1446              :         ;
    1447    141402324 :       else if (VOID_TYPE_P (to_pointee)
    1448      4395023 :                && !TYPE_PTRDATAMEM_P (from)
    1449      4395023 :                && TREE_CODE (from_pointee) != FUNCTION_TYPE)
    1450              :         {
    1451      4394698 :           tree nfrom = TREE_TYPE (from);
    1452              :           /* Don't try to apply restrict to void.  */
    1453      4394698 :           int quals = cp_type_quals (nfrom) & ~TYPE_QUAL_RESTRICT;
    1454      4394698 :           from_pointee = cp_build_qualified_type (void_type_node, quals);
    1455      4394698 :           from = build_pointer_type (from_pointee);
    1456      4394698 :           conv = build_conv (ck_ptr, from, conv);
    1457      4394698 :         }
    1458    137007626 :       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     69736990 :       else if (CLASS_TYPE_P (from_pointee)
    1476     69734555 :                && 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    205857582 :                && DERIVED_FROM_P (to_pointee, from_pointee))
    1489              :         {
    1490      5904676 :           from_pointee
    1491      5904676 :             = cp_build_qualified_type (to_pointee,
    1492              :                                        cp_type_quals (from_pointee));
    1493      5904676 :           from = build_pointer_type (from_pointee);
    1494      5904676 :           conv = build_conv (ck_ptr, from, conv);
    1495      5904676 :           conv->base_p = true;
    1496              :         }
    1497              : 
    1498    198996200 :       if (same_type_p (from, to))
    1499              :         /* OK */;
    1500    191265339 :       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    191264716 :       else if (!c_cast_p && comp_ptr_ttypes (to_pointee, from_pointee))
    1506     53039451 :         conv = build_conv (ck_qual, to, conv);
    1507    138225265 :       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    138225061 :       else if (fnptr_conv_p (to, from))
    1511       227815 :         conv = build_conv (ck_fnptr, to, conv);
    1512              :       /* Allow conversions among compatible ObjC pointer types (base
    1513              :          conversions have been already handled above).  */
    1514    137997246 :       else if (c_dialect_objc ()
    1515    137997246 :                && objc_compare_types (to, from, -4, NULL_TREE))
    1516            0 :         conv = build_conv (ck_ptr, to, conv);
    1517    137997246 :       else if (ptr_reasonably_similar (to_pointee, from_pointee))
    1518              :         {
    1519      8319271 :           conv = build_conv (ck_ptr, to, conv);
    1520      8319271 :           conv->bad_p = true;
    1521              :         }
    1522              :       else
    1523              :         return NULL;
    1524              : 
    1525    264021477 :       from = to;
    1526              :     }
    1527    378326806 :   else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
    1528              :     {
    1529        83306 :       tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
    1530        83306 :       tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
    1531        83306 :       tree fbase = class_of_this_parm (fromfn);
    1532        83306 :       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        83306 :       if (!same_type_p (fbase, tbase) && !DERIVED_FROM_P (fbase, tbase))
    1537              :         return NULL;
    1538              : 
    1539        83145 :       tree fstat = static_fn_type (fromfn);
    1540        83145 :       tree tstat = static_fn_type (tofn);
    1541        83145 :       if (same_type_p (tstat, fstat)
    1542        83145 :           || fnptr_conv_p (tstat, fstat))
    1543              :         /* OK */;
    1544              :       else
    1545              :         return NULL;
    1546              : 
    1547        82877 :       if (!same_type_p (fbase, tbase))
    1548              :         {
    1549        82808 :           from = build_memfn_type (fstat,
    1550              :                                    tbase,
    1551              :                                    cp_type_quals (tbase),
    1552              :                                    type_memfn_rqual (tofn));
    1553        82808 :           from = build_ptrmemfunc_type (build_pointer_type (from));
    1554        82808 :           conv = build_conv (ck_pmem, from, conv);
    1555        82808 :           conv->base_p = true;
    1556              :         }
    1557        82877 :       if (fnptr_conv_p (tstat, fstat))
    1558           69 :         conv = build_conv (ck_fnptr, to, conv);
    1559              :     }
    1560    378243500 :   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      6136655 :       if (ARITHMETIC_TYPE_P (from)
    1569      6080687 :           || UNSCOPED_ENUM_P (from)
    1570      3994502 :           || fcode == POINTER_TYPE
    1571      2817459 :           || TYPE_PTRMEM_P (from)
    1572     14329559 :           || NULLPTR_TYPE_P (from))
    1573              :         {
    1574      8695163 :           conv = build_conv (ck_std, to, conv);
    1575      8695163 :           if (fcode == POINTER_TYPE
    1576      7518120 :               || TYPE_PTRDATAMEM_P (from)
    1577      7517976 :               || (TYPE_PTRMEMFUNC_P (from)
    1578           77 :                   && conv->rank < cr_pbool)
    1579     16213062 :               || NULLPTR_TYPE_P (from))
    1580      1177344 :             conv->rank = cr_pbool;
    1581      8695163 :           if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
    1582           38 :             conv->bad_p = true;
    1583      8695163 :           if (flags & LOOKUP_NO_NARROWING)
    1584        30873 :             conv->check_narrowing = true;
    1585      8695163 :           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    366731179 :   else if (ARITHMETIC_TYPE_P (to))
    1594              :     {
    1595     29210201 :       if (! (INTEGRAL_CODE_P (fcode)
    1596     22873454 :              || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
    1597    216612742 :           || 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    186093781 :       if (!COMPLETE_TYPE_P (from))
    1604              :         return NULL;
    1605              : 
    1606    186093775 :       conv = build_conv (ck_std, to, conv);
    1607              : 
    1608    186093775 :       tree underlying_type = NULL_TREE;
    1609    186093775 :       if (TREE_CODE (from) == ENUMERAL_TYPE
    1610    186093775 :           && ENUM_FIXED_UNDERLYING_TYPE_P (from))
    1611      1629239 :         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    186093775 :       if ((same_type_p (to, type_promotes_to (from))
    1619    174712859 :            || (underlying_type && same_type_p (to, underlying_type)))
    1620    186093794 :           && next_conversion (conv)->rank <= cr_promotion)
    1621     11380935 :         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    186093775 :       if (fcode == REAL_TYPE
    1633    186093775 :           && tcode == REAL_TYPE
    1634     15420722 :           && (extended_float_type_p (from)
    1635     14868130 :               || extended_float_type_p (to))
    1636    188854140 :           && cp_compare_floating_point_conversion_ranks (from, to) >= 2)
    1637      1271894 :         conv->bad_p = true;
    1638              :     }
    1639    172991891 :   else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
    1640    172991891 :            && vector_types_convertible_p (from, to, false))
    1641         4884 :     return build_conv (ck_std, to, conv);
    1642    172987007 :   else if (MAYBE_CLASS_TYPE_P (to) && MAYBE_CLASS_TYPE_P (from)
    1643     73851884 :            && is_properly_derived_from (from, to))
    1644              :     {
    1645       473552 :       if (conv->kind == ck_rvalue)
    1646       473501 :         conv = next_conversion (conv);
    1647       473552 :       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       473552 :       conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
    1653              :       /* If we're performing copy-initialization, remember to skip
    1654              :          explicit constructors.  */
    1655       473552 :       if (flags & LOOKUP_ONLYCONVERTING)
    1656       473485 :         conv->copy_init_p = true;
    1657              :     }
    1658              :   else
    1659    172513455 :     return NULL;
    1660              : 
    1661    264021477 :   if (flags & LOOKUP_NO_NARROWING)
    1662     91576975 :     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    269488318 : reference_related_p (tree t1, tree t2)
    1673              : {
    1674    269488318 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1675              :     return false;
    1676              : 
    1677    269488314 :   t1 = TYPE_MAIN_VARIANT (t1);
    1678    269488314 :   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    269488314 :   return (similar_type_p (t1, t2)
    1685    269488314 :           || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    1686     70584250 :               && DERIVED_FROM_P (t1, t2)));
    1687              : }
    1688              : 
    1689              : /* Returns nonzero if T1 is reference-compatible with T2.  */
    1690              : 
    1691              : bool
    1692    239719225 : 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    239719225 :   tree ptype1 = build_pointer_type (t1);
    1700    239719225 :   tree ptype2 = build_pointer_type (t2);
    1701    239719225 :   conversion *conv = standard_conversion (ptype1, ptype2, NULL_TREE,
    1702              :                                           /*c_cast_p=*/false, 0, tf_none);
    1703    239719225 :   if (!conv || conv->bad_p)
    1704    135972416 :     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    114159136 : 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    114159136 :   if (!((TYPE_PTR_P (to) && TYPE_PTR_P (from))
    1717         2400 :         || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from))))
    1718              :     return false;
    1719              : 
    1720      4525554 :   conversion *conv = standard_conversion (to, from, NULL_TREE,
    1721              :                                           /*c_cast_p=*/false, 0, tf_none);
    1722      8980901 :   for (conversion *t = conv; t; t = next_conversion (t))
    1723      4525570 :     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         1954 : handler_match_for_exception_type (tree handler, tree except_type)
    1734              : {
    1735         1954 :   tree handler_type = HANDLER_TYPE (handler);
    1736         1954 :   if (handler_type == NULL_TREE)
    1737              :     return true; /* ... */
    1738         1921 :   if (same_type_ignoring_top_level_qualifiers_p (handler_type, except_type))
    1739              :     return true;
    1740          292 :   if (CLASS_TYPE_P (except_type) && CLASS_TYPE_P (handler_type))
    1741              :     {
    1742           80 :       base_kind b_kind;
    1743           80 :       tree binfo = lookup_base (except_type, handler_type, ba_check, &b_kind,
    1744              :                                 tf_none);
    1745           80 :       if (binfo && binfo != error_mark_node)
    1746           37 :         return true;
    1747              :     }
    1748          255 :   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    117798786 : direct_reference_binding (tree type, conversion *conv)
    1785              : {
    1786    117798786 :   tree t;
    1787              : 
    1788    117798786 :   gcc_assert (TYPE_REF_P (type));
    1789    117798786 :   gcc_assert (!TYPE_REF_P (conv->type));
    1790              : 
    1791    117798786 :   t = TREE_TYPE (type);
    1792              : 
    1793    117798786 :   if (conv->kind == ck_identity)
    1794              :     /* Mark the identity conv as to not decay to rvalue.  */
    1795    117798786 :     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    117798786 :   if (is_properly_derived_from (conv->type, t))
    1814              :     {
    1815              :       /* Represent the derived-to-base conversion.  */
    1816      3639650 :       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      3639650 :       conv->need_temporary_p = false;
    1821              :     }
    1822    114159136 :   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        70223 :     conv = build_conv (ck_qual, strip_top_quals (t), conv);
    1846              : 
    1847    117798786 :   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    238931102 : reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
    1859              :                    tsubst_flags_t complain)
    1860              : {
    1861    238931102 :   conversion *conv = NULL;
    1862    238931102 :   conversion *bad_direct_conv = nullptr;
    1863    238931102 :   tree to = TREE_TYPE (rto);
    1864    238931102 :   tree from = rfrom;
    1865    238931102 :   tree tfrom;
    1866    238931102 :   bool related_p;
    1867    238931102 :   bool compatible_p;
    1868    238931102 :   cp_lvalue_kind gl_kind;
    1869    238931102 :   bool is_lvalue;
    1870              : 
    1871    238931102 :   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    238931102 :   bool copy_list_init = false;
    1880    238931102 :   bool single_list_conv = false;
    1881    238931102 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    1882              :     {
    1883        85834 :       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        85834 :       if (CONSTRUCTOR_NELTS (expr) == 1
    1895        45816 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    1896              :         {
    1897         3015 :           tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    1898         3015 :           if (error_operand_p (elt))
    1899              :             return NULL;
    1900         3010 :           tree etype = TREE_TYPE (elt);
    1901         3010 :           if (reference_related_p (to, etype))
    1902              :             {
    1903          595 :               expr = elt;
    1904          595 :               from = etype;
    1905          595 :               goto skip;
    1906              :             }
    1907         2415 :           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    238931097 :     skip:;
    1918              :     }
    1919              : 
    1920    238931097 :   if (TYPE_REF_P (from))
    1921              :     {
    1922        57284 :       from = TREE_TYPE (from);
    1923        57284 :       if (!TYPE_REF_IS_RVALUE (rfrom)
    1924        57284 :           || TREE_CODE (from) == FUNCTION_TYPE)
    1925              :         gl_kind = clk_ordinary;
    1926              :       else
    1927              :         gl_kind = clk_rvalueref;
    1928              :     }
    1929    238873813 :   else if (expr)
    1930    235620802 :     gl_kind = lvalue_kind (expr);
    1931      2998270 :   else if (CLASS_TYPE_P (from)
    1932      3253011 :            || 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    238931097 :   if ((flags & LOOKUP_NO_TEMP_BIND)
    1939      3380411 :       && (gl_kind & clk_class))
    1940              :     gl_kind = clk_none;
    1941              : 
    1942              :   /* Same mask as real_lvalue_p.  */
    1943    236320587 :   is_lvalue = gl_kind && !(gl_kind & (clk_rvalueref|clk_class));
    1944              : 
    1945    204623862 :   tfrom = from;
    1946    204623862 :   if ((gl_kind & clk_bitfield) != 0)
    1947      1595521 :     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    238931097 :   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    238931097 :   if (related_p && c_cast_p
    1956    238931097 :       && !at_least_as_qualified_p (to, tfrom))
    1957          194 :     to = cp_build_qualified_type (to, cp_type_quals (tfrom));
    1958    238931097 :   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    238931097 :   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    104862718 :       conv = build_identity_conv (tfrom, expr);
    1984    104862718 :       conv = direct_reference_binding (rto, conv);
    1985              : 
    1986    104862718 :       if (TYPE_REF_P (rfrom))
    1987              :         /* Handle rvalue reference to function properly.  */
    1988        15685 :         conv->rvaluedness_matches_p
    1989        15685 :           = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
    1990              :       else
    1991    104847033 :         conv->rvaluedness_matches_p
    1992    104847033 :           = (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
    1993              : 
    1994    104862718 :       if ((gl_kind & clk_bitfield) != 0
    1995    104862718 :           || ((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     76655923 :       if (is_lvalue && TYPE_REF_IS_RVALUE (rto)
    2012    114576820 :           && TREE_CODE (to) != FUNCTION_TYPE)
    2013      9712500 :         conv->bad_p = true;
    2014              : 
    2015              :       /* Nor the reverse.  */
    2016     28206795 :       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     17621490 :           && !(cxx_dialect <= cxx20
    2021     15008259 :                && (gl_kind & clk_implicit_rval))
    2022     16603024 :           && (!CP_TYPE_CONST_NON_VOLATILE_P (to)
    2023     16497470 :               || (flags & LOOKUP_NO_RVAL_BIND))
    2024    104968272 :           && TREE_CODE (to) != FUNCTION_TYPE)
    2025       105554 :         conv->bad_p = true;
    2026              : 
    2027    104862718 :       if (!compatible_p)
    2028      6243914 :         conv->bad_p = true;
    2029              : 
    2030    104862718 :       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      4342213 :   else if (!related_p
    2037    129726166 :            && !(flags & LOOKUP_NO_CONVERSION)
    2038     47546651 :            && (CLASS_TYPE_P (from) || single_list_conv))
    2039              :     {
    2040     18496087 :       tree rexpr = expr;
    2041     18496087 :       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     18496087 :       z_candidate *cand = build_user_type_conversion_1 (rto, rexpr, flags,
    2058              :                                                         complain);
    2059     18496087 :       if (cand)
    2060              :         {
    2061        13015 :           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    134055756 :   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    130896682 :   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    173011255 :   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    130896682 :   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    130896682 :   if (!maybe_valid_p && (flags & LOOKUP_SHORTCUT_BAD_CONVS))
    2116              :     {
    2117      7361586 :       if (bad_direct_conv)
    2118              :         return bad_direct_conv;
    2119              : 
    2120      7361257 :       conv = alloc_conversion (ck_deferred_bad);
    2121      7361257 :       conv->bad_p = true;
    2122      7361257 :       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    123535096 :   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    123535096 :   if (!(flags & LOOKUP_COPY_PARM))
    2137    104994490 :     flags |= LOOKUP_ONLYCONVERTING;
    2138              : 
    2139    123535096 :   if (!conv)
    2140    123535096 :     conv = implicit_conversion (to, from, expr, c_cast_p,
    2141              :                                 flags, complain);
    2142    123535096 :   if (!conv)
    2143              :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2144              : 
    2145     11385396 :   if (conv->user_conv_p)
    2146              :     {
    2147      7607940 :       if (copy_list_init)
    2148              :         /* Remember this was copy-list-initialization.  */
    2149        59159 :         conv->need_temporary_p = true;
    2150              : 
    2151              :       /* If initializing the temporary used a conversion function,
    2152              :          recalculate the second conversion sequence.  */
    2153     21963790 :       for (conversion *t = conv; t; t = next_conversion (t))
    2154     14774052 :         if (t->kind == ck_user
    2155      7582513 :             && 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     14774040 :         else if (t->kind == ck_user
    2165     14774040 :                  && DECL_CONV_FN_P (t->cand->fn))
    2166              :           {
    2167       418190 :             tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn));
    2168              :             /* A prvalue of non-class type is cv-unqualified.  */
    2169       418190 :             if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype))
    2170         1638 :               ftype = cv_unqualified (ftype);
    2171       418190 :             int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND;
    2172       418190 :             conversion *new_second
    2173       418190 :               = reference_binding (rto, ftype, NULL_TREE, c_cast_p,
    2174              :                                    sflags, complain);
    2175       418190 :             if (!new_second)
    2176              :               return bad_direct_conv ? bad_direct_conv : nullptr;
    2177       418190 :             conv = merge_conversion_sequences (t, new_second);
    2178       418190 :             gcc_assert (maybe_valid_p || conv->bad_p);
    2179              :             return conv;
    2180              :           }
    2181              :     }
    2182              : 
    2183     10967206 :   conv = build_conv (ck_ref_bind, rto, conv);
    2184              :   /* This reference binding, unlike those above, requires the
    2185              :      creation of a temporary.  */
    2186     10967206 :   conv->need_temporary_p = true;
    2187     10967206 :   conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
    2188     10967206 :   conv->bad_p |= !maybe_valid_p;
    2189              : 
    2190     10967206 :   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   1457372269 : implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
    2200              :                      int flags, tsubst_flags_t complain)
    2201              : {
    2202   1457372269 :   conversion *conv;
    2203              : 
    2204   1457372269 :   if (from == error_mark_node || to == error_mark_node
    2205   1457371101 :       || 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   1457371101 :   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   1457371101 :   complain &= ~tf_error;
    2220              : 
    2221              :   /* Call reshape_init early to remove redundant braces.  */
    2222   1457371101 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) && CLASS_TYPE_P (to))
    2223              :     {
    2224      2217836 :       to = complete_type (to);
    2225      2217836 :       if (!COMPLETE_TYPE_P (to))
    2226              :         return nullptr;
    2227      2217812 :       if (!CLASSTYPE_NON_AGGREGATE (to))
    2228              :         {
    2229      1238749 :           expr = reshape_init (to, expr, complain);
    2230      1238749 :           if (expr == error_mark_node)
    2231              :             return nullptr;
    2232      1238509 :           from = TREE_TYPE (expr);
    2233              :         }
    2234              :     }
    2235              : 
    2236              :   /* An argument should have gone through convert_from_reference.  */
    2237   1457370837 :   gcc_checking_assert (!expr || !TYPE_REF_P (from));
    2238              : 
    2239   1457370837 :   if (TYPE_REF_P (to))
    2240    232318351 :     conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
    2241              :   else
    2242   1225052486 :     conv = standard_conversion (to, from, expr, c_cast_p, flags, complain);
    2243              : 
    2244   1457370837 :   if (conv)
    2245              :     return conv;
    2246              : 
    2247    298530449 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    2248              :     {
    2249      4510547 :       if (is_std_init_list (to) && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2250        82223 :         return build_list_conv (to, expr, flags, complain);
    2251              : 
    2252              :       /* As an extension, allow list-initialization of _Complex.  */
    2253      4346092 :       if (TREE_CODE (to) == COMPLEX_TYPE
    2254      4401065 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2255              :         {
    2256        54964 :           conv = build_complex_conv (to, expr, flags, complain);
    2257        54964 :           if (conv)
    2258              :             return conv;
    2259              :         }
    2260              : 
    2261              :       /* Allow conversion from an initializer-list with one element to a
    2262              :          scalar type.  */
    2263      4291168 :       if (SCALAR_TYPE_P (to))
    2264              :         {
    2265      2131874 :           int nelts = CONSTRUCTOR_NELTS (expr);
    2266       331606 :           tree elt;
    2267              : 
    2268       331606 :           if (nelts == 0)
    2269      1800268 :             elt = build_value_init (to, tf_none);
    2270       331606 :           else if (nelts == 1 && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2271       330891 :             elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2272              :           else
    2273          715 :             elt = error_mark_node;
    2274              : 
    2275      2131874 :           conv = implicit_conversion (to, TREE_TYPE (elt), elt,
    2276              :                                       c_cast_p, flags, complain);
    2277      2131874 :           if (conv)
    2278              :             {
    2279      2130196 :               conv->check_narrowing = true;
    2280      2130196 :               if (BRACE_ENCLOSED_INITIALIZER_P (elt))
    2281              :                 /* Too many levels of braces, i.e. '{{1}}'.  */
    2282           16 :                 conv->bad_p = true;
    2283      2130196 :               return conv;
    2284              :             }
    2285              :         }
    2286      2159294 :       else if (TREE_CODE (to) == ARRAY_TYPE)
    2287         1663 :         return build_array_conv (to, expr, flags, complain);
    2288              :     }
    2289              : 
    2290    296261443 :   if (expr != NULL_TREE
    2291    289193963 :       && (MAYBE_CLASS_TYPE_P (from)
    2292    146388963 :           || MAYBE_CLASS_TYPE_P (to))
    2293    510255239 :       && (flags & LOOKUP_NO_CONVERSION) == 0)
    2294              :     {
    2295     79563926 :       struct z_candidate *cand;
    2296              : 
    2297     54319472 :       if (CLASS_TYPE_P (to)
    2298     54319282 :           && BRACE_ENCLOSED_INITIALIZER_P (expr)
    2299     81698901 :           && !CLASSTYPE_NON_AGGREGATE (complete_type (to)))
    2300      1238454 :         return build_aggr_conv (to, expr, flags, complain);
    2301              : 
    2302     78325472 :       cand = build_user_type_conversion_1 (to, expr, flags, complain);
    2303     78325472 :       if (cand)
    2304              :         {
    2305       883496 :           if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    2306       874130 :               && CONSTRUCTOR_NELTS (expr) == 1
    2307        56880 :               && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    2308     14318293 :               && !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        56520 :               tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2316        56520 :               tree elttype = TREE_TYPE (elt);
    2317        56520 :               if (reference_related_p (to, elttype))
    2318           79 :                 return implicit_conversion (to, elttype, elt,
    2319           79 :                                             c_cast_p, flags, complain);
    2320              :             }
    2321     14261334 :           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     78325393 :       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      6778277 : good_conversion (tree to, tree from, tree expr,
    2341              :                  int flags, tsubst_flags_t complain)
    2342              : {
    2343      6778277 :   conversion *c = implicit_conversion (to, from, expr, /*cast*/false,
    2344              :                                        flags, complain);
    2345      6778277 :   if (c && c->bad_p)
    2346      2624056 :     c = NULL;
    2347      6778277 :   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   1052695545 : 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   1052695545 :   struct z_candidate *cand = (struct z_candidate *)
    2363   1052695545 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2364              : 
    2365   1052695545 :   cand->fn = fn;
    2366   1052695545 :   cand->first_arg = first_arg;
    2367   1052695545 :   cand->args = args;
    2368   1052695545 :   cand->convs = convs;
    2369   1052695545 :   cand->num_convs = num_convs;
    2370   1052695545 :   cand->access_path = access_path;
    2371   1052695545 :   cand->conversion_path = conversion_path;
    2372   1052695545 :   cand->viable = viable;
    2373   1052695545 :   cand->reason = reason;
    2374   1052695545 :   cand->next = *candidates;
    2375   1052695545 :   cand->flags = flags;
    2376   1052695545 :   *candidates = cand;
    2377              : 
    2378   1052695545 :   if (convs && cand->reversed ())
    2379              :     /* Swap the conversions for comparison in joust; we'll swap them back
    2380              :        before build_over_call.  */
    2381     89849067 :     std::swap (convs[0], convs[1]);
    2382              : 
    2383   1052695545 :   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    685151788 : add_ignored_candidate (z_candidate **candidates, tree fn)
    2392              : {
    2393              :   /* No need to dynamically allocate these.  */
    2394    685151788 :   static const rejection_reason reason_ignored = { rr_ignored, {} };
    2395              : 
    2396    685151788 :   struct z_candidate *cand = (struct z_candidate *)
    2397    685146908 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2398              : 
    2399    685151788 :   cand->fn = fn;
    2400    685151788 :   cand->reason = const_cast<rejection_reason *> (&reason_ignored);
    2401    685151788 :   cand->next = *candidates;
    2402    685151788 :   *candidates = cand;
    2403              : 
    2404    685151788 :   return cand;
    2405              : }
    2406              : 
    2407              : /* True iff CAND is a candidate added by add_ignored_candidate.  */
    2408              : 
    2409              : static bool
    2410    615839909 : ignored_candidate_p (const z_candidate *cand)
    2411              : {
    2412    615833854 :   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    149095973 : remaining_arguments (tree arg)
    2420              : {
    2421    149095973 :   int n;
    2422              : 
    2423    257622699 :   for (n = 0; arg != NULL_TREE && arg != void_list_node;
    2424    108526726 :        arg = TREE_CHAIN (arg))
    2425    108526726 :     n++;
    2426              : 
    2427    149095973 :   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    429051780 : conv_flags (int i, int nargs, tree fn, tree arg, int flags)
    2441              : {
    2442    429051780 :   int lflags = flags;
    2443    429051780 :   tree t;
    2444    444884234 :   if (i == 0 && nargs == 1 && DECL_CONSTRUCTOR_P (fn)
    2445    146113038 :       && (t = FUNCTION_FIRST_USER_PARMTYPE (fn))
    2446    575164818 :       && (same_type_ignoring_top_level_qualifiers_p
    2447    146113038 :           (non_reference (TREE_VALUE (t)), DECL_CONTEXT (fn))))
    2448              :     {
    2449    114040769 :       if (!(flags & LOOKUP_ONLYCONVERTING))
    2450     33758673 :         lflags |= LOOKUP_COPY_PARM;
    2451    114040769 :       if ((flags & LOOKUP_LIST_INIT_CTOR)
    2452    114040769 :           && BRACE_ENCLOSED_INITIALIZER_P (arg))
    2453         1397 :         lflags |= LOOKUP_NO_CONVERSION;
    2454              :     }
    2455              :   else
    2456    315011011 :     lflags |= LOOKUP_ONLYCONVERTING;
    2457              : 
    2458    429051780 :   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     91514371 : build_this_conversion (tree fn, tree ctype,
    2467              :                        tree& parmtype, tree& argtype, tree& arg,
    2468              :                        int flags, tsubst_flags_t complain)
    2469              : {
    2470    183028742 :   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     91514371 :   parmtype = cp_build_qualified_type (ctype,
    2483     91514371 :                                       cp_type_quals (TREE_TYPE (parmtype)));
    2484     91514371 :   bool this_p = true;
    2485     91514371 :   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       156797 :       bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
    2490       156797 :       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       156797 :       this_p = false;
    2494              :     }
    2495              :   else
    2496              :     {
    2497     91357574 :       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     91357574 :       arg = build_address (arg);
    2502     91357574 :       argtype = lvalue_type (arg);
    2503              :     }
    2504     91514371 :   flags |= LOOKUP_ONLYCONVERTING;
    2505     91514371 :   conversion *t = implicit_conversion (parmtype, argtype, arg,
    2506              :                                        /*c_cast_p=*/false, flags, complain);
    2507     91514371 :   t->this_p = this_p;
    2508     91514371 :   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    606301271 : 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    606301271 :   tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2537    606301271 :   int i, len;
    2538    606301271 :   tree parmnode;
    2539    606301271 :   tree orig_first_arg = first_arg;
    2540    606301271 :   int skip;
    2541    606301271 :   int viable = 1;
    2542    606301271 :   struct rejection_reason *reason = NULL;
    2543              : 
    2544              :   /* The `this', `in_chrg' and VTT arguments to constructors are not
    2545              :      considered in overload resolution.  */
    2546   1212602542 :   if (DECL_CONSTRUCTOR_P (fn))
    2547              :     {
    2548    281011261 :       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    281011186 :         parmlist = skip_artificial_parms_for (fn, parmlist);
    2553    281011261 :       skip = num_artificial_parms_for (fn);
    2554    281011261 :       if (skip > 0 && first_arg != NULL_TREE)
    2555              :         {
    2556    281011261 :           --skip;
    2557    281011261 :           first_arg = NULL_TREE;
    2558              :         }
    2559              :     }
    2560              :   else
    2561              :     skip = 0;
    2562              : 
    2563   1173390055 :   len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0);
    2564    606301271 :   if (!convs)
    2565    527902061 :     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    606301271 :   parmnode = parmlist;
    2575   1240590337 :   for (i = 0; i < len; ++i)
    2576              :     {
    2577    708747699 :       if (parmnode == NULL_TREE || parmnode == void_list_node)
    2578              :         break;
    2579    634289066 :       parmnode = TREE_CHAIN (parmnode);
    2580              :     }
    2581              : 
    2582    606301271 :   if ((i < len && parmnode)
    2583    606301271 :       || !sufficient_parms_p (parmnode))
    2584              :     {
    2585    149092518 :       int remaining = remaining_arguments (parmnode);
    2586    149092518 :       viable = 0;
    2587    149092518 :       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    556290703 :   if (viable && len == 1 && parmlist && DECL_CONSTRUCTOR_P (fn)
    2596    148324610 :       && flag_new_inheriting_ctors
    2597    754617196 :       && DECL_INHERITED_CTOR (fn))
    2598              :     {
    2599       843834 :       tree ptype = non_reference (TREE_VALUE (parmlist));
    2600       843834 :       tree dtype = DECL_CONTEXT (fn);
    2601      1687668 :       tree btype = DECL_INHERITED_CTOR_BASE (fn);
    2602       843834 :       if (reference_related_p (ptype, dtype)
    2603       843834 :           && reference_related_p (btype, ptype))
    2604              :         {
    2605       598652 :           viable = false;
    2606       598652 :           reason = inherited_ctor_rejection ();
    2607              :         }
    2608              :     }
    2609              : 
    2610              :   /* Second, for a function to be viable, its constraints must be
    2611              :      satisfied. */
    2612    606301271 :   if (flag_concepts && viable && !constraints_satisfied_p (fn))
    2613              :     {
    2614       151166 :       reason = constraint_failure ();
    2615       151166 :       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    606301271 :   if (viable && parmlist && (flags & LOOKUP_DEFAULTED))
    2622              :     {
    2623     75689348 :       if (DECL_CONSTRUCTOR_P (fn))
    2624              :         i = 1;
    2625     19659857 :       else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    2626     19659857 :                && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    2627              :         i = 2;
    2628              :       else
    2629              :         i = 0;
    2630     37844674 :       if (i && len == i)
    2631              :         {
    2632     20879092 :           parmnode = chain_index (i-1, parmlist);
    2633     20879092 :           if (!reference_related_p (non_reference (TREE_VALUE (parmnode)),
    2634              :                                     ctype))
    2635      4205830 :             viable = 0;
    2636              :         }
    2637              : 
    2638              :       /* This only applies at the top level.  */
    2639     33638844 :       flags &= ~LOOKUP_DEFAULTED;
    2640              :     }
    2641              : 
    2642    606301271 :   if (! viable)
    2643    154048166 :     goto out;
    2644              : 
    2645    452253105 :   if (shortcut_bad_convs)
    2646    452123776 :     flags |= LOOKUP_SHORTCUT_BAD_CONVS;
    2647              :   else
    2648       129329 :     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    452253105 :   parmnode = parmlist;
    2655              : 
    2656    775055795 :   for (i = 0; i < len; ++i)
    2657              :     {
    2658    497625592 :       tree argtype, to_type;
    2659    497625592 :       tree arg;
    2660              : 
    2661    497625592 :       if (parmnode == void_list_node)
    2662              :         break;
    2663              : 
    2664    497625592 :       if (convs[i])
    2665              :         {
    2666              :           /* Already set during deduction.  */
    2667      6027473 :           parmnode = TREE_CHAIN (parmnode);
    2668      6027473 :           continue;
    2669              :         }
    2670              : 
    2671    491598119 :       if (i == 0 && first_arg != NULL_TREE)
    2672     88039004 :         arg = first_arg;
    2673              :       else
    2674    403559115 :         arg = const_cast<tree> (
    2675    773328691 :                 (*args)[i + skip - (first_arg != NULL_TREE ? 1 : 0)]);
    2676    491598119 :       argtype = lvalue_type (arg);
    2677              : 
    2678    491598119 :       conversion *t;
    2679    491598119 :       if (parmnode)
    2680              :         {
    2681    486414808 :           tree parmtype = TREE_VALUE (parmnode);
    2682    486414808 :           if (i == 0
    2683    394482100 :               && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2684    956630888 :               && !DECL_CONSTRUCTOR_P (fn))
    2685     88030032 :             t = build_this_conversion (fn, ctype, parmtype, argtype, arg,
    2686              :                                        flags, complain);
    2687              :           else
    2688              :             {
    2689    398384776 :               int lflags = conv_flags (i, len-skip, fn, arg, flags);
    2690    398384776 :               t = implicit_conversion (parmtype, argtype, arg,
    2691              :                                        /*c_cast_p=*/false, lflags, complain);
    2692              :             }
    2693    486414808 :           to_type = parmtype;
    2694    486414808 :           parmnode = TREE_CHAIN (parmnode);
    2695              :         }
    2696              :       else
    2697              :         {
    2698      5183311 :           t = build_identity_conv (argtype, arg);
    2699      5183311 :           t->ellipsis_p = true;
    2700      5183311 :           to_type = argtype;
    2701              :         }
    2702              : 
    2703    491598119 :       convs[i] = t;
    2704    491598119 :       if (! t)
    2705              :         {
    2706    153728033 :           viable = 0;
    2707    153728033 :           reason = arg_conversion_rejection (first_arg, i, argtype, to_type,
    2708    153728033 :                                              EXPR_LOCATION (arg));
    2709    153728033 :           break;
    2710              :         }
    2711              : 
    2712    337870086 :       if (t->bad_p)
    2713              :         {
    2714     21126430 :           viable = -1;
    2715     21126430 :           reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type,
    2716     21126430 :                                                  EXPR_LOCATION (arg));
    2717     21126430 :           if (shortcut_bad_convs)
    2718              :             break;
    2719              :         }
    2720              :     }
    2721              : 
    2722    277430203 :  out:
    2723    606301271 :   return add_candidate (candidates, fn, orig_first_arg, args, len, convs,
    2724    606301271 :                         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        95238 : 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        95238 :   tree totype = TREE_TYPE (TREE_TYPE (fn));
    2746        95238 :   int i, len, viable, flags;
    2747        95238 :   tree parmlist, parmnode;
    2748        95238 :   conversion **convs;
    2749        95238 :   struct rejection_reason *reason;
    2750              : 
    2751       190634 :   for (parmlist = totype; TREE_CODE (parmlist) != FUNCTION_TYPE; )
    2752        95396 :     parmlist = TREE_TYPE (parmlist);
    2753        95238 :   parmlist = TYPE_ARG_TYPES (parmlist);
    2754              : 
    2755        95238 :   len = vec_safe_length (arglist) + 1;
    2756        95238 :   convs = alloc_conversions (len);
    2757        95238 :   parmnode = parmlist;
    2758        95238 :   viable = 1;
    2759        95238 :   flags = LOOKUP_IMPLICIT;
    2760        95238 :   reason = NULL;
    2761              : 
    2762              :   /* Don't bother looking up the same type twice.  */
    2763        95238 :   if (*candidates && (*candidates)->fn == totype)
    2764              :     return NULL;
    2765              : 
    2766        95223 :   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       311609 :   for (i = 0; i < len; ++i)
    2775              :     {
    2776       216552 :       tree arg, argtype, convert_type = NULL_TREE;
    2777       216552 :       conversion *t;
    2778              : 
    2779       216552 :       if (i == 0)
    2780              :         arg = obj;
    2781              :       else
    2782       121338 :         arg = (*arglist)[i - 1];
    2783       216552 :       argtype = lvalue_type (arg);
    2784              : 
    2785       216552 :       if (i == 0)
    2786              :         {
    2787        95214 :           t = build_identity_conv (argtype, NULL_TREE);
    2788        95214 :           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        95214 :           convert_type = totype;
    2792              :         }
    2793       121338 :       else if (parmnode == void_list_node)
    2794              :         break;
    2795       121242 :       else if (parmnode)
    2796              :         {
    2797       121233 :           t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg,
    2798              :                                    /*c_cast_p=*/false, flags, complain);
    2799       121233 :           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       216456 :       convs[i] = t;
    2809       216456 :       if (! t)
    2810              :         break;
    2811              : 
    2812       216395 :       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       216395 :       if (i == 0)
    2820        95214 :         continue;
    2821              : 
    2822       121181 :       if (parmnode)
    2823       121172 :         parmnode = TREE_CHAIN (parmnode);
    2824              :     }
    2825              : 
    2826        95214 :   if (i < len
    2827        95214 :       || ! 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        95214 :   return add_candidate (candidates, totype, obj, arglist, len, convs,
    2835        95214 :                         access_path, conversion_path, viable, reason, flags);
    2836              : }
    2837              : 
    2838              : static void
    2839      9003534 : 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      9003534 :   conversion *t;
    2844      9003534 :   conversion **convs;
    2845      9003534 :   size_t num_convs;
    2846      9003534 :   int viable = 1;
    2847      9003534 :   tree types[2];
    2848      9003534 :   struct rejection_reason *reason = NULL;
    2849              : 
    2850      9003534 :   types[0] = type1;
    2851      9003534 :   types[1] = type2;
    2852              : 
    2853      9003534 :   num_convs = args.length ();
    2854      9003534 :   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      9003534 :   if (type1 != boolean_type_node)
    2862      8460802 :     flags |= LOOKUP_ONLYCONVERTING;
    2863              : 
    2864     26304689 :   for (unsigned i = 0; i < 2 && i < num_convs; ++i)
    2865              :     {
    2866     17301155 :       t = implicit_conversion (types[i], argtypes[i], args[i],
    2867              :                                /*c_cast_p=*/false, flags, complain);
    2868     17301155 :       if (! t)
    2869              :         {
    2870      1818953 :           viable = 0;
    2871              :           /* We need something for printing the candidate.  */
    2872      1818953 :           t = build_identity_conv (types[i], NULL_TREE);
    2873      1818953 :           reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i],
    2874      1818953 :                                              types[i], EXPR_LOCATION (args[i]));
    2875              :         }
    2876     15482202 :       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     17301155 :       convs[i] = t;
    2884              :     }
    2885              : 
    2886              :   /* For COND_EXPR we rearranged the arguments; undo that now.  */
    2887      9003534 :   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      9003534 :   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      9003534 : }
    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         2880 : 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         2880 :   return ((CP_INTEGRAL_TYPE_P (type)
    2931          204 :            && same_type_p (type_promotes_to (type), type))
    2932         2880 :           || 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     13282918 : 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     13282918 :   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     13282918 :   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       108479 :     case INDIRECT_REF:
    3012       108479 :       if (TYPE_PTR_P (type1)
    3013       108479 :           && (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       195523 :     case NEGATE_EXPR:
    3031       195523 :       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       152622 :     case BIT_NOT_EXPR:
    3040       152622 :       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       192963 :     case MINUS_EXPR:
    3120       192963 :       if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
    3121              :         break;
    3122           13 :       if (TYPE_PTROB_P (type1)
    3123       192949 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3124              :         {
    3125            4 :           type2 = ptrdiff_type_node;
    3126            4 :           break;
    3127              :         }
    3128              :       /* FALLTHRU */
    3129       842141 :     case MULT_EXPR:
    3130       842141 :     case TRUNC_DIV_EXPR:
    3131       842141 :       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      6358314 :     case SPACESHIP_EXPR:
    3140      6358314 :     case EQ_EXPR:
    3141      6358314 :     case NE_EXPR:
    3142       207000 :       if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3143      6565314 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)))
    3144              :         break;
    3145      6358280 :       if (NULLPTR_TYPE_P (type1) && NULLPTR_TYPE_P (type2))
    3146              :         break;
    3147      6358274 :       if (TYPE_PTRMEM_P (type1) && null_ptr_cst_p (args[1]))
    3148              :         {
    3149              :           type2 = type1;
    3150              :           break;
    3151              :         }
    3152      6358271 :       if (TYPE_PTRMEM_P (type2) && null_ptr_cst_p (args[0]))
    3153              :         {
    3154              :           type1 = type2;
    3155              :           break;
    3156              :         }
    3157              :       /* Fall through.  */
    3158      7041950 :     case LT_EXPR:
    3159      7041950 :     case GT_EXPR:
    3160      7041950 :     case LE_EXPR:
    3161      7041950 :     case GE_EXPR:
    3162      7041950 :     case MAX_EXPR:
    3163      7041950 :     case MIN_EXPR:
    3164      7041950 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3165              :         break;
    3166      5420427 :       if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3167              :         break;
    3168      5416749 :       if (TREE_CODE (type1) == ENUMERAL_TYPE
    3169      3869455 :           && TREE_CODE (type2) == ENUMERAL_TYPE)
    3170              :         break;
    3171      2647047 :       if (TYPE_PTR_P (type1)
    3172      2647047 :           && null_ptr_cst_p (args[1]))
    3173              :         {
    3174              :           type2 = type1;
    3175              :           break;
    3176              :         }
    3177      2647028 :       if (null_ptr_cst_p (args[0])
    3178      2647028 :           && TYPE_PTR_P (type2))
    3179              :         {
    3180              :           type1 = type2;
    3181              :           break;
    3182              :         }
    3183              :       return;
    3184              : 
    3185       221308 :     case PLUS_EXPR:
    3186       221308 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3187              :         break;
    3188              :       /* FALLTHRU */
    3189       166545 :     case ARRAY_REF:
    3190       166545 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && TYPE_PTROB_P (type2))
    3191              :         {
    3192            6 :           type1 = ptrdiff_type_node;
    3193            6 :           break;
    3194              :         }
    3195       166539 :       if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3196              :         {
    3197        36158 :           type2 = ptrdiff_type_node;
    3198        36158 :           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      2955565 :     case TRUNC_MOD_EXPR:
    3214      2955565 :     case BIT_AND_EXPR:
    3215      2955565 :     case BIT_IOR_EXPR:
    3216      2955565 :     case BIT_XOR_EXPR:
    3217      2955565 :     case LSHIFT_EXPR:
    3218      2955565 :     case RSHIFT_EXPR:
    3219      2955565 :       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      1717433 :     case MODIFY_EXPR:
    3260      1717433 :       switch (code2)
    3261              :         {
    3262        99859 :         case PLUS_EXPR:
    3263        99859 :         case MINUS_EXPR:
    3264        99859 :           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        99864 :         case MULT_EXPR:
    3271        99864 :         case TRUNC_DIV_EXPR:
    3272        99864 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3273              :             break;
    3274              :           return;
    3275              : 
    3276      1617569 :         case TRUNC_MOD_EXPR:
    3277      1617569 :         case BIT_AND_EXPR:
    3278      1617569 :         case BIT_IOR_EXPR:
    3279      1617569 :         case BIT_XOR_EXPR:
    3280      1617569 :         case LSHIFT_EXPR:
    3281      1617569 :         case RSHIFT_EXPR:
    3282      1617569 :           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      1381911 :       type1 = build_reference_type (type1);
    3305      1381911 :       break;
    3306              : 
    3307         2699 :     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         2699 :       if (promoted_arithmetic_type_p (type1)
    3323         2699 :           && promoted_arithmetic_type_p (type2))
    3324              :         /* That's OK.  */
    3325              :         break;
    3326              : 
    3327              :       /* Otherwise, the types should be pointers.  */
    3328         2676 :       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         2555 :         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      8460678 :   bool u1 = uses_template_parms (type1);
    3350      8460678 :   bool u2 = type2 ? uses_template_parms (type2) : false;
    3351      8460665 :   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      8460668 :         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      8234773 :   if (type2 && !same_type_p (type1, type2)
    3373      1844717 :       && TREE_CODE (type1) == TREE_CODE (type2)
    3374      8887027 :       && (TYPE_REF_P (type1)
    3375       426359 :           || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3376       426248 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3377       426230 :           || TYPE_PTRMEMFUNC_P (type1)
    3378       426230 :           || MAYBE_CLASS_TYPE_P (type1)
    3379       426230 :           || 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      8460445 :   build_builtin_candidate
    3406      8460445 :     (candidates, fnname, type1, type2, args, argtypes, flags, complain);
    3407              : }
    3408              : 
    3409              : tree
    3410    809941054 : type_decays_to (tree type)
    3411              : {
    3412    809941054 :   if (TREE_CODE (type) == ARRAY_TYPE)
    3413      6059974 :     return build_pointer_type (TREE_TYPE (type));
    3414    803881080 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    3415        31811 :     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     24154202 : 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     24154202 :   int ref1;
    3439     24154202 :   int enum_p = 0;
    3440     24154202 :   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     24154202 :   vec<tree, va_gc> *types[2];
    3444     24154202 :   unsigned ix;
    3445     24154202 :   vec<tree, va_gc> &args = *argv;
    3446     24154202 :   unsigned len = args.length ();
    3447              : 
    3448     67438292 :   for (unsigned i = 0; i < len; ++i)
    3449              :     {
    3450     43284090 :       if (args[i])
    3451     43284090 :         argtypes[i] = unlowered_expr_type (args[i]);
    3452              :       else
    3453            0 :         argtypes[i] = NULL_TREE;
    3454              :     }
    3455              : 
    3456     24154202 :   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       480018 :     case TRUTH_NOT_EXPR:
    3477       480018 :       build_builtin_candidate
    3478       480018 :         (candidates, fnname, boolean_type_node,
    3479              :          NULL_TREE, args, argtypes, flags, complain);
    3480     14054797 :       return;
    3481              : 
    3482        62714 :     case TRUTH_ORIF_EXPR:
    3483        62714 :     case TRUTH_ANDIF_EXPR:
    3484        62714 :       build_builtin_candidate
    3485        62714 :         (candidates, fnname, boolean_type_node,
    3486              :          boolean_type_node, args, argtypes, flags, complain);
    3487        62714 :       return;
    3488              : 
    3489              :     case ADDR_EXPR:
    3490              :     case COMPOUND_EXPR:
    3491              :     case COMPONENT_REF:
    3492              :     case CO_AWAIT_EXPR:
    3493              :       return;
    3494              : 
    3495      6357286 :     case COND_EXPR:
    3496      6357286 :     case EQ_EXPR:
    3497      6357286 :     case NE_EXPR:
    3498      6357286 :     case LT_EXPR:
    3499      6357286 :     case LE_EXPR:
    3500      6357286 :     case GT_EXPR:
    3501      6357286 :     case GE_EXPR:
    3502      6357286 :     case SPACESHIP_EXPR:
    3503      6357286 :       enum_p = 1;
    3504              :       /* Fall through.  */
    3505              : 
    3506              :     default:
    3507              :       ref1 = 0;
    3508              :     }
    3509              : 
    3510     21492079 :   types[0] = make_tree_vector ();
    3511     21492079 :   types[1] = make_tree_vector ();
    3512              : 
    3513     21492079 :   if (len == 3)
    3514          689 :     len = 2;
    3515     42987695 :   for (unsigned i = 0; i < len; ++i)
    3516              :     {
    3517     32408272 :       if (MAYBE_CLASS_TYPE_P (argtypes[i]))
    3518              :         {
    3519     15220972 :           tree convs;
    3520              : 
    3521     15220972 :           if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
    3522              :             return;
    3523              : 
    3524     11809728 :           convs = lookup_conversions (argtypes[i]);
    3525              : 
    3526     11809728 :           if (code == COND_EXPR)
    3527              :             {
    3528         1208 :               if (lvalue_p (args[i]))
    3529          883 :                 vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3530              : 
    3531         1208 :               vec_safe_push (types[i], TYPE_MAIN_VARIANT (argtypes[i]));
    3532              :             }
    3533              : 
    3534     11808520 :           else if (! convs)
    3535              :             return;
    3536              : 
    3537     10596711 :           for (; convs; convs = TREE_CHAIN (convs))
    3538              :             {
    3539      6288395 :               type = TREE_TYPE (convs);
    3540              : 
    3541      7783861 :               if (i == 0 && ref1
    3542      6288395 :                   && (!TYPE_REF_P (type)
    3543         1319 :                       || CP_TYPE_CONST_P (TREE_TYPE (type))))
    3544      1495466 :                 continue;
    3545              : 
    3546      4792929 :               if (code == COND_EXPR && TYPE_REF_P (type))
    3547           23 :                 vec_safe_push (types[i], type);
    3548              : 
    3549      4792929 :               type = non_reference (type);
    3550      4792929 :               if (i != 0 || ! ref1)
    3551              :                 {
    3552      4792890 :                   type = cv_unqualified (type_decays_to (type));
    3553      4792890 :                   if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
    3554          328 :                     vec_safe_push (types[i], type);
    3555      4792890 :                   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3556      2712260 :                     type = type_promotes_to (type);
    3557              :                 }
    3558              : 
    3559      4792929 :               if (! vec_member (type, types[i]))
    3560      4789109 :                 vec_safe_push (types[i], type);
    3561              :             }
    3562              :         }
    3563              :       else
    3564              :         {
    3565     17187300 :           if (code == COND_EXPR && lvalue_p (args[i]))
    3566           88 :             vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3567     17187300 :           type = non_reference (argtypes[i]);
    3568     17187300 :           if (i != 0 || ! ref1)
    3569              :             {
    3570     15469954 :               type = cv_unqualified (type_decays_to (type));
    3571     15469954 :               if (enum_p && UNSCOPED_ENUM_P (type))
    3572      1845092 :                 vec_safe_push (types[i], type);
    3573     15469954 :               if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3574      8805842 :                 type = type_promotes_to (type);
    3575              :             }
    3576     17187300 :           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     21682181 :   FOR_EACH_VEC_ELT_REVERSE (*(types[0]), ix, t)
    3583              :     {
    3584     11102758 :       unsigned jx;
    3585     11102758 :       tree u;
    3586              : 
    3587     11102758 :       if (!types[1]->is_empty ())
    3588     23928969 :         FOR_EACH_VEC_ELT_REVERSE (*(types[1]), jx, u)
    3589     12826211 :           add_builtin_candidate
    3590     12826211 :             (candidates, code, code2, fnname, t,
    3591              :              u, args, argtypes, flags, complain);
    3592              :       else
    3593       456707 :         add_builtin_candidate
    3594       456707 :           (candidates, code, code2, fnname, t,
    3595              :            NULL_TREE, args, argtypes, flags, complain);
    3596              :     }
    3597              : 
    3598     10579423 :   release_tree_vector (types[0]);
    3599     10579423 :   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    515713167 : 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    515713167 :   int ntparms = DECL_NTPARMS (tmpl);
    3624    515713167 :   tree targs = make_tree_vec (ntparms);
    3625    515713167 :   unsigned int len = vec_safe_length (arglist);
    3626    515713167 :   unsigned int nargs = (first_arg == NULL_TREE ? 0 : 1) + len;
    3627    515713167 :   unsigned int skip_without_in_chrg = 0;
    3628    515713167 :   tree first_arg_without_in_chrg = first_arg;
    3629    515713167 :   tree *args_without_in_chrg;
    3630    515713167 :   unsigned int nargs_without_in_chrg;
    3631    515713167 :   unsigned int ia, ix;
    3632    515713167 :   tree arg;
    3633    515713167 :   struct z_candidate *cand;
    3634    515713167 :   tree fn;
    3635    515713167 :   struct rejection_reason *reason = NULL;
    3636    515713167 :   int errs;
    3637    515713167 :   conversion **convs = NULL;
    3638              : 
    3639              :   /* We don't do deduction on the in-charge parameter, the VTT
    3640              :      parameter or 'this'.  */
    3641    515713167 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (tmpl))
    3642              :     {
    3643     49938872 :       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    515713167 :         ++skip_without_in_chrg;
    3650              :     }
    3651              : 
    3652    515713167 :   if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
    3653    515713167 :        || DECL_BASE_CONSTRUCTOR_P (tmpl))
    3654    516645137 :       && 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    515713167 :   if (len < skip_without_in_chrg)
    3663            0 :     return add_ignored_candidate (candidates, tmpl);
    3664              : 
    3665    561717002 :   if (DECL_CONSTRUCTOR_P (tmpl) && nargs == 2
    3666    556791309 :       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (first_arg),
    3667     41078142 :                                                     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      2195162 :       if (tree firstparm = FUNCTION_FIRST_USER_PARMTYPE (tmpl))
    3680              :         {
    3681      2195162 :           firstparm = TREE_VALUE (firstparm);
    3682      2195162 :           if (PACK_EXPANSION_P (firstparm))
    3683         1884 :             firstparm = PACK_EXPANSION_PATTERN (firstparm);
    3684      2195162 :           if (TREE_CODE (firstparm) == TEMPLATE_TYPE_PARM)
    3685              :             {
    3686       663149 :               gcc_assert (!explicit_targs);
    3687       663149 :               reason = invalid_copy_with_fn_template_rejection ();
    3688       663149 :               goto fail;
    3689              :             }
    3690              :         }
    3691              :     }
    3692              : 
    3693    515050018 :   nargs_without_in_chrg = ((first_arg_without_in_chrg != NULL_TREE ? 1 : 0)
    3694    515050018 :                            + (len - skip_without_in_chrg));
    3695    515050018 :   args_without_in_chrg = XALLOCAVEC (tree, nargs_without_in_chrg);
    3696    515050018 :   ia = 0;
    3697    515050018 :   if (first_arg_without_in_chrg != NULL_TREE)
    3698              :     {
    3699         6278 :       args_without_in_chrg[ia] = first_arg_without_in_chrg;
    3700         6278 :       ++ia;
    3701              :     }
    3702    880107709 :   for (ix = skip_without_in_chrg;
    3703   1395157727 :        vec_safe_iterate (arglist, ix, &arg);
    3704              :        ++ix)
    3705              :     {
    3706    880107709 :       args_without_in_chrg[ia] = arg;
    3707    880107709 :       ++ia;
    3708              :     }
    3709    515050018 :   gcc_assert (ia == nargs_without_in_chrg);
    3710              : 
    3711    515050018 :   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    515050006 :       int min_arity = 0, max_arity = 0;
    3719    515050006 :       tree parms = TYPE_ARG_TYPES (TREE_TYPE (tmpl));
    3720    515050006 :       parms = skip_artificial_parms_for (tmpl, parms);
    3721   1950131744 :       for (; parms != void_list_node; parms = TREE_CHAIN (parms))
    3722              :         {
    3723   1845744105 :           if (!parms || PACK_EXPANSION_P (TREE_VALUE (parms)))
    3724              :             {
    3725              :               max_arity = -1;
    3726              :               break;
    3727              :             }
    3728    920031732 :           if (TREE_PURPOSE (parms))
    3729              :             /* A parameter with a default argument.  */
    3730      9221330 :             ++max_arity;
    3731              :           else
    3732    910810402 :             ++min_arity, ++max_arity;
    3733              :         }
    3734    515050006 :       if (ia < (unsigned)min_arity)
    3735              :         {
    3736              :           /* Too few arguments.  */
    3737     33790516 :           reason = arity_rejection (NULL_TREE, min_arity, ia,
    3738              :                                     /*least_p=*/(max_arity == -1));
    3739     33790516 :           goto fail;
    3740              :         }
    3741    481259490 :       else if (max_arity != -1 && ia > (unsigned)max_arity)
    3742              :         {
    3743              :           /* Too many arguments.  */
    3744      4804441 :           reason = arity_rejection (NULL_TREE, max_arity, ia);
    3745      4804441 :           goto fail;
    3746              :         }
    3747              : 
    3748    476455049 :       convs = alloc_conversions (nargs);
    3749              : 
    3750    476455049 :       if (shortcut_bad_convs
    3751    476450510 :           && DECL_IOBJ_MEMBER_FUNCTION_P (tmpl)
    3752    547112421 :           && !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      3484339 :           tree parmtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (tmpl)));
    3759      3484339 :           tree argtype = lvalue_type (first_arg);
    3760      3484339 :           tree arg = first_arg;
    3761      3484339 :           conversion *t = build_this_conversion (tmpl, ctype,
    3762              :                                                  parmtype, argtype, arg,
    3763              :                                                  flags, complain);
    3764      3484339 :           convs[0] = t;
    3765      3484339 :           if (t->bad_p)
    3766              :             {
    3767        31701 :               reason = bad_arg_conversion_rejection (first_arg, 0,
    3768              :                                                      arg, parmtype,
    3769        31701 :                                                      EXPR_LOCATION (arg));
    3770        31701 :               goto fail;
    3771              :             }
    3772              :         }
    3773              :     }
    3774              : 
    3775    476423360 :   errs = errorcount+sorrycount;
    3776    952833169 :   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    476423360 :                             false, complain & tf_decltype);
    3781              : 
    3782    476409809 :   if (fn == error_mark_node)
    3783              :     {
    3784              :       /* Don't repeat unification later if it already resulted in errors.  */
    3785    398005138 :       if (errorcount+sorrycount == errs)
    3786    398005028 :         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    398005138 :       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     78404671 :   if (((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    3799              :        == LOOKUP_ONLYCONVERTING)
    3800     78404671 :       && DECL_NONCONVERTING_P (fn))
    3801         4880 :     return add_ignored_candidate (candidates, fn);
    3802              : 
    3803    156799582 :   if (DECL_CONSTRUCTOR_P (fn) && nargs == 2)
    3804              :     {
    3805      4608003 :       tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3806      9215979 :       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     78399219 :   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     78399210 :     cand = add_function_candidate (candidates, fn, ctype,
    3823              :                                    first_arg, arglist, access_path,
    3824              :                                    conversion_path, flags, convs,
    3825              :                                    shortcut_bad_convs, complain);
    3826     78399219 :   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      5295003 :     cand->template_decl = build_template_info (tmpl, targs);
    3845              :   else
    3846     73104216 :     cand->template_decl = DECL_TEMPLATE_INFO (fn);
    3847     78399219 :   cand->explicit_targs = explicit_targs;
    3848              : 
    3849     78399219 :   return cand;
    3850    437295517 :  fail:
    3851    437295517 :   int viable = (reason->code == rr_bad_arg_conversion ? -1 : 0);
    3852    437295517 :   return add_candidate (candidates, tmpl, first_arg, arglist, nargs, convs,
    3853    437295517 :                         access_path, conversion_path, viable, reason, flags);
    3854              : }
    3855              : 
    3856              : 
    3857              : static struct z_candidate *
    3858    515713155 : 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    515713155 :   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    515699604 :                                  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    308845446 : splice_viable (struct z_candidate *cands,
    3904              :                bool strict_p,
    3905              :                bool *any_viable_p)
    3906              : {
    3907    308845446 :   z_candidate *strictly_viable = nullptr;
    3908    308845446 :   z_candidate **strictly_viable_tail = &strictly_viable;
    3909              : 
    3910    308845446 :   z_candidate *non_strictly_viable = nullptr;
    3911    308845446 :   z_candidate **non_strictly_viable_tail = &non_strictly_viable;
    3912              : 
    3913    308845446 :   z_candidate *non_viable = nullptr;
    3914    308845446 :   z_candidate **non_viable_tail = &non_viable;
    3915              : 
    3916    308845446 :   z_candidate *non_viable_ignored = nullptr;
    3917    308845446 :   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    308845446 :   if (processing_template_decl)
    3922     56301949 :     strict_p = true;
    3923              : 
    3924   1217757181 :   for (z_candidate *cand = cands; cand; cand = cand->next)
    3925              :     {
    3926    908911735 :       if (!strict_p
    3927    302483736 :           && (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    810888269 :         strict_p = true;
    3932              : 
    3933              :       /* Move this candidate to the appropriate list according to
    3934              :          its viability.  */
    3935    908911735 :       auto& tail = (cand->viable == 1 ? strictly_viable_tail
    3936              :                     : cand->viable == -1 ? non_strictly_viable_tail
    3937   1470699519 :                     : ignored_candidate_p (cand) ? non_viable_ignored_tail
    3938   1470699519 :                     : non_viable_tail);
    3939    908911735 :       *tail = cand;
    3940    908911735 :       tail = &cand->next;
    3941              :     }
    3942              : 
    3943    617690892 :   *any_viable_p = (strictly_viable != nullptr
    3944    308845446 :                    || (!strict_p && non_strictly_viable != nullptr));
    3945              : 
    3946              :   /* Combine the lists.  */
    3947    308845446 :   *non_viable_ignored_tail = nullptr;
    3948    308845446 :   *non_viable_tail = non_viable_ignored;
    3949    308845446 :   *non_strictly_viable_tail = non_viable;
    3950    308845446 :   *strictly_viable_tail = non_strictly_viable;
    3951              : 
    3952    308845446 :   return strictly_viable;
    3953              : }
    3954              : 
    3955              : static bool
    3956    293689414 : any_strictly_viable (struct z_candidate *cands)
    3957              : {
    3958    427341029 :   for (; cands; cands = cands->next)
    3959    142699484 :     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     64586738 : 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     64586738 :   if (processing_template_decl)
    3974        73829 :     return build_address (obj);
    3975              : 
    3976     64512909 :   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      4572261 : equal_functions (tree fn1, tree fn2)
    3985              : {
    3986      4572261 :   if (TREE_CODE (fn1) != TREE_CODE (fn2))
    3987              :     return 0;
    3988      4556916 :   if (TREE_CODE (fn1) == TEMPLATE_DECL)
    3989        36043 :     return fn1 == fn2;
    3990      9041728 :   if (DECL_LOCAL_DECL_P (fn1) || DECL_LOCAL_DECL_P (fn2)
    3991      9041725 :       || DECL_EXTERN_C_FUNCTION_P (fn1))
    3992      2906628 :     return decls_match (fn1, fn2);
    3993      1614245 :   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        13173 : print_z_candidate (location_t loc, const char *msgstr,
    4068              :                    struct z_candidate *candidate)
    4069              : {
    4070        13173 :   const char *msg = (msgstr == NULL
    4071        13173 :                      ? ""
    4072        13173 :                      : ACONCAT ((_(msgstr), " ", NULL)));
    4073        13173 :   tree fn = candidate->fn;
    4074        13173 :   if (flag_new_inheriting_ctors)
    4075        13146 :     fn = strip_inheriting_ctors (fn);
    4076        13173 :   location_t cloc = location_of (fn);
    4077              : 
    4078        13173 :   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        12959 :   else if (TYPE_P (fn))
    4095           11 :     inform (cloc, "%s%qT (conversion)", msg, fn);
    4096        12948 :   else if (candidate->viable == -1)
    4097         4366 :     inform (cloc, "%s%#qD (near match)", msg, fn);
    4098         8582 :   else if (ignored_candidate_p (candidate))
    4099            6 :     inform (cloc, "%s%#qD (ignored)", msg, fn);
    4100         8576 :   else if (DECL_DELETED_FN (fn))
    4101           60 :     inform (cloc, "%s%#qD (deleted)", msg, fn);
    4102         8516 :   else if (candidate->reversed ())
    4103          300 :     inform (cloc, "%s%#qD (reversed)", msg, fn);
    4104         8216 :   else if (candidate->rewritten ())
    4105          150 :     inform (cloc, "%s%#qD (rewritten)", msg, fn);
    4106              :   else
    4107         8066 :     inform (cloc, "%s%#qD", msg, fn);
    4108              : 
    4109        13173 :   auto_diagnostic_nesting_level sentinel;
    4110              : 
    4111        13173 :   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        13173 :   if (candidate->reason != NULL)
    4119              :     {
    4120        10084 :       struct rejection_reason *r = candidate->reason;
    4121              : 
    4122        10084 :       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         3190 :         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         3190 :           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         3145 :           inform (cloc, "template argument deduction/substitution failed:");
    4159         3145 :           {
    4160         3145 :             auto_diagnostic_nesting_level sentinel;
    4161         3145 :             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         3145 :           }
    4172         3145 :           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        13173 : }
    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         5454 : print_z_candidates (location_t loc, struct z_candidate *candidates,
    4203              :                     tristate only_viable_p /* = tristate::unknown () */)
    4204              : {
    4205         5454 :   struct z_candidate *cand1;
    4206         5454 :   struct z_candidate **cand2;
    4207              : 
    4208         5454 :   if (!candidates)
    4209         1007 :     return;
    4210              : 
    4211              :   /* Remove non-viable deleted candidates.  */
    4212         4447 :   cand1 = candidates;
    4213        20195 :   for (cand2 = &cand1; *cand2; )
    4214              :     {
    4215        15748 :       if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
    4216        11393 :           && !(*cand2)->viable
    4217        19507 :           && DECL_DELETED_FN ((*cand2)->fn))
    4218          102 :         *cand2 = (*cand2)->next;
    4219              :       else
    4220        15646 :         cand2 = &(*cand2)->next;
    4221              :     }
    4222              :   /* ...if there are any non-deleted ones.  */
    4223         4447 :   if (cand1)
    4224         4441 :     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        19793 :   for (cand1 = candidates; cand1; cand1 = cand1->next)
    4232              :     {
    4233        15346 :       tree fn = cand1->fn;
    4234              :       /* Skip builtin candidates and conversion functions.  */
    4235        15346 :       if (!DECL_P (fn))
    4236          285 :         continue;
    4237        15061 :       cand2 = &cand1->next;
    4238       143162 :       while (*cand2)
    4239              :         {
    4240       128101 :           if (DECL_P ((*cand2)->fn)
    4241       128101 :               && equal_functions (fn, (*cand2)->fn))
    4242          306 :             *cand2 = (*cand2)->next;
    4243              :           else
    4244       127795 :             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         4447 :   if (only_viable_p.is_unknown ())
    4253         4438 :     only_viable_p = candidates->viable == 1;
    4254              : 
    4255         4447 :   auto_diagnostic_nesting_level sentinel;
    4256              : 
    4257         4447 :   int num_candidates = 0;
    4258        17508 :   for (auto iter = candidates; iter; iter = iter->next)
    4259              :     {
    4260        13402 :       if (only_viable_p.is_true () && iter->viable != 1)
    4261              :         break;
    4262        13061 :       ++num_candidates;
    4263              :     }
    4264              : 
    4265         4447 :   inform_num_candidates (loc, num_candidates);
    4266              : 
    4267         4447 :   auto_diagnostic_nesting_level sentinel2;
    4268              : 
    4269         4447 :   int candidate_idx = 0;
    4270        21922 :   for (; candidates; candidates = candidates->next)
    4271              :     {
    4272        13398 :       if (only_viable_p.is_true () && candidates->viable != 1)
    4273              :         break;
    4274        13092 :       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        13028 :       pretty_printer pp;
    4281        13028 :       pp_printf (&pp, N_("candidate %i:"), candidate_idx + 1);
    4282        13028 :       const char *const msgstr = pp_formatted_text (&pp);
    4283        13028 :       print_z_candidate (loc, msgstr, candidates);
    4284        13028 :       ++candidate_idx;
    4285        13028 :     }
    4286         4447 : }
    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     14718024 : merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
    4296              : {
    4297     14718024 :   conversion **t;
    4298     14718024 :   bool bad = user_seq->bad_p;
    4299              : 
    4300     14718024 :   gcc_assert (user_seq->kind == ck_user);
    4301              : 
    4302              :   /* Find the end of the second conversion sequence.  */
    4303     15430779 :   for (t = &std_seq; (*t)->kind != ck_identity; t = &((*t)->u.next))
    4304              :     {
    4305              :       /* The entire sequence is a user-conversion sequence.  */
    4306       712755 :       (*t)->user_conv_p = true;
    4307       712755 :       if (bad)
    4308         2941 :         (*t)->bad_p = true;
    4309              :     }
    4310              : 
    4311     14718024 :   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       429588 :     user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
    4316              : 
    4317              :   /* Replace the identity conversion with the user conversion
    4318              :      sequence.  */
    4319     14718024 :   *t = user_seq;
    4320              : 
    4321     14718024 :   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      2424824 : 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      2424824 :   gcc_assert (*candidates == NULL);
    4343              : 
    4344              :   /* We're looking for a ctor for list-initialization.  */
    4345      2424824 :   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      2424824 :   flags |= LOOKUP_NO_NARROWING;
    4349              : 
    4350      4849648 :   unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1;
    4351      2424824 :   tree init_list = (*args)[nart];
    4352              : 
    4353              :   /* Always use the default constructor if the list is empty (DR 990).  */
    4354      2424824 :   if (CONSTRUCTOR_NELTS (init_list) == 0
    4355      2424824 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
    4356              :     ;
    4357      2189132 :   else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list)
    4358      2189132 :            && !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         6707 :       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      2189084 :   else if (TYPE_HAS_LIST_CTOR (totype))
    4368              :     {
    4369        76555 :       flags |= LOOKUP_LIST_ONLY;
    4370        76555 :       add_candidates (fns, first_arg, args, NULL_TREE,
    4371              :                       explicit_targs, template_only, conversion_path,
    4372              :                       access_path, flags, candidates, complain);
    4373       153110 :       if (any_strictly_viable (*candidates))
    4374              :         return;
    4375              :     }
    4376              : 
    4377              :   /* Expand the CONSTRUCTOR into a new argument vec.  */
    4378      2418117 :   vec<tree, va_gc> *new_args;
    4379      4599840 :   vec_alloc (new_args, nart + CONSTRUCTOR_NELTS (init_list));
    4380      2418120 :   for (unsigned i = 0; i < nart; ++i)
    4381            3 :     new_args->quick_push ((*args)[i]);
    4382      2418117 :   new_args = append_ctor_to_tree_vector (new_args, init_list);
    4383              : 
    4384              :   /* We aren't looking for list-ctors anymore.  */
    4385      2418117 :   flags &= ~LOOKUP_LIST_ONLY;
    4386              :   /* We allow more user-defined conversions within an init-list.  */
    4387      2418117 :   flags &= ~LOOKUP_NO_CONVERSION;
    4388              : 
    4389      2418117 :   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         1165 : list_ctor_element_type (tree fn)
    4398              : {
    4399         1165 :   gcc_checking_assert (is_list_ctor (fn));
    4400              : 
    4401         1165 :   tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    4402         1165 :   parm = non_reference (TREE_VALUE (parm));
    4403         1165 :   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         1256 : braced_init_element_type (tree expr)
    4411              : {
    4412         1256 :   if (TREE_CODE (expr) == CONSTRUCTOR
    4413         1256 :       && TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE)
    4414            0 :     return TREE_TYPE (TREE_TYPE (expr));
    4415         1256 :   if (!BRACE_ENCLOSED_INITIALIZER_P (expr))
    4416              :     return NULL_TREE;
    4417              : 
    4418         1256 :   tree elttype = NULL_TREE;
    4419        13618 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (expr))
    4420              :     {
    4421        10026 :       tree type = TREE_TYPE (e.value);
    4422        10026 :       type = type_decays_to (type);
    4423        10026 :       if (!elttype)
    4424              :         elttype = type;
    4425         8789 :       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          248 : count_ctor_elements (tree ctor)
    4455              : {
    4456          248 :   unsigned HOST_WIDE_INT len = 0;
    4457         2046 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (ctor))
    4458         1302 :     if (TREE_CODE (e.value) == RAW_DATA_CST)
    4459            9 :       len += RAW_DATA_LENGTH (e.value);
    4460              :     else
    4461         1293 :       ++len;
    4462          248 :   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        11005 : 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        11005 :   if (!TYPE_NON_AGGREGATE_CLASS (elttype))
    4474              :     return NULL_TREE;
    4475         1256 :   tree init_elttype = braced_init_element_type (init);
    4476         1256 :   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          317 :   conversion_obstack_sentinel cos;
    4482          317 :   init_elttype = cp_build_qualified_type (init_elttype, TYPE_QUAL_CONST);
    4483          317 :   tree arg = build_stub_object (init_elttype);
    4484          317 :   conversion *c = implicit_conversion (elttype, init_elttype, arg, false,
    4485              :                                        LOOKUP_NORMAL, tf_none);
    4486          317 :   if (c && c->kind == ck_rvalue)
    4487            0 :     c = next_conversion (c);
    4488          311 :   if (!c || c->kind != ck_user)
    4489              :     return NULL_TREE;
    4490              :   /* Check that we actually can perform the conversion.  */
    4491          308 :   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          302 :   if (!DECL_CONSTRUCTOR_P (c->cand->fn)
    4498          302 :       || (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          299 :   tree first = CONSTRUCTOR_ELT (init, 0)->value;
    4505          299 :   conversion *fc = implicit_conversion (elttype, init_elttype, first, false,
    4506              :                                         LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING,
    4507              :                                         tf_none);
    4508          299 :   if (fc && fc->kind == ck_rvalue)
    4509           48 :     fc = next_conversion (fc);
    4510          299 :   if (!fc || fc->kind != ck_user || fc->cand->fn != c->cand->fn)
    4511              :     return NULL_TREE;
    4512          257 :   first = convert_like (fc, first, tf_none);
    4513          257 :   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          254 :   first = maybe_constant_init (first);
    4519          254 :   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          317 : }
    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     14299834 : maybe_init_list_as_range (tree fn, tree expr)
    4553              : {
    4554     14299834 :   if (!processing_template_decl
    4555     13793816 :       && BRACE_ENCLOSED_INITIALIZER_P (expr)
    4556       855502 :       && is_list_ctor (fn)
    4557     14301152 :       && decl_in_std_namespace_p (fn))
    4558              :     {
    4559         1165 :       tree to = list_ctor_element_type (fn);
    4560         1165 :       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     96848511 : build_user_type_conversion_1 (tree totype, tree expr, int flags,
    4583              :                               tsubst_flags_t complain)
    4584              : {
    4585     96848511 :   struct z_candidate *candidates, *cand;
    4586     96848511 :   tree fromtype;
    4587     96848511 :   tree ctors = NULL_TREE;
    4588     96848511 :   tree conv_fns = NULL_TREE;
    4589     96848511 :   conversion *conv = NULL;
    4590     96848511 :   tree first_arg = NULL_TREE;
    4591     96848511 :   vec<tree, va_gc> *args = NULL;
    4592     96848511 :   bool any_viable_p;
    4593     96848511 :   int convflags;
    4594              : 
    4595     96848511 :   if (!expr)
    4596              :     return NULL;
    4597              : 
    4598     96848505 :   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     96848505 :   gcc_assert (!MAYBE_CLASS_TYPE_P (fromtype) || !MAYBE_CLASS_TYPE_P (totype)
    4604              :               || !DERIVED_FROM_P (totype, fromtype));
    4605              : 
    4606     96848505 :   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     53107507 :     ctors = get_class_binding (totype, complete_ctor_identifier);
    4610              : 
    4611     96848505 :   tree to_nonref = non_reference (totype);
    4612     96848505 :   if (MAYBE_CLASS_TYPE_P (fromtype))
    4613              :     {
    4614     69256780 :       if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
    4615     69229269 :           (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
    4616     57495858 :            && 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     69229266 :         conv_fns = lookup_conversions (fromtype);
    4626              :     }
    4627              : 
    4628     96848505 :   candidates = 0;
    4629     96848505 :   flags |= LOOKUP_NO_CONVERSION;
    4630     96848505 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4631       896574 :     flags |= LOOKUP_NO_NARROWING;
    4632              :   /* Prevent add_candidates from treating a non-strictly viable candidate
    4633              :      as unviable.  */
    4634     96848505 :   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     96848505 :   convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION
    4639     96848505 :                | (flags & LOOKUP_NO_NARROWING));
    4640     96848505 :   flags &= ~LOOKUP_NO_TEMP_BIND;
    4641              : 
    4642     96848505 :   if (ctors)
    4643              :     {
    4644     52896932 :       int ctorflags = flags;
    4645              : 
    4646     52896932 :       first_arg = build_dummy_object (totype);
    4647              : 
    4648              :       /* We should never try to call the abstract or base constructor
    4649              :          from here.  */
    4650    371226560 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (OVL_FIRST (ctors))
    4651              :                   && !DECL_HAS_VTT_PARM_P (OVL_FIRST (ctors)));
    4652              : 
    4653     52896932 :       args = make_tree_vector_single (expr);
    4654     52896932 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4655              :         {
    4656              :           /* List-initialization.  */
    4657       896574 :           add_list_candidates (ctors, first_arg, args, totype, NULL_TREE,
    4658       896574 :                                false, TYPE_BINFO (totype), TYPE_BINFO (totype),
    4659              :                                ctorflags, &candidates, complain);
    4660              :         }
    4661              :       else
    4662              :         {
    4663     52000358 :           add_candidates (ctors, first_arg, args, NULL_TREE, NULL_TREE, false,
    4664     52000358 :                           TYPE_BINFO (totype), TYPE_BINFO (totype),
    4665              :                           ctorflags, &candidates, complain);
    4666              :         }
    4667              : 
    4668    287684340 :       for (cand = candidates; cand; cand = cand->next)
    4669              :         {
    4670    234787408 :           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    234787408 :           if (!TYPE_REF_P (totype)
    4681    234787408 :               && cxx_dialect < cxx17
    4682       424336 :               && (flags & LOOKUP_ONLYCONVERTING)
    4683       367426 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4684       114600 :             cand->second_conv
    4685       114600 :               = build_conv (ck_rvalue, totype, cand->second_conv);
    4686              :         }
    4687              :     }
    4688              : 
    4689     96848505 :   if (conv_fns)
    4690              :     {
    4691     28733690 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4692            0 :         first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
    4693              :       else
    4694     96848505 :         first_arg = expr;
    4695              :     }
    4696              : 
    4697    130421900 :   for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
    4698              :     {
    4699     33573395 :       tree conversion_path = TREE_PURPOSE (conv_fns);
    4700     33573395 :       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     33573395 :       tree convtype = non_reference (TREE_TYPE (conv_fns));
    4712     49406889 :       if ((flags & LOOKUP_NO_CONVERSION)
    4713     33573395 :           && !WILDCARD_TYPE_P (convtype)
    4714     63799838 :           && (CLASS_TYPE_P (to_nonref)
    4715     31899919 :               != CLASS_TYPE_P (convtype)))
    4716     15833494 :         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     17739901 :       if (TYPE_REF_P (totype))
    4723      4847422 :         convflags |= LOOKUP_NO_TEMP_BIND;
    4724              : 
    4725     17739901 :       old_candidates = candidates;
    4726     17739901 :       add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype,
    4727              :                       NULL_TREE, false,
    4728     17739901 :                       conversion_path, TYPE_BINFO (fromtype),
    4729              :                       flags, &candidates, complain);
    4730              : 
    4731     35479797 :       for (cand = candidates; cand != old_candidates; cand = cand->next)
    4732              :         {
    4733     17739896 :           if (cand->viable == 0)
    4734              :             /* Already rejected, don't change to -1.  */
    4735      6586234 :             continue;
    4736              : 
    4737     11153662 :           tree rettype = TREE_TYPE (TREE_TYPE (cand->fn));
    4738     11153662 :           conversion *ics
    4739     11153662 :             = 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      4086692 :           if (ics && MAYBE_CLASS_TYPE_P (totype) && ics->kind != ck_rvalue
    4756     11811324 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4757       242255 :             ics = build_conv (ck_rvalue, totype, ics);
    4758              : 
    4759     11153662 :           cand->second_conv = ics;
    4760              : 
    4761     11153662 :           if (!ics)
    4762              :             {
    4763      7066970 :               cand->viable = 0;
    4764     14132113 :               cand->reason = arg_conversion_rejection (NULL_TREE, -2,
    4765              :                                                        rettype, totype,
    4766      7066970 :                                                        EXPR_LOCATION (expr));
    4767              :             }
    4768        14425 :           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      4088046 :                    && 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      4085344 :           else if (DECL_NONCONVERTING_P (cand->fn)
    4779      4085344 :                    && 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         2633 :               cand->viable = -1;
    4789         2633 :               cand->reason = explicit_conversion_rejection (rettype, totype);
    4790              :             }
    4791      4082711 :           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      4080719 :           else if (primary_template_specialization_p (cand->fn)
    4800      4080719 :                    && 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     96848505 :   candidates = splice_viable (candidates, false, &any_viable_p);
    4813     96848505 :   if (!any_viable_p)
    4814              :     {
    4815     82547332 :       if (args)
    4816     42011380 :         release_tree_vector (args);
    4817     82547332 :       return NULL;
    4818              :     }
    4819              : 
    4820     14301173 :   cand = tourney (candidates, complain);
    4821     14301173 :   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     14299834 :   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     14299834 :   tree convtype;
    4857     28599668 :   if (!DECL_CONSTRUCTOR_P (cand->fn))
    4858      4073247 :     convtype = non_reference (TREE_TYPE (TREE_TYPE (cand->fn)));
    4859     10226587 :   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        11891 :     convtype = cv_unqualified (totype);
    4864              :   else
    4865              :     convtype = totype;
    4866              :   /* Build the user conversion sequence.  */
    4867     14299834 :   conv = build_conv
    4868     14299834 :     (ck_user,
    4869              :      convtype,
    4870     14299834 :      build_identity_conv (TREE_TYPE (expr), expr));
    4871     14299834 :   conv->cand = cand;
    4872     14299834 :   if (cand->viable == -1)
    4873         7319 :     conv->bad_p = true;
    4874              : 
    4875              :   /* Remember that this was a list-initialization.  */
    4876     14299834 :   if (flags & LOOKUP_NO_NARROWING)
    4877      3206439 :     conv->check_narrowing = true;
    4878              : 
    4879              :   /* Combine it with the second conversion sequence.  */
    4880     14299834 :   cand->second_conv = merge_conversion_sequences (conv,
    4881              :                                                   cand->second_conv);
    4882              : 
    4883     14299834 :   return cand;
    4884              : }
    4885              : 
    4886              : /* Wrapper for above. */
    4887              : 
    4888              : tree
    4889        26843 : build_user_type_conversion (tree totype, tree expr, int flags,
    4890              :                             tsubst_flags_t complain)
    4891              : {
    4892        26843 :   struct z_candidate *cand;
    4893        26843 :   tree ret;
    4894              : 
    4895        26843 :   auto_cond_timevar tv (TV_OVERLOAD);
    4896              : 
    4897        26843 :   conversion_obstack_sentinel cos;
    4898              : 
    4899        26843 :   cand = build_user_type_conversion_1 (totype, expr, flags, complain);
    4900              : 
    4901        26843 :   if (cand)
    4902              :     {
    4903        26639 :       if (cand->second_conv->kind == ck_ambig)
    4904           65 :         ret = error_mark_node;
    4905              :       else
    4906              :         {
    4907        26574 :           expr = convert_like (cand->second_conv, expr, complain);
    4908        26574 :           ret = convert_from_reference (expr);
    4909              :         }
    4910              :     }
    4911              :   else
    4912              :     ret = NULL_TREE;
    4913              : 
    4914        53686 :   return ret;
    4915        26843 : }
    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    303165594 : build_converted_constant_expr_internal (tree type, tree expr,
    4960              :                                         int flags, tsubst_flags_t complain)
    4961              : {
    4962    303165594 :   conversion *conv;
    4963    303165594 :   tree t;
    4964    303165594 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    4965              : 
    4966    303165594 :   if (error_operand_p (expr))
    4967           57 :     return error_mark_node;
    4968              : 
    4969    303165537 :   conversion_obstack_sentinel cos;
    4970              : 
    4971    303165537 :   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    303165537 :   for (conversion *c = conv;
    4992    353008636 :        c && c->kind != ck_identity;
    4993     49843099 :        c = next_conversion (c))
    4994              :     {
    4995     49843099 :       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          537 :         case ck_ref_bind:
    5013          537 :           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      8719464 :         case ck_base:
    5024      8719464 :         case ck_pmem:
    5025      8719464 :         case ck_ptr:
    5026      8719464 :         case ck_std:
    5027      8719464 :           t = next_conversion (c)->type;
    5028      8719464 :           if (INTEGRAL_OR_ENUMERATION_TYPE_P (t)
    5029      8719389 :               && 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    303164885 :   if (conv && conv->kind == ck_ref_bind
    5050    303166074 :       && REFERENCE_REF_P (expr))
    5051              :     {
    5052          291 :       tree ref = TREE_OPERAND (expr, 0);
    5053          291 :       if (same_type_p (type, TREE_TYPE (ref)))
    5054              :         return ref;
    5055              :     }
    5056              : 
    5057    303165268 :   if (conv)
    5058              :     {
    5059              :       /* Don't copy a class in a template.  */
    5060        29061 :       if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue
    5061    303179495 :           && processing_template_decl)
    5062          155 :         conv = next_conversion (conv);
    5063              : 
    5064              :       /* Issuing conversion warnings for value-dependent expressions is
    5065              :          likely too noisy.  */
    5066    303164616 :       warning_sentinel w (warn_conversion);
    5067    303164616 :       conv->check_narrowing = true;
    5068    303164616 :       conv->check_narrowing_const_only = true;
    5069    303164616 :       expr = convert_like (conv, expr, complain);
    5070    303164616 :     }
    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    303165537 : }
    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    174637389 : build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
    5097              : {
    5098    174637389 :   return build_converted_constant_expr_internal (type, expr, LOOKUP_IMPLICIT,
    5099    174637389 :                                                  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    128528205 : build_converted_constant_bool_expr (tree expr, tsubst_flags_t complain)
    5108              : {
    5109    128528205 :   return build_converted_constant_expr_internal (boolean_type_node, expr,
    5110    128528205 :                                                  LOOKUP_NORMAL, complain);
    5111              : }
    5112              : 
    5113              : /* Do any initial processing on the arguments to a function call.  */
    5114              : 
    5115              : vec<tree, va_gc> *
    5116    192313856 : resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
    5117              : {
    5118    192313856 :   unsigned int ix;
    5119    192313856 :   tree arg;
    5120              : 
    5121    358944634 :   FOR_EACH_VEC_SAFE_ELT (args, ix, arg)
    5122              :     {
    5123    166631385 :       if (error_operand_p (arg))
    5124              :         return NULL;
    5125    166630915 :       else if (VOID_TYPE_P (TREE_TYPE (arg)))
    5126              :         {
    5127          110 :           if (complain & tf_error)
    5128           12 :             error_at (cp_expr_loc_or_input_loc (arg),
    5129              :                       "invalid use of void expression");
    5130          110 :           return NULL;
    5131              :         }
    5132    166630805 :       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    166630778 :       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     90010929 : 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     90010929 :   struct z_candidate *cand;
    5162     90010929 :   tree explicit_targs;
    5163     90010929 :   int template_only;
    5164              : 
    5165     90010929 :   auto_cond_timevar tv (TV_OVERLOAD);
    5166              : 
    5167     90010929 :   explicit_targs = NULL_TREE;
    5168     90010929 :   template_only = 0;
    5169              : 
    5170     90010929 :   *candidates = NULL;
    5171     90010929 :   *any_viable_p = true;
    5172              : 
    5173              :   /* Check FN.  */
    5174     90010929 :   gcc_assert (OVL_P (fn) || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
    5175              : 
    5176     90010929 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5177              :     {
    5178     30709780 :       explicit_targs = TREE_OPERAND (fn, 1);
    5179     30709780 :       fn = TREE_OPERAND (fn, 0);
    5180     30709780 :       template_only = 1;
    5181              :     }
    5182              : 
    5183              :   /* Add the various candidate functions.  */
    5184     90010929 :   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     89997411 :   *candidates = splice_viable (*candidates, false, any_viable_p);
    5192     89997411 :   if (*any_viable_p)
    5193              :     {
    5194     89816909 :       if (complain & tf_any_viable)
    5195              :         cand = *candidates;
    5196              :       else
    5197     89816729 :         cand = tourney (*candidates, complain);
    5198              :     }
    5199              :   else
    5200              :     cand = NULL;
    5201              : 
    5202    179994822 :   return cand;
    5203     89997411 : }
    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         2907 : print_error_for_call_failure (tree fn, const vec<tree, va_gc> *args,
    5212              :                               struct z_candidate *candidates)
    5213              : {
    5214         2907 :   tree targs = NULL_TREE;
    5215         2907 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5216              :     {
    5217          513 :       targs = TREE_OPERAND (fn, 1);
    5218          513 :       fn = TREE_OPERAND (fn, 0);
    5219              :     }
    5220         5814 :   tree name = OVL_NAME (fn);
    5221         2907 :   location_t loc = location_of (name);
    5222         2907 :   if (targs)
    5223          513 :     name = lookup_template_function (name, targs);
    5224              : 
    5225         2907 :   auto_diagnostic_group d;
    5226         5814 :   if (!any_strictly_viable (candidates))
    5227         2431 :     error_at (loc, "no matching function for call to %<%D(%A)%>",
    5228              :               name, build_tree_list_vec (args));
    5229              :   else
    5230          476 :     error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous",
    5231              :               name, build_tree_list_vec (args));
    5232         2907 :   if (candidates)
    5233         2907 :     print_z_candidates (loc, candidates);
    5234         2907 : }
    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        29057 : perform_dguide_overload_resolution (tree dguides, const vec<tree, va_gc> *args,
    5242              :                                     tsubst_flags_t complain)
    5243              : {
    5244        29057 :   z_candidate *candidates;
    5245        29057 :   bool any_viable_p;
    5246        29057 :   tree result;
    5247              : 
    5248        58114 :   gcc_assert (deduction_guide_p (OVL_FIRST (dguides)));
    5249              : 
    5250        29057 :   conversion_obstack_sentinel cos;
    5251              : 
    5252        29057 :   z_candidate *cand = perform_overload_resolution (dguides, args, &candidates,
    5253              :                                                    &any_viable_p, complain);
    5254        29057 :   if (!cand)
    5255              :     {
    5256          895 :       if (complain & tf_error)
    5257          192 :         print_error_for_call_failure (dguides, args, candidates);
    5258          895 :       result = error_mark_node;
    5259              :     }
    5260              :   else
    5261        28162 :     result = cand->fn;
    5262              : 
    5263        58114 :   return result;
    5264        29057 : }
    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     88970033 : build_new_function_call (tree fn, vec<tree, va_gc> **args,
    5272              :                          tsubst_flags_t complain)
    5273              : {
    5274     88970033 :   struct z_candidate *candidates, *cand;
    5275     88970033 :   bool any_viable_p;
    5276     88970033 :   tree result;
    5277              : 
    5278     88970033 :   if (args != NULL && *args != NULL)
    5279              :     {
    5280     88970033 :       *args = resolve_args (*args, complain & ~tf_any_viable);
    5281     88970033 :       if (*args == NULL)
    5282          329 :         return error_mark_node;
    5283              :     }
    5284              : 
    5285     88969704 :   if (flag_tm)
    5286         3537 :     tm_malloc_replacement (fn);
    5287              : 
    5288     88969704 :   conversion_obstack_sentinel cos;
    5289              : 
    5290     88969704 :   cand = perform_overload_resolution (fn, *args, &candidates, &any_viable_p,
    5291              :                                       complain);
    5292              : 
    5293     88956186 :   if (!cand)
    5294              :     {
    5295       189715 :       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         3129 :           if (!any_viable_p && candidates && ! candidates->next
    5300         1355 :               && 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         2706 :           print_error_for_call_failure (fn, *args, candidates);
    5310              :         }
    5311       189292 :       result = error_mark_node;
    5312              :     }
    5313     88766471 :   else if (complain & tf_any_viable)
    5314          180 :     return void_node;
    5315              :   else
    5316     88766291 :     result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5317              : 
    5318     88955583 :   if (flag_coroutines
    5319     86892834 :       && result
    5320     86892834 :       && TREE_CODE (result) == CALL_EXPR
    5321    142587259 :       && DECL_BUILT_IN_CLASS (TREE_OPERAND (CALL_EXPR_FN (result), 0))
    5322     53631676 :           == BUILT_IN_NORMAL)
    5323      7479561 :    result = coro_validate_builtin_call (result);
    5324              : 
    5325              :   return result;
    5326     88956186 : }
    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      1012145 : 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      1012145 :   tree original_size = *size;
    5348      1012145 :   tree fns;
    5349      1012145 :   struct z_candidate *candidates;
    5350      1012145 :   struct z_candidate *cand = NULL;
    5351      1012145 :   bool any_viable_p;
    5352              : 
    5353      1012145 :   if (fn)
    5354      1010708 :     *fn = NULL_TREE;
    5355              :   /* Set to (size_t)-1 if the size check fails.  */
    5356      1012145 :   if (size_check != NULL_TREE)
    5357              :     {
    5358        20304 :       tree errval = TYPE_MAX_VALUE (sizetype);
    5359        20304 :       if (cxx_dialect >= cxx11 && flag_exceptions)
    5360        19900 :         errval = throw_bad_array_new_length ();
    5361        20304 :       *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5362              :                            original_size, errval);
    5363              :     }
    5364      1012145 :   vec_safe_insert (*args, 0, *size);
    5365      1012145 :   *args = resolve_args (*args, complain);
    5366      1012145 :   if (*args == NULL)
    5367            0 :     return error_mark_node;
    5368              : 
    5369      1012145 :   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      1012145 :   fns = lookup_qualified_name (global_namespace, fnname);
    5381              : 
    5382      1012145 :   if (align_arg)
    5383              :     {
    5384         9053 :       vec<tree, va_gc>* align_args
    5385         9053 :         = vec_copy_and_insert (*args, align_arg, 1);
    5386         9053 :       cand = perform_overload_resolution (fns, align_args, &candidates,
    5387              :                                           &any_viable_p, tf_none);
    5388         9053 :       if (cand)
    5389         9030 :         *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         9030 :   if (!cand)
    5396      1003115 :     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      1012145 :   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      1012136 :    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      1012136 :    if (fn)
    5446      1010699 :      *fn = cand->fn;
    5447              : 
    5448              :    /* Build the CALL_EXPR.  */
    5449      1012136 :    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      1012136 :    tree call = extract_call_expr (ret);
    5455      1012136 :    if (TREE_CODE (call) == CALL_EXPR)
    5456      1012136 :      CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    5457              : 
    5458              :    return ret;
    5459      1012145 : }
    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     76106259 : keep_unused_object_arg (tree result, tree obj, tree fn)
    5471              : {
    5472     76106259 :   if (result == NULL_TREE
    5473     76106259 :       || result == error_mark_node
    5474     75155646 :       || DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    5475     78561901 :       || !TREE_SIDE_EFFECTS (obj))
    5476              :     return result;
    5477              : 
    5478              :   /* But avoid the implicit lvalue-rvalue conversion when `obj' is
    5479              :      volatile.  */
    5480        83850 :   tree a = obj;
    5481        83850 :   if (TREE_THIS_VOLATILE (a))
    5482        55752 :     a = build_this (a);
    5483        83850 :   if (TREE_SIDE_EFFECTS (a))
    5484        28107 :     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      2178086 : build_op_call (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
    5492              : {
    5493      2178086 :   struct z_candidate *candidates = 0, *cand;
    5494      2178086 :   tree fns, convs, first_mem_arg = NULL_TREE;
    5495      2178086 :   bool any_viable_p;
    5496      2178086 :   tree result = NULL_TREE;
    5497              : 
    5498      2178086 :   auto_cond_timevar tv (TV_OVERLOAD);
    5499              : 
    5500      2178086 :   obj = mark_lvalue_use (obj);
    5501              : 
    5502      2178086 :   if (error_operand_p (obj))
    5503            0 :     return error_mark_node;
    5504              : 
    5505      2178086 :   tree type = TREE_TYPE (obj);
    5506              : 
    5507      2178086 :   obj = prep_operand (obj);
    5508              : 
    5509      2178086 :   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      2178086 :   if (TYPE_BINFO (type))
    5520              :     {
    5521      2178068 :       fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1, complain);
    5522      2178068 :       if (fns == error_mark_node)
    5523              :         return error_mark_node;
    5524              :     }
    5525              :   else
    5526              :     fns = NULL_TREE;
    5527              : 
    5528      2178076 :   if (args != NULL && *args != NULL)
    5529              :     {
    5530      2178076 :       *args = resolve_args (*args, complain);
    5531      2178076 :       if (*args == NULL)
    5532          109 :         return error_mark_node;
    5533              :     }
    5534              : 
    5535      2177967 :   conversion_obstack_sentinel cos;
    5536              : 
    5537      2177967 :   if (fns)
    5538              :     {
    5539      2175089 :       first_mem_arg = obj;
    5540              : 
    5541      2175089 :       add_candidates (BASELINK_FUNCTIONS (fns),
    5542              :                       first_mem_arg, *args, NULL_TREE,
    5543              :                       NULL_TREE, false,
    5544      2175089 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    5545              :                       LOOKUP_NORMAL, &candidates, complain);
    5546              :     }
    5547              : 
    5548      2177967 :   bool any_call_ops = candidates != nullptr;
    5549              : 
    5550      2177967 :   convs = lookup_conversions (type);
    5551              : 
    5552      2326973 :   for (; convs; convs = TREE_CHAIN (convs))
    5553              :     {
    5554       149006 :       tree totype = TREE_TYPE (convs);
    5555              : 
    5556       129496 :       if (TYPE_PTRFN_P (totype)
    5557        19513 :           || TYPE_REFFN_P (totype)
    5558       168475 :           || (TYPE_REF_P (totype)
    5559          989 :               && TYPE_PTRFN_P (TREE_TYPE (totype))))
    5560       259390 :         for (tree fn : ovl_range (TREE_VALUE (convs)))
    5561              :           {
    5562       129695 :             if (DECL_NONCONVERTING_P (fn))
    5563            3 :               continue;
    5564              : 
    5565       129692 :             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        34463 :                 if (any_call_ops)
    5571        34451 :                   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        95229 :               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      2177967 :   candidates = splice_viable (candidates, true, &any_viable_p);
    5588      2177967 :   if (!any_viable_p)
    5589              :     {
    5590        27081 :       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        27081 :       result = error_mark_node;
    5598              :     }
    5599              :   else
    5600              :     {
    5601      2150886 :       cand = tourney (candidates, complain);
    5602      2150886 :       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      2150869 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    5614      2150810 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    5615      4301679 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, CALL_EXPR))
    5616              :         {
    5617      2150810 :           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      2150810 :           result = keep_unused_object_arg (result, obj, cand->fn);
    5622              :         }
    5623              :       else
    5624              :         {
    5625           59 :           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           59 :               gcc_checking_assert (TYPE_P (cand->fn));
    5631           59 :               obj = convert_like (cand->convs[0], obj, complain);
    5632              :             }
    5633           59 :           obj = convert_from_reference (obj);
    5634           59 :           result = cp_build_function_call_vec (obj, args, complain);
    5635              :         }
    5636              :     }
    5637              : 
    5638      2177967 :   return result;
    5639      2178086 : }
    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         1465 : concat_op_error_string (bool match, const char *errmsg, const char *suffix)
    5647              : {
    5648         1465 :   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         1444 : op_error_string (const char *errmsg, int ntypes, bool match)
    5660              : {
    5661         1444 :   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         1465 : 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         1465 :   bool assop = code == MODIFY_EXPR;
    5687         1465 :   const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
    5688              : 
    5689         1465 :   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         1446 :     default:
    5745         1446 :       if (arg2)
    5746         1348 :         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         2654 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%E %s %E%>"),
    5759              :                                           2, match),
    5760              :                     opname, arg1, opname, arg2,
    5761         1327 :                     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         1465 : }
    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       516118 : conditional_conversion (tree e1, tree e2, tsubst_flags_t complain)
    5779              : {
    5780       516118 :   tree t1 = non_reference (TREE_TYPE (e1));
    5781       516118 :   tree t2 = non_reference (TREE_TYPE (e2));
    5782       516118 :   conversion *conv;
    5783       516118 :   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       516118 :   if (glvalue_p (e2))
    5796              :     {
    5797       488330 :       tree rtype = cp_build_reference_type (t2, !lvalue_p (e2));
    5798       488330 :       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       488330 :       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       412125 :   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       184059 :   if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    5826       369115 :       && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
    5827              :     {
    5828        55241 :       if (good_base && at_least_as_qualified_p (t2, t1))
    5829              :         {
    5830        27517 :           conv = build_identity_conv (t1, e1);
    5831        27517 :           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        27511 :             conv = build_conv (ck_rvalue, t2, conv);
    5836        27517 :           return conv;
    5837              :         }
    5838              :       else
    5839        27724 :         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       254118 :     return implicit_conversion (t2, t1, e1, /*c_cast_p=*/false,
    5848       254118 :                                 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      7635439 : build_conditional_expr (const op_location_t &loc,
    5856              :                         tree arg1, tree arg2, tree arg3,
    5857              :                         tsubst_flags_t complain)
    5858              : {
    5859      7635439 :   tree arg2_type;
    5860      7635439 :   tree arg3_type;
    5861      7635439 :   tree result = NULL_TREE;
    5862      7635439 :   tree result_type = NULL_TREE;
    5863      7635439 :   tree semantic_result_type = NULL_TREE;
    5864      7635439 :   bool is_glvalue = true;
    5865      7635439 :   struct z_candidate *candidates = 0;
    5866      7635439 :   struct z_candidate *cand;
    5867      7635439 :   tree orig_arg2, orig_arg3;
    5868              : 
    5869      7635439 :   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      7635439 :   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      7635439 :   if (error_operand_p (arg1)
    5906      7635361 :       || error_operand_p (arg2)
    5907     15270751 :       || error_operand_p (arg3))
    5908          169 :     return error_mark_node;
    5909              : 
    5910      7635270 :   conversion_obstack_sentinel cos;
    5911              : 
    5912      7635270 :   orig_arg2 = arg2;
    5913      7635270 :   orig_arg3 = arg3;
    5914              : 
    5915      7635270 :   if (gnu_vector_type_p (TREE_TYPE (arg1))
    5916      7635270 :       && (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      7633870 :   arg1 = perform_implicit_conversion_flags (boolean_type_node, arg1, complain,
    6056              :                                             LOOKUP_NORMAL);
    6057      7633870 :   if (error_operand_p (arg1))
    6058           25 :     return error_mark_node;
    6059              : 
    6060      7633845 :   arg2_type = unlowered_expr_type (arg2);
    6061      7633845 :   arg3_type = unlowered_expr_type (arg3);
    6062              : 
    6063      7633845 :   if ((TREE_CODE (arg2) == EXCESS_PRECISION_EXPR
    6064      7633827 :        || 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      7633845 :   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       114905 :       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       114905 :       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       114905 :       if (TREE_CODE (arg2) == THROW_EXPR
    6139           81 :           && TREE_CODE (arg3) != THROW_EXPR)
    6140              :         {
    6141           69 :           result_type = arg3_type;
    6142           69 :           is_glvalue = glvalue_p (arg3);
    6143              :         }
    6144       114836 :       else if (TREE_CODE (arg2) != THROW_EXPR
    6145       114824 :                && TREE_CODE (arg3) == THROW_EXPR)
    6146              :         {
    6147          171 :           result_type = arg2_type;
    6148          171 :           is_glvalue = glvalue_p (arg2);
    6149              :         }
    6150       114665 :       else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
    6151              :         {
    6152       114636 :           result_type = void_type_node;
    6153       114636 :           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       114876 :       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      7518940 :   else if (!same_type_p (arg2_type, arg3_type)
    6183      7518940 :             && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)
    6184      1477984 :                 || (same_type_ignoring_top_level_qualifiers_p (arg2_type,
    6185              :                                                                arg3_type)
    6186       425259 :                     && glvalue_p (arg2) && glvalue_p (arg3)
    6187       102836 :                     && lvalue_p (arg2) == lvalue_p (arg3))))
    6188              :     {
    6189       258059 :       conversion *conv2;
    6190       258059 :       conversion *conv3;
    6191       258059 :       bool converted = false;
    6192              : 
    6193       258059 :       conv2 = conditional_conversion (arg2, arg3, complain);
    6194       258059 :       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       258059 :       if ((conv2 && !conv2->bad_p
    6206        61827 :            && conv3 && !conv3->bad_p)
    6207        61810 :           || (conv2 && conv2->kind == ck_ambig)
    6208       257946 :           || (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       257946 :       else if (conv2 && !conv2->bad_p)
    6225              :         {
    6226        61714 :           arg2 = convert_like (conv2, arg2, complain);
    6227        61714 :           arg2 = convert_from_reference (arg2);
    6228        61714 :           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        61714 :           if (error_operand_p (arg2))
    6235            4 :             result = error_mark_node;
    6236            4 :           converted = true;
    6237              :         }
    6238       196232 :       else if (conv3 && !conv3->bad_p)
    6239              :         {
    6240       195543 :           arg3 = convert_like (conv3, arg3, complain);
    6241       195543 :           arg3 = convert_from_reference (arg3);
    6242       195543 :           arg3_type = TREE_TYPE (arg3);
    6243       195543 :           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       257942 :       if (converted
    6267       257253 :           && CLASS_TYPE_P (arg2_type)
    6268       287539 :           && 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     11207393 :   if (((lvalue_p (arg2) && lvalue_p (arg3))
    6281      4429467 :        || (xvalue_p (arg2) && xvalue_p (arg3)))
    6282     10655345 :       && same_type_p (arg2_type, arg3_type))
    6283              :     {
    6284      3046177 :       result_type = arg2_type;
    6285      3046177 :       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      4472646 :   is_glvalue = false;
    6296      4472646 :   if (!same_type_p (arg2_type, arg3_type)
    6297      4472646 :       && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
    6298              :     {
    6299          689 :       releasing_vec args;
    6300          689 :       conversion *conv;
    6301          689 :       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          689 :       args->quick_push (arg2);
    6307          689 :       args->quick_push (arg3);
    6308          689 :       args->quick_push (arg1);
    6309          689 :       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          689 :       candidates = splice_viable (candidates, false, &any_viable_p);
    6321          689 :       if (!any_viable_p)
    6322              :         {
    6323          573 :           if (complain & tf_error)
    6324           22 :             error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6325              :                       arg2_type, arg3_type);
    6326          573 :           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          689 :     }
    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      4472073 :   arg2 = force_rvalue (arg2, complain);
    6367      4472073 :   if (!CLASS_TYPE_P (arg2_type))
    6368      4366262 :     arg2_type = TREE_TYPE (arg2);
    6369              : 
    6370      4472073 :   arg3 = force_rvalue (arg3, complain);
    6371      4472073 :   if (!CLASS_TYPE_P (arg3_type))
    6372      4366262 :     arg3_type = TREE_TYPE (arg3);
    6373              : 
    6374      4472073 :   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      4472025 :   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        22970 :   else if ((ARITHMETIC_TYPE_P (arg2_type)
    6391        22260 :             || UNSCOPED_ENUM_P (arg2_type))
    6392       965585 :            && (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       942501 :       tree eptype2 = arg2_type;
    6400       942501 :       tree eptype3 = arg3_type;
    6401       942501 :       tree eptype;
    6402          710 :       if (ANY_INTEGRAL_TYPE_P (arg2_type)
    6403       942504 :           && (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       942496 :                && (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       942501 :       result_type = type_after_usual_arithmetic_conversions (eptype2,
    6419              :                                                              eptype3);
    6420       942501 :       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       942501 :       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       942501 :       if (complain & tf_warning)
    6462       891748 :         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       942501 :       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       942467 :       else if ((((complain & (cxx_dialect >= cxx26
    6490       942467 :                               ? tf_warning_or_error : tf_warning))
    6491       894572 :                  && warn_deprecated_enum_float_conv)
    6492        63127 :                 || (cxx_dialect >= cxx26
    6493         1397 :                     && (complain & tf_warning_or_error) == 0))
    6494       880638 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6495           36 :                     && SCALAR_FLOAT_TYPE_P (arg3_type))
    6496       880627 :                    || (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       932743 :       else if ((extra_warnings || warn_enum_conversion)
    6521       942453 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6522           15 :                     && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
    6523         9698 :                    || (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       942498 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6538       942498 :       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        22276 :   else if ((null_ptr_cst_p (arg2)
    6557          163 :             && TYPE_PTR_OR_PTRMEM_P (arg3_type))
    6558        22113 :            || (null_ptr_cst_p (arg3)
    6559        21168 :                && 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        22348 :            || (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
    6563              :     {
    6564        22222 :       result_type = composite_pointer_type (loc,
    6565              :                                             arg2_type, arg3_type, arg2,
    6566              :                                             arg3, CPO_CONDITIONAL_EXPR,
    6567              :                                             complain);
    6568        22222 :       if (result_type == error_mark_node)
    6569              :         return error_mark_node;
    6570        22196 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6571        22196 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6572              :     }
    6573              : 
    6574      4471942 :   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      4471942 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6583              :     return error_mark_node;
    6584              : 
    6585      4471939 :  valid_operands:
    6586      7632992 :   if (processing_template_decl && is_glvalue)
    6587              :     {
    6588              :       /* Let lvalue_kind know this was a glvalue.  */
    6589       109931 :       tree arg = (result_type == arg2_type ? arg2 : arg3);
    6590       109931 :       result_type = cp_build_reference_type (result_type, xvalue_p (arg));
    6591              :     }
    6592              : 
    6593      7632992 :   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      7632992 :   if (warn_duplicated_branches
    6598          153 :       && (complain & tf_warning)
    6599      7633145 :       && (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      7632992 :   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      4586755 :       if (CLASS_TYPE_P (TREE_TYPE (result)))
    6614              :         {
    6615       105848 :           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       105848 :           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      4586755 :       result = rvalue (result);
    6624      4586755 :       if (semantic_result_type)
    6625           73 :         result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6626              :                          result);
    6627              :     }
    6628              :   else
    6629              :     {
    6630      3046237 :       result = force_paren_expr (result);
    6631      3046237 :       gcc_assert (semantic_result_type == NULL_TREE);
    6632              :     }
    6633              : 
    6634              :   return result;
    6635      7635439 : }
    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    620858274 : prep_operand (tree operand)
    6643              : {
    6644    620858274 :   if (operand)
    6645              :     {
    6646    716847914 :       if (CLASS_TYPE_P (TREE_TYPE (operand))
    6647    385167012 :           && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
    6648              :         /* Make sure the template type is instantiated now.  */
    6649     11469533 :         instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (operand)));
    6650              :     }
    6651              : 
    6652    620858274 :   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    220695265 : perfect_conversion_p (conversion *conv)
    6663              : {
    6664    220695265 :   if (CONVERSION_RANK (conv) != cr_identity)
    6665              :     return false;
    6666    157819812 :   if (conv->kind == ck_ref_bind)
    6667              :     {
    6668     41328585 :       if (!conv->rvaluedness_matches_p)
    6669              :         return false;
    6670     28676679 :       if (!same_type_p (TREE_TYPE (conv->type),
    6671              :                         next_conversion (conv)->type))
    6672              :         return false;
    6673              :     }
    6674    141308662 :   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    527902061 : perfect_candidate_p (z_candidate *cand)
    6688              : {
    6689    527902061 :   if (cand->viable < 1)
    6690              :     return false;
    6691              :   /* CWG1402 makes an implicitly deleted move op worse than other
    6692              :      candidates.  */
    6693    203848440 :   if (DECL_DELETED_FN (cand->fn) && DECL_DEFAULTED_FN (cand->fn)
    6694    202901430 :       && move_fn_p (cand->fn))
    6695              :     return false;
    6696    201313604 :   int len = cand->num_convs;
    6697    342622219 :   for (int i = 0; i < len; ++i)
    6698    220695265 :     if (!perfect_conversion_p (cand->convs[i]))
    6699              :       return false;
    6700    121926954 :   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     21126570 : missing_conversion_p (const z_candidate *cand)
    6710              : {
    6711     38262807 :   for (unsigned i = 0; i < cand->num_convs; ++i)
    6712              :     {
    6713     25385157 :       conversion *conv = cand->convs[i];
    6714     25385157 :       if (!conv)
    6715              :         return true;
    6716     24496940 :       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      7360703 :           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    297070762 : 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    297070762 :   tree ctype;
    6747    297070762 :   const vec<tree, va_gc> *non_static_args;
    6748    297070762 :   bool check_list_ctor = false;
    6749    297070762 :   bool check_converting = false;
    6750    297070762 :   unification_kind_t strict;
    6751    297070762 :   tree ne_context = NULL_TREE;
    6752    297070762 :   tree ne_fns = NULL_TREE;
    6753              : 
    6754    297070762 :   if (!fns)
    6755      3462240 :     return;
    6756              : 
    6757              :   /* Precalculate special handling of constructors and conversion ops.  */
    6758    293608522 :   tree fn = OVL_FIRST (fns);
    6759    293608522 :   if (DECL_CONV_FN_P (fn))
    6760              :     {
    6761     17741293 :       check_list_ctor = false;
    6762     17741293 :       check_converting = (flags & LOOKUP_ONLYCONVERTING) != 0;
    6763     17741293 :       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         1392 :         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     17741293 :       ctype = TYPE_MAIN_VARIANT (TREE_TYPE (first_arg));
    6774              :     }
    6775              :   else
    6776              :     {
    6777    551734458 :       if (DECL_CONSTRUCTOR_P (fn))
    6778              :         {
    6779     77867996 :           check_list_ctor = (flags & LOOKUP_LIST_ONLY) != 0;
    6780              :           /* For list-initialization we consider explicit constructors
    6781              :              and complain if one is chosen.  */
    6782     77867996 :           check_converting
    6783     77867996 :             = ((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    6784              :                == LOOKUP_ONLYCONVERTING);
    6785              :         }
    6786    275867229 :       strict = DEDUCE_CALL;
    6787    434589775 :       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    293608522 :   if ((flags & (LOOKUP_REWRITTEN | LOOKUP_REVERSED))
    6793    293608522 :       && DECL_OVERLOADED_OPERATOR_IS (fn, EQ_EXPR))
    6794              :     {
    6795      6763981 :       tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6796      6763981 :       if (DECL_CLASS_SCOPE_P (fn))
    6797              :         {
    6798       177799 :           ne_context = DECL_CONTEXT (fn);
    6799       177799 :           ne_fns = lookup_fnfields (TREE_TYPE ((*args)[0]), ne_name,
    6800              :                                     1, tf_none);
    6801       177799 :           if (ne_fns == error_mark_node || ne_fns == NULL_TREE)
    6802              :             ne_fns = NULL_TREE;
    6803              :           else
    6804        17323 :             ne_fns = BASELINK_FUNCTIONS (ne_fns);
    6805              :         }
    6806              :       else
    6807              :         {
    6808      6586182 :           ne_context = decl_namespace_context (fn);
    6809      6586182 :           ne_fns = lookup_qualified_name (ne_context, ne_name,
    6810              :                                           LOOK_want::NORMAL,
    6811              :                                           /*complain*/false);
    6812      6586182 :           if (ne_fns == error_mark_node
    6813      2086817 :               || !is_overloaded_fn (ne_fns))
    6814      4499365 :             ne_fns = NULL_TREE;
    6815              :         }
    6816              :     }
    6817              : 
    6818    293608522 :   if (first_arg)
    6819              :     non_static_args = args;
    6820              :   else
    6821              :     /* Delay creating the implicit this parameter until it is needed.  */
    6822    125647073 :     non_static_args = NULL;
    6823              : 
    6824    293608522 :   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    293608522 :   bool seen_perfect = false;
    6830    293608522 :   enum { templates, non_templates, either } which = either;
    6831    293608522 :   if (template_only)
    6832              :     which = templates;
    6833              :   else /*if (flags & LOOKUP_DEFAULTED)*/
    6834    260356444 :     which = non_templates;
    6835              : 
    6836              :   /* Template candidates that we'll potentially ignore if the
    6837              :      perfect candidate optimization succeeds.  */
    6838    293608522 :   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    293608522 :   z_candidate *bad_cands = nullptr;
    6851    293608522 :   bool shortcut_bad_convs = true;
    6852              : 
    6853    432152634 :  again:
    6854   2617654426 :   for (tree fn : lkp_range (fns))
    6855              :     {
    6856   2185515343 :       if (which == templates && TREE_CODE (fn) != TEMPLATE_DECL)
    6857              :         {
    6858    316440676 :           if (template_only)
    6859       822259 :             add_ignored_candidate (candidates, fn);
    6860    316440676 :           continue;
    6861              :         }
    6862   1869074667 :       if (which == non_templates && TREE_CODE (fn) == TEMPLATE_DECL)
    6863              :         {
    6864    658377519 :           add_ignored_candidate (&ignored_template_cands, fn);
    6865    658377519 :           continue;
    6866              :         }
    6867    231136495 :       if ((check_converting && DECL_NONCONVERTING_P (fn))
    6868   1417114885 :           || (check_list_ctor && !is_list_ctor (fn)))
    6869              :         {
    6870     25947130 :           add_ignored_candidate (candidates, fn);
    6871     25947130 :           continue;
    6872              :         }
    6873              : 
    6874   1184750018 :       tree fn_first_arg = NULL_TREE;
    6875   1184750018 :       const vec<tree, va_gc> *fn_args = args;
    6876              : 
    6877   1184750018 :       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    419728855 :           if (first_arg == NULL_TREE)
    6883              :             {
    6884      8502390 :               unsigned int ix;
    6885      8502390 :               tree arg;
    6886      8502390 :               vec<tree, va_gc> *tempvec;
    6887      8502390 :               vec_alloc (tempvec, args->length () - 1);
    6888     22904051 :               for (ix = 1; args->iterate (ix, &arg); ++ix)
    6889      5899271 :                 tempvec->quick_push (arg);
    6890      8502390 :               non_static_args = tempvec;
    6891      8502390 :               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    765021163 :       else if (vec_safe_length (args) == 2 && (flags & LOOKUP_REVERSED))
    6900              :         {
    6901    220119304 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6902    220119304 :           if (same_type_p (TREE_VALUE (parmlist),
    6903              :                            TREE_VALUE (TREE_CHAIN (parmlist))))
    6904    104992744 :             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   1079757274 :       if (ne_context)
    6910              :         {
    6911    150767133 :           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    150585366 :               tree fn_ns = decl_namespace_context (fn);
    6917    150585366 :               if (fn_ns != ne_context)
    6918              :                 {
    6919      8788839 :                   ne_context = fn_ns;
    6920      8788839 :                   tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6921      8788839 :                   ne_fns = lookup_qualified_name (ne_context, ne_name,
    6922              :                                                   LOOK_want::NORMAL,
    6923              :                                                   /*complain*/false);
    6924      8788839 :                   if (ne_fns == error_mark_node
    6925      5444183 :                       || !is_overloaded_fn (ne_fns))
    6926      3344656 :                     ne_fns = NULL_TREE;
    6927              :                 }
    6928              :             }
    6929    150767133 :           bool found = false;
    6930   1638233403 :           for (lkp_iterator ne (ne_fns); !found && ne; ++ne)
    6931   1523608328 :             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   1523608328 :             else if (fns_correspond (fn, *ne))
    6938              :               {
    6939              :                 found = true;
    6940              :                 break;
    6941              :               }
    6942    150767133 :           if (found)
    6943     36142058 :             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   1043615216 :       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   1043615216 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    6957    515713155 :         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    527902061 :           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    527902061 :           if (perfect_candidate_p (*candidates))
    6984   1043601665 :             seen_perfect = true;
    6985              :         }
    6986              : 
    6987   1043601665 :       z_candidate *cand = *candidates;
    6988   1043601665 :       if (cand->viable == 1)
    6989    277429710 :         seen_strictly_viable = true;
    6990              : 
    6991   1043601665 :       if (cand->viable == -1
    6992     21127063 :           && shortcut_bad_convs
    6993   1064728235 :           && (missing_conversion_p (cand)
    6994     12877650 :               || 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      8274458 :           if (complain & (tf_error | tf_conv))
    7002              :             {
    7003      7960070 :               *candidates = cand->next;
    7004      7960070 :               cand->next = bad_cands;
    7005      7960070 :               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       314388 :             cand->viable = 0;
    7014              :         }
    7015              :     }
    7016    432139083 :   if (which == non_templates && !seen_perfect)
    7017              :     {
    7018    138434455 :       which = templates;
    7019    138434455 :       ignored_template_cands = nullptr;
    7020    138434455 :       goto again;
    7021              :     }
    7022    293704628 :   else if (which == templates
    7023    293704628 :            && !seen_strictly_viable
    7024              :            && shortcut_bad_convs
    7025     57477624 :            && 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       243376 :       which = either;
    7031              :       fns = NULL_TREE;
    7032       243376 :       for (z_candidate *cand = bad_cands; cand; cand = cand->next)
    7033              :         {
    7034       133719 :           tree fn = cand->fn;
    7035       133719 :           if (tree ti = cand->template_decl)
    7036          117 :             fn = TI_TEMPLATE (ti);
    7037       133719 :           fns = ovl_make (fn, fns);
    7038              :         }
    7039       109657 :       shortcut_bad_convs = false;
    7040       109657 :       bad_cands = nullptr;
    7041       109657 :       goto again;
    7042              :     }
    7043              : 
    7044    293594971 :   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    455026173 :       for (z_candidate *omitted_cands : { ignored_template_cands, bad_cands })
    7049              :         {
    7050    303350782 :           z_candidate **omitted_cands_tail = &omitted_cands;
    7051    348760914 :           while (*omitted_cands_tail)
    7052     45410132 :             omitted_cands_tail = &(*omitted_cands_tail)->next;
    7053    303350782 :           *omitted_cands_tail = *candidates;
    7054    303350782 :           *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     16865583 : op_is_ordered (tree_code code)
    7064              : {
    7065     16865179 :   switch (code)
    7066              :     {
    7067              :       // 5. b @= a
    7068      3648324 :     case MODIFY_EXPR:
    7069      3648324 :       return (flag_strong_eval_order > 1 ? -1 : 0);
    7070              : 
    7071              :       // 6. a[b]
    7072       504403 :     case ARRAY_REF:
    7073       503999 :       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        57615 :     case MEMBER_REF:
    7081              :       // 7. a << b
    7082        57615 :     case LSHIFT_EXPR:
    7083              :       // 8. a >> b
    7084        57615 :     case RSHIFT_EXPR:
    7085              :       // a && b
    7086              :       // Predates P0145R3.
    7087        57615 :     case TRUTH_ANDIF_EXPR:
    7088              :       // a || b
    7089              :       // Predates P0145R3.
    7090        57615 :     case TRUTH_ORIF_EXPR:
    7091              :       // a , b
    7092              :       // Predates P0145R3.
    7093        57615 :     case COMPOUND_EXPR:
    7094        57615 :       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     34790801 : 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     34790801 :   z_candidate *start_candidates = *candidates;
    7119     34790801 :   bool ismodop = code2 != ERROR_MARK;
    7120     34790801 :   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     34790801 :   bool rewritten = (flags & LOOKUP_REWRITTEN);
    7127     34790801 :   if (rewritten && code != EQ_EXPR && code != SPACESHIP_EXPR)
    7128      1093701 :     flags &= ~LOOKUP_REWRITTEN;
    7129              : 
    7130     31866666 :   bool memonly = false;
    7131     31866666 :   switch (code)
    7132              :     {
    7133              :       /* =, ->, [], () must be non-static member functions.  */
    7134      6267153 :     case MODIFY_EXPR:
    7135      6267153 :       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     30595994 :       tree fns;
    7152     30595994 :       if (!lookups)
    7153     21817446 :         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      8778548 :       else if (tree found = purpose_member (fnname, lookups))
    7157      1671880 :         fns = TREE_VALUE (found);
    7158              :       else
    7159              :         fns = NULL_TREE;
    7160     30595994 :       fns = lookup_arg_dependent (fnname, fns, arglist);
    7161     30595994 :       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     34790768 :   tree arg1_type = TREE_TYPE ((*arglist)[0]);
    7168     34790768 :   unsigned nargs = arglist->length () > 1 ? 2 : 1;
    7169     29765762 :   tree arg2_type = nargs > 1 ? TREE_TYPE ((*arglist)[1]) : NULL_TREE;
    7170     34790768 :   if (CLASS_TYPE_P (arg1_type))
    7171              :     {
    7172     20962136 :       tree fns = lookup_fnfields (arg1_type, fnname, 1, complain);
    7173     20962136 :       if (fns == error_mark_node)
    7174              :         return error_mark_node;
    7175     20962124 :       if (fns)
    7176              :         {
    7177      9008695 :           if (code == ARRAY_REF)
    7178              :             {
    7179       506305 :               vec<tree,va_gc> *restlist = make_tree_vector ();
    7180      1012610 :               for (unsigned i = 1; i < nargs; ++i)
    7181       506305 :                 vec_safe_push (restlist, (*arglist)[i]);
    7182       506305 :               z_candidate *save_cand = *candidates;
    7183      1012610 :               add_candidates (BASELINK_FUNCTIONS (fns),
    7184       506305 :                               (*arglist)[0], restlist, NULL_TREE,
    7185              :                               NULL_TREE, false,
    7186       506305 :                               BASELINK_BINFO (fns),
    7187       506305 :                               BASELINK_ACCESS_BINFO (fns),
    7188              :                               flags, candidates, complain);
    7189              :               /* Release the vec if we didn't add a candidate that uses it.  */
    7190       506901 :               for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7191       506901 :                 if (c->args == restlist)
    7192              :                   {
    7193       506305 :                     restlist = NULL;
    7194       506305 :                     break;
    7195              :                   }
    7196       506305 :               release_tree_vector (restlist);
    7197              :             }
    7198              :           else
    7199      8502390 :             add_candidates (BASELINK_FUNCTIONS (fns),
    7200              :                             NULL_TREE, arglist, NULL_TREE,
    7201              :                             NULL_TREE, false,
    7202      8502390 :                             BASELINK_BINFO (fns),
    7203      8502390 :                             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     13828632 :   else if (! arg2_type || ! CLASS_TYPE_P (arg2_type))
    7214              :     {
    7215              :       struct z_candidate **candp, **next;
    7216              : 
    7217    226232218 :       for (candp = candidates; *candp != start_candidates; candp = next)
    7218              :         {
    7219    212961489 :           unsigned i;
    7220    212961489 :           z_candidate *cand = *candp;
    7221    212961489 :           next = &cand->next;
    7222              : 
    7223    212961489 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    7224              : 
    7225    628193052 :           for (i = 0; i < nargs; ++i)
    7226              :             {
    7227    420187614 :               tree parmtype = TREE_VALUE (parmlist);
    7228    420187614 :               tree argtype = unlowered_expr_type ((*arglist)[i]);
    7229              : 
    7230    420187614 :               if (TYPE_REF_P (parmtype))
    7231    332113131 :                 parmtype = TREE_TYPE (parmtype);
    7232    420187614 :               if (TREE_CODE (argtype) == ENUMERAL_TYPE
    7233    820300848 :                   && (same_type_ignoring_top_level_qualifiers_p
    7234    400113234 :                       (argtype, parmtype)))
    7235              :                 break;
    7236              : 
    7237    415231563 :               parmlist = TREE_CHAIN (parmlist);
    7238              :             }
    7239              : 
    7240              :           /* No argument has an appropriate type, so remove this
    7241              :              candidate function from the list.  */
    7242    212961489 :           if (i == nargs)
    7243              :             {
    7244    208005438 :               *candp = cand->next;
    7245    208005438 :               next = candp;
    7246              :             }
    7247              :         }
    7248              :     }
    7249              : 
    7250     34790756 :   if (!rewritten)
    7251              :     {
    7252              :       /* The standard says to rewrite built-in candidates, too,
    7253              :          but there's no point.  */
    7254     24153513 :       add_builtin_candidates (candidates, code, code2, fnname, arglist,
    7255              :                               flags, complain);
    7256              : 
    7257              :       /* Maybe add C++20 rewritten comparison candidates.  */
    7258     24153513 :       tree_code rewrite_code = ERROR_MARK;
    7259     24153513 :       if (cxx_dialect >= cxx20
    7260     23855367 :           && nargs == 2
    7261     43105437 :           && (OVERLOAD_TYPE_P (arg1_type) || OVERLOAD_TYPE_P (arg2_type)))
    7262     18944304 :         switch (code)
    7263              :           {
    7264      1540841 :           case LT_EXPR:
    7265      1540841 :           case LE_EXPR:
    7266      1540841 :           case GT_EXPR:
    7267      1540841 :           case GE_EXPR:
    7268      1540841 :           case SPACESHIP_EXPR:
    7269      1540841 :             rewrite_code = SPACESHIP_EXPR;
    7270      1540841 :             break;
    7271              : 
    7272              :           case NE_EXPR:
    7273              :           case EQ_EXPR:
    7274              :             rewrite_code = EQ_EXPR;
    7275              :             break;
    7276              : 
    7277              :           default:;
    7278              :           }
    7279              : 
    7280      1540841 :       if (rewrite_code)
    7281              :         {
    7282      6295098 :           tree r;
    7283      6295098 :           flags |= LOOKUP_REWRITTEN;
    7284      6295098 :           if (rewrite_code != code)
    7285              :             {
    7286              :               /* Add rewritten candidates in same order.  */
    7287      3248166 :               r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7288              :                                            arglist, lookups, flags, complain);
    7289      3248166 :               if (r == error_mark_node)
    7290              :                 return error_mark_node;
    7291              :             }
    7292              : 
    7293      6295092 :           z_candidate *save_cand = *candidates;
    7294              : 
    7295              :           /* Add rewritten candidates in reverse order.  */
    7296      6295092 :           flags |= LOOKUP_REVERSED;
    7297      6295092 :           vec<tree,va_gc> *revlist = make_tree_vector ();
    7298      6295092 :           revlist->quick_push ((*arglist)[1]);
    7299      6295092 :           revlist->quick_push ((*arglist)[0]);
    7300      6295092 :           r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7301              :                                        revlist, lookups, flags, complain);
    7302      6295092 :           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      6448552 :           for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7307      3229464 :             if (c->args == revlist)
    7308              :               {
    7309              :                 revlist = NULL;
    7310              :                 break;
    7311              :               }
    7312      6295092 :           release_tree_vector (revlist);
    7313              :         }
    7314              :     }
    7315              : 
    7316              :   return NULL_TREE;
    7317              : }
    7318              : 
    7319              : tree
    7320    206236269 : 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    206236269 :   struct z_candidate *candidates = 0, *cand;
    7325    206236269 :   releasing_vec arglist;
    7326    206236269 :   tree result = NULL_TREE;
    7327    206236269 :   bool result_valid_p = false;
    7328    206236269 :   enum tree_code code2 = ERROR_MARK;
    7329    206236269 :   enum tree_code code_orig_arg1 = ERROR_MARK;
    7330    206236269 :   enum tree_code code_orig_arg2 = ERROR_MARK;
    7331    206236269 :   bool strict_p;
    7332    206236269 :   bool any_viable_p;
    7333              : 
    7334    206236269 :   auto_cond_timevar tv (TV_OVERLOAD);
    7335              : 
    7336    206236269 :   if (error_operand_p (arg1)
    7337    206232593 :       || error_operand_p (arg2)
    7338    412462852 :       || error_operand_p (arg3))
    7339         9686 :     return error_mark_node;
    7340              : 
    7341    206226583 :   conversion_obstack_sentinel cos;
    7342              : 
    7343    206226583 :   bool ismodop = code == MODIFY_EXPR;
    7344    206226583 :   if (ismodop)
    7345              :     {
    7346     10612637 :       code2 = TREE_CODE (arg3);
    7347     10612637 :       arg3 = NULL_TREE;
    7348              :     }
    7349              : 
    7350    206226583 :   tree arg1_type = unlowered_expr_type (arg1);
    7351    206226583 :   tree arg2_type = arg2 ? unlowered_expr_type (arg2) : NULL_TREE;
    7352              : 
    7353    206226583 :   arg1 = prep_operand (arg1);
    7354              : 
    7355    206226583 :   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     16052434 :     case TRUTH_ORIF_EXPR:
    7369     16052434 :     case TRUTH_ANDIF_EXPR:
    7370     16052434 :     case TRUTH_AND_EXPR:
    7371     16052434 :     case TRUTH_OR_EXPR:
    7372              :       /* These are saved for the sake of warn_logical_operator.  */
    7373     16052434 :       code_orig_arg1 = TREE_CODE (arg1);
    7374     16052434 :       code_orig_arg2 = TREE_CODE (arg2);
    7375     16052434 :       break;
    7376     48782091 :     case GT_EXPR:
    7377     48782091 :     case LT_EXPR:
    7378     48782091 :     case GE_EXPR:
    7379     48782091 :     case LE_EXPR:
    7380     48782091 :     case EQ_EXPR:
    7381     48782091 :     case NE_EXPR:
    7382              :       /* These are saved for the sake of maybe_warn_bool_compare.  */
    7383     48782091 :       code_orig_arg1 = TREE_CODE (arg1_type);
    7384     48782091 :       code_orig_arg2 = TREE_CODE (arg2_type);
    7385     48782091 :       break;
    7386              : 
    7387              :     default:
    7388              :       break;
    7389              :     }
    7390              : 
    7391    206226583 :   arg2 = prep_operand (arg2);
    7392    206226583 :   arg3 = prep_operand (arg3);
    7393              : 
    7394    206226583 :   if (code == COND_EXPR)
    7395              :     /* Use build_conditional_expr instead.  */
    7396            0 :     gcc_unreachable ();
    7397    206226583 :   else if (! OVERLOAD_TYPE_P (arg1_type)
    7398    387622104 :            && (! arg2 || ! OVERLOAD_TYPE_P (arg2_type)))
    7399    180979040 :     goto builtin;
    7400              : 
    7401     25247543 :   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    7402              :     {
    7403       338874 :       arg2 = integer_zero_node;
    7404       338874 :       arg2_type = integer_type_node;
    7405              :     }
    7406              : 
    7407     25247543 :   arglist->quick_push (arg1);
    7408     25247543 :   if (arg2 != NULL_TREE)
    7409     20222537 :     arglist->quick_push (arg2);
    7410     25247543 :   if (arg3 != NULL_TREE)
    7411            0 :     arglist->quick_push (arg3);
    7412              : 
    7413     25247543 :   result = add_operator_candidates (&candidates, code, code2, arglist,
    7414              :                                     lookups, flags, complain);
    7415     25247510 :   if (result == error_mark_node)
    7416              :     return error_mark_node;
    7417              : 
    7418     25247498 :   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     23406993 :     default:
    7432     23406993 :       strict_p = false;
    7433     23406993 :       break;
    7434              :     }
    7435              : 
    7436     25247498 :   candidates = splice_viable (candidates, strict_p, &any_viable_p);
    7437     25247498 :   if (!any_viable_p)
    7438              :     {
    7439      1880292 :       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        36763 :         default:
    7483        36763 :           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         1345 :               if (invalid_nonstatic_memfn_p (loc, arg1, tf_error)
    7489         1342 :                     || invalid_nonstatic_memfn_p (loc, arg2, tf_error)
    7490         2681 :                     || 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         1336 :                     auto_diagnostic_group d;
    7497         1336 :                     op_error (loc, code, code2, arg1, arg2, arg3, false);
    7498         1336 :                     print_z_candidates (loc, candidates);
    7499         1336 :                   }
    7500              :             }
    7501        36763 :           result = error_mark_node;
    7502        36763 :           break;
    7503              :         }
    7504              :     }
    7505              :   else
    7506              :     {
    7507     23367206 :       cand = tourney (candidates, complain);
    7508     23367206 :       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     23367020 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    7521              :         {
    7522     19481408 :           if (overload)
    7523              :             {
    7524     14977920 :               if (cand->rewritten ())
    7525              :                 /* build_min_non_dep_op_overload needs to know whether the
    7526              :                    candidate is rewritten/reversed.  */
    7527      2016330 :                 *overload = build_tree_list (build_int_cst (integer_type_node,
    7528      2016330 :                                                             cand->flags),
    7529              :                                              cand->fn);
    7530              :               else
    7531     12961590 :                 *overload = cand->fn;
    7532              :             }
    7533              : 
    7534     19481408 :           if (resolve_args (arglist, complain) == NULL)
    7535            4 :             result = error_mark_node;
    7536              :           else
    7537              :             {
    7538     19481404 :               tsubst_flags_t ocomplain = complain;
    7539     19481404 :               if (cand->rewritten ())
    7540              :                 /* We'll wrap this call in another one.  */
    7541      2016756 :                 ocomplain &= ~tf_decltype;
    7542     19481404 :               if (cand->reversed ())
    7543              :                 {
    7544              :                   /* We swapped these in add_candidate, swap them back now.  */
    7545        16224 :                   std::swap (cand->convs[0], cand->convs[1]);
    7546        16224 :                   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     19481404 :               result = build_over_call (cand, LOOKUP_NORMAL, ocomplain);
    7552              :             }
    7553              : 
    7554     36352475 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7555              :             /* There won't be a CALL_EXPR.  */;
    7556     16867593 :           else if (result && result != error_mark_node)
    7557              :             {
    7558     16865179 :               tree call = extract_call_expr (result);
    7559     16865179 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7560              : 
    7561              :               /* Specify evaluation order as per P0145R2.  */
    7562     16865179 :               CALL_EXPR_ORDERED_ARGS (call) = false;
    7563     16865179 :               switch (op_is_ordered (code))
    7564              :                 {
    7565      3620674 :                 case -1:
    7566      3620674 :                   CALL_EXPR_REVERSE_ARGS (call) = true;
    7567      3620674 :                   break;
    7568              : 
    7569       560577 :                 case 1:
    7570       560577 :                   CALL_EXPR_ORDERED_ARGS (call) = true;
    7571       560577 :                   break;
    7572              : 
    7573              :                 default:
    7574              :                   break;
    7575              :                 }
    7576              :             }
    7577              : 
    7578              :           /* If this was a C++20 rewritten comparison, adjust the result.  */
    7579     19481405 :           if (cand->rewritten ())
    7580              :             {
    7581      2016756 :               switch (code)
    7582              :                 {
    7583         7196 :                 case EQ_EXPR:
    7584         7196 :                   gcc_checking_assert (cand->reversed ());
    7585       921818 :                   gcc_fallthrough ();
    7586       921818 :                 case NE_EXPR:
    7587       921818 :                   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       921816 :                   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       921778 :                   else if (code == NE_EXPR)
    7606              :                     /* !(y == x) or !(x == y)  */
    7607       914603 :                     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      1094648 :                   gcc_fallthrough ();
    7623      1094648 :                 case LT_EXPR:
    7624      1094648 :                 case LE_EXPR:
    7625      1094648 :                 case GT_EXPR:
    7626      1094648 :                 case GE_EXPR:
    7627      1094648 :                   {
    7628      1094648 :                     tree lhs = result;
    7629      1094648 :                     tree rhs = integer_zero_node;
    7630      1094648 :                     if (cand->reversed ())
    7631         1980 :                       std::swap (lhs, rhs);
    7632      1094648 :                     warning_sentinel ws (warn_zero_as_null_pointer_constant);
    7633      1094648 :                     result = build_new_op (loc, code,
    7634              :                                            LOOKUP_NORMAL|LOOKUP_REWRITTEN,
    7635              :                                            lhs, rhs, NULL_TREE, lookups,
    7636              :                                            NULL, complain);
    7637      1094648 :                   }
    7638      1094648 :                   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     19481405 :           if (code == ARRAY_REF)
    7649       506289 :             result = keep_unused_object_arg (result, arg1, cand->fn);
    7650              :         }
    7651              :       else
    7652              :         {
    7653              :           /* Give any warnings we noticed during overload resolution.  */
    7654      3885612 :           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      3885612 :           switch (code)
    7663              :             {
    7664      3039474 :             case GT_EXPR:
    7665      3039474 :             case LT_EXPR:
    7666      3039474 :             case GE_EXPR:
    7667      3039474 :             case LE_EXPR:
    7668      3039474 :             case EQ_EXPR:
    7669      3039474 :             case NE_EXPR:
    7670      3039474 :               if (TREE_CODE (arg1_type) == ENUMERAL_TYPE
    7671      2844045 :                   && TREE_CODE (arg2_type) == ENUMERAL_TYPE
    7672      5808797 :                   && (TYPE_MAIN_VARIANT (arg1_type)
    7673      2769323 :                       != 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      3885612 :           conversion *conv = cand->convs[0];
    7697      3885612 :           if (conv->user_conv_p)
    7698              :             {
    7699        47869 :               conv = strip_standard_conversion (conv);
    7700        47869 :               arg1 = convert_like (conv, arg1, complain);
    7701              :             }
    7702              : 
    7703      3885612 :           if (arg2)
    7704              :             {
    7705      3407278 :               conv = cand->convs[1];
    7706      3407278 :               if (conv->user_conv_p)
    7707              :                 {
    7708         9017 :                   conv = strip_standard_conversion (conv);
    7709         9017 :                   arg2 = convert_like (conv, arg2, complain);
    7710              :                 }
    7711              :             }
    7712              : 
    7713      3885612 :           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     25247282 :   if (result || result_valid_p)
    7726              :     return result;
    7727              : 
    7728      3885611 :  builtin:
    7729    184864651 :   switch (code)
    7730              :     {
    7731      4345915 :     case MODIFY_EXPR:
    7732      4345915 :       return cp_build_modify_expr (loc, arg1, code2, arg2, complain);
    7733              : 
    7734     19266286 :     case INDIRECT_REF:
    7735     19266286 :       return cp_build_indirect_ref (loc, arg1, RO_UNARY_STAR, complain);
    7736              : 
    7737     16051306 :     case TRUTH_ANDIF_EXPR:
    7738     16051306 :     case TRUTH_ORIF_EXPR:
    7739     16051306 :     case TRUTH_AND_EXPR:
    7740     16051306 :     case TRUTH_OR_EXPR:
    7741     16051306 :       if ((complain & tf_warning) && !processing_template_decl)
    7742      7205628 :         warn_logical_operator (loc, code, boolean_type_node,
    7743              :                                code_orig_arg1, arg1,
    7744              :                                code_orig_arg2, arg2);
    7745              :       /* Fall through.  */
    7746     59910152 :     case GT_EXPR:
    7747     59910152 :     case LT_EXPR:
    7748     59910152 :     case GE_EXPR:
    7749     59910152 :     case LE_EXPR:
    7750     59910152 :     case EQ_EXPR:
    7751     59910152 :     case NE_EXPR:
    7752     59910152 :       if ((complain & tf_warning)
    7753     53945083 :           && ((code_orig_arg1 == BOOLEAN_TYPE)
    7754     53945083 :               ^ (code_orig_arg2 == BOOLEAN_TYPE)))
    7755        25655 :         maybe_warn_bool_compare (loc, code, arg1, arg2);
    7756     53945083 :       if (complain & tf_warning && warn_tautological_compare)
    7757       439870 :         warn_tautological_cmp (loc, code, arg1, arg2);
    7758              :       /* Fall through.  */
    7759    126475336 :     case SPACESHIP_EXPR:
    7760    126475336 :     case PLUS_EXPR:
    7761    126475336 :     case MINUS_EXPR:
    7762    126475336 :     case MULT_EXPR:
    7763    126475336 :     case TRUNC_DIV_EXPR:
    7764    126475336 :     case MAX_EXPR:
    7765    126475336 :     case MIN_EXPR:
    7766    126475336 :     case LSHIFT_EXPR:
    7767    126475336 :     case RSHIFT_EXPR:
    7768    126475336 :     case TRUNC_MOD_EXPR:
    7769    126475336 :     case BIT_AND_EXPR:
    7770    126475336 :     case BIT_IOR_EXPR:
    7771    126475336 :     case BIT_XOR_EXPR:
    7772    126475336 :       return cp_build_binary_op (loc, code, arg1, arg2, complain);
    7773              : 
    7774     29597342 :     case UNARY_PLUS_EXPR:
    7775     29597342 :     case NEGATE_EXPR:
    7776     29597342 :     case BIT_NOT_EXPR:
    7777     29597342 :     case TRUTH_NOT_EXPR:
    7778     29597342 :     case PREINCREMENT_EXPR:
    7779     29597342 :     case POSTINCREMENT_EXPR:
    7780     29597342 :     case PREDECREMENT_EXPR:
    7781     29597342 :     case POSTDECREMENT_EXPR:
    7782     29597342 :     case REALPART_EXPR:
    7783     29597342 :     case IMAGPART_EXPR:
    7784     29597342 :     case ABS_EXPR:
    7785     29597342 :     case CO_AWAIT_EXPR:
    7786     29597342 :       return cp_build_unary_op (code, arg1, false, complain);
    7787              : 
    7788      2251182 :     case ARRAY_REF:
    7789      2251182 :       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    206236233 : }
    7808              : 
    7809              : /* Build a new call to operator[].  This may change ARGS.  */
    7810              : 
    7811              : tree
    7812          439 : 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          439 :   struct z_candidate *candidates = 0, *cand;
    7817          439 :   tree fns, first_mem_arg = NULL_TREE;
    7818          439 :   bool any_viable_p;
    7819          439 :   tree result = NULL_TREE;
    7820              : 
    7821          439 :   auto_cond_timevar tv (TV_OVERLOAD);
    7822              : 
    7823          439 :   obj = mark_lvalue_use (obj);
    7824              : 
    7825          439 :   if (error_operand_p (obj))
    7826            0 :     return error_mark_node;
    7827              : 
    7828          439 :   tree type = TREE_TYPE (obj);
    7829              : 
    7830          439 :   obj = prep_operand (obj);
    7831              : 
    7832          439 :   if (TYPE_BINFO (type))
    7833              :     {
    7834          439 :       fns = lookup_fnfields (TYPE_BINFO (type), ovl_op_identifier (ARRAY_REF),
    7835              :                              1, complain);
    7836          439 :       if (fns == error_mark_node)
    7837              :         return error_mark_node;
    7838              :     }
    7839              :   else
    7840              :     fns = NULL_TREE;
    7841              : 
    7842          439 :   if (args != NULL && *args != NULL)
    7843              :     {
    7844          439 :       *args = resolve_args (*args, complain);
    7845          439 :       if (*args == NULL)
    7846            0 :         return error_mark_node;
    7847              :     }
    7848              : 
    7849          439 :   conversion_obstack_sentinel cos;
    7850              : 
    7851          439 :   if (fns)
    7852              :     {
    7853          437 :       first_mem_arg = obj;
    7854              : 
    7855          437 :       add_candidates (BASELINK_FUNCTIONS (fns),
    7856              :                       first_mem_arg, *args, NULL_TREE,
    7857              :                       NULL_TREE, false,
    7858          437 :                       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          439 :   candidates = splice_viable (candidates, true, &any_viable_p);
    7865          439 :   if (!any_viable_p)
    7866              :     {
    7867           35 :       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           35 :       result = error_mark_node;
    7875              :     }
    7876              :   else
    7877              :     {
    7878          404 :       cand = tourney (candidates, complain);
    7879          404 :       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          404 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    7891          404 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    7892          808 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, ARRAY_REF))
    7893              :         {
    7894          404 :           if (overload)
    7895          404 :             *overload = cand->fn;
    7896          404 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    7897          808 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7898              :             /* There won't be a CALL_EXPR.  */;
    7899          404 :           else if (result && result != error_mark_node)
    7900              :             {
    7901          404 :               tree call = extract_call_expr (result);
    7902          404 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7903              : 
    7904              :               /* Specify evaluation order as per P0145R2.  */
    7905          404 :               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          404 :           result = keep_unused_object_arg (result, obj, cand->fn);
    7912              :         }
    7913              :       else
    7914            0 :         gcc_unreachable ();
    7915              :     }
    7916              : 
    7917          439 :   return result;
    7918          439 : }
    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     44419309 : extract_call_expr (tree call)
    7926              : {
    7927     44419738 :   while (TREE_CODE (call) == COMPOUND_EXPR)
    7928          429 :     call = TREE_OPERAND (call, 1);
    7929     44419309 :   if (REFERENCE_REF_P (call))
    7930     10600438 :     call = TREE_OPERAND (call, 0);
    7931     44419309 :   if (TREE_CODE (call) == TARGET_EXPR)
    7932      3248169 :     call = TARGET_EXPR_INITIAL (call);
    7933              : 
    7934     44419309 :   if (TREE_CODE (call) != CALL_EXPR
    7935       839153 :       && TREE_CODE (call) != AGGR_INIT_EXPR
    7936       742774 :       && call != error_mark_node)
    7937       742756 :     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       635581 : second_parm_is_size_t (tree fn)
    7946              : {
    7947       635581 :   tree t = FUNCTION_ARG_CHAIN (fn);
    7948       635581 :   if (!t || !same_type_p (TREE_VALUE (t), size_type_node))
    7949       635566 :     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       326058 : aligned_allocation_fn_p (tree t)
    7961              : {
    7962       326058 :   if (!aligned_new_threshold)
    7963              :     return false;
    7964              : 
    7965       316383 :   tree a = FUNCTION_ARG_CHAIN (t);
    7966       316383 :   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      5443429 : std_destroying_delete_t_p (tree t)
    7973              : {
    7974      5443429 :   return (TYPE_CONTEXT (t) == std_node
    7975      5443429 :           && 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      5443444 : destroying_delete_p (tree t)
    7986              : {
    7987      5443444 :   tree a = TYPE_ARG_TYPES (TREE_TYPE (t));
    7988      5443444 :   if (!a || !TREE_CHAIN (a))
    7989              :     return NULL_TREE;
    7990      5443429 :   tree type = TREE_VALUE (TREE_CHAIN (a));
    7991      5443429 :   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      3721270 : usual_deallocation_fn_p (tree t, dealloc_info *di)
    8007              : {
    8008      3721270 :   if (di) *di = dealloc_info();
    8009              : 
    8010              :   /* A template instance is never a usual deallocation function,
    8011              :      regardless of its signature.  */
    8012      3721270 :   if (TREE_CODE (t) == TEMPLATE_DECL
    8013      3721270 :       || 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      3721258 :   bool global = DECL_NAMESPACE_SCOPE_P (t);
    8022      3721258 :   tree chain = FUNCTION_ARG_CHAIN (t);
    8023      3721258 :   if (chain && destroying_delete_p (t))
    8024              :     {
    8025           78 :       if (di) di->destroying = TREE_VALUE (chain);
    8026           78 :       chain = TREE_CHAIN (chain);
    8027              :     }
    8028      3721258 :   if (chain
    8029      3721255 :       && (!global || flag_sized_deallocation)
    8030      7427414 :       && same_type_p (TREE_VALUE (chain), size_type_node))
    8031              :     {
    8032      1071511 :       if (di) di->sized = true;
    8033      1071511 :       chain = TREE_CHAIN (chain);
    8034              :     }
    8035      3721255 :   if (chain && aligned_new_threshold
    8036      7426485 :       && same_type_p (TREE_VALUE (chain), align_type_node))
    8037              :     {
    8038      1591819 :       if (di) di->aligned = true;
    8039      1591819 :       chain = TREE_CHAIN (chain);
    8040              :     }
    8041      3721258 :   return (chain == void_list_node);
    8042              : }
    8043              : 
    8044              : /* Just return whether FN is a usual deallocation function.  */
    8045              : 
    8046              : bool
    8047         8828 : usual_deallocation_fn_p (tree fn)
    8048              : {
    8049         8828 :   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      1177111 : 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      1177111 :   tree fn = NULL_TREE;
    8080      1177111 :   tree fns, fnname, type, t;
    8081      1177111 :   dealloc_info di_fn = { };
    8082              : 
    8083      1177111 :   if (addr == error_mark_node)
    8084              :     return error_mark_node;
    8085              : 
    8086      1177111 :   type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
    8087              : 
    8088      1177111 :   fnname = ovl_op_identifier (false, code);
    8089              : 
    8090       823939 :   if (CLASS_TYPE_P (type)
    8091       823903 :       && COMPLETE_TYPE_P (complete_type (type))
    8092      2000991 :       && !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       479266 :       fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1, complain);
    8102       479266 :       if (fns == error_mark_node)
    8103              :         return error_mark_node;
    8104              :     }
    8105              :   else
    8106              :     fns = NULL_TREE;
    8107              : 
    8108       479263 :   if (fns == NULL_TREE)
    8109      1176051 :     fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    8110              : 
    8111              :   /* Strip const and volatile from addr.  */
    8112      1177108 :   tree oaddr = addr;
    8113      1177108 :   addr = cp_convert (ptr_type_node, addr, complain);
    8114              : 
    8115      1177108 :   tree excluded_destroying = NULL_TREE;
    8116              : 
    8117      1177108 :   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       636444 :       t = FUNCTION_ARG_CHAIN (alloc_fn);
    8127       636444 :       t = tree_cons (NULL_TREE, ptr_type_node, t);
    8128       636444 :       t = build_function_type (void_type_node, t);
    8129              : 
    8130       636444 :       fn = instantiate_type (t, fns, tf_none);
    8131       636444 :       if (fn == error_mark_node)
    8132              :         return NULL_TREE;
    8133              : 
    8134       635581 :       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       635581 :       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      1176245 :         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      4793770 :     for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8198              :       {
    8199      3712442 :         dealloc_info di_elt;
    8200      3712442 :         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      2141434 :             if (alloc_fn && di_elt.destroying)
    8206              :               {
    8207           13 :                 excluded_destroying = elt;
    8208      1092194 :                 continue;
    8209              :               }
    8210              : 
    8211      2141421 :             if (!fn)
    8212              :               {
    8213       540639 :                 fn = elt;
    8214       540639 :                 di_fn = di_elt;
    8215       540639 :                 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      1600782 :             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      1600770 :             if (aligned_new_threshold)
    8240              :               {
    8241      1600529 :                 bool want_align = type_has_new_extended_alignment (type);
    8242      1600529 :                 if (di_elt.aligned != di_fn.aligned)
    8243              :                   {
    8244       551530 :                     if (want_align == di_elt.aligned)
    8245              :                       {
    8246       515477 :                         fn = elt;
    8247       515477 :                         di_fn = di_elt;
    8248              :                       }
    8249       551530 :                     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      1049240 :             bool want_size;
    8256      1049240 :             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      1049132 :                 want_size = COMPLETE_TYPE_P (type);
    8270      1049132 :                 if (code == VEC_DELETE_EXPR
    8271      1049132 :                     && !TYPE_VEC_NEW_USES_COOKIE (type))
    8272              :                   /* We need a cookie to determine the array size.  */
    8273              :                   want_size = false;
    8274              :               }
    8275      1049240 :             gcc_assert (di_fn.sized != di_elt.sized);
    8276      1049240 :             if (want_size == di_elt.sized)
    8277              :               {
    8278        44291 :                 fn = elt;
    8279        44291 :                 di_fn = di_elt;
    8280              :               }
    8281              :           }
    8282              :       }
    8283              : 
    8284              :   /* If we have a matching function, call it.  */
    8285      1176245 :   if (fn)
    8286              :     {
    8287      1176220 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    8288              : 
    8289              :       /* If the FN is a member function, make sure that it is
    8290              :          accessible.  */
    8291      1176220 :       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      1176220 :       if (DECL_DELETED_FN (fn) && alloc_fn)
    8297              :         return NULL_TREE;
    8298              : 
    8299      1176214 :       tree ret;
    8300      1176214 :       if (placement)
    8301              :         {
    8302              :           /* The placement args might not be suitable for overload
    8303              :              resolution at this point, so build the call directly.  */
    8304       635581 :           int nargs = call_expr_nargs (placement);
    8305       635581 :           tree *argarray = XALLOCAVEC (tree, nargs);
    8306       635581 :           int i;
    8307       635581 :           argarray[0] = addr;
    8308      1271213 :           for (i = 1; i < nargs; i++)
    8309       635632 :             argarray[i] = CALL_EXPR_ARG (placement, i);
    8310       635581 :           if (!mark_used (fn, complain) && !(complain & tf_error))
    8311            0 :             return error_mark_node;
    8312       635581 :           ret = build_cxx_call (fn, nargs, argarray, complain);
    8313              :         }
    8314              :       else
    8315              :         {
    8316       540633 :           tree destroying = di_fn.destroying;
    8317       540633 :           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       540633 :           releasing_vec args;
    8331       540633 :           args->quick_push (addr);
    8332       540633 :           if (destroying)
    8333           25 :             args->quick_push (destroying);
    8334       540633 :           if (di_fn.sized)
    8335       502873 :             args->quick_push (size);
    8336       540633 :           if (di_fn.aligned)
    8337              :             {
    8338        18030 :               tree al = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (type));
    8339        18030 :               args->quick_push (al);
    8340              :             }
    8341       540633 :           ret = cp_build_function_call_vec (fn, &args, complain);
    8342       540633 :         }
    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      1176214 :       tree call = extract_call_expr (ret);
    8352      1176214 :       if (TREE_CODE (call) == CALL_EXPR && !destroying_delete_p (fn))
    8353      1176183 :         CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    8354              : 
    8355      1176214 :       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      1173890 : 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      1173890 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/false,
    8401      1173890 :                                  placement, alloc_fn, complain);
    8402              : }
    8403              : 
    8404              : /* Arguments as per build_op_delete_call_1 ().  */
    8405              : 
    8406              : tree
    8407         3221 : 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         3221 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/true,
    8412         3221 :                                  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     13286537 : build_temp (tree expr, tree type, int flags,
    8473              :             enum diagnostics::kind *diagnostic_kind, tsubst_flags_t complain)
    8474              : {
    8475     13286537 :   int savew, savee;
    8476              : 
    8477     13286537 :   *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     13286537 :   if ((lvalue_kind (expr) & clk_packed)
    8484            6 :       && CLASS_TYPE_P (TREE_TYPE (expr))
    8485     13286543 :       && !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     13286534 :   if (TREE_CODE (expr) == CALL_EXPR
    8492            6 :       && CLASS_TYPE_P (type)
    8493     13286540 :       && same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (expr)))
    8494            3 :     expr = build_cplus_new (type, expr, complain);
    8495              : 
    8496     13286534 :   savew = warningcount + werrorcount, savee = errorcount;
    8497     13286534 :   releasing_vec args (make_tree_vector_single (expr));
    8498     13286534 :   expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
    8499              :                                     &args, type, flags, complain);
    8500     13286534 :   if (warningcount + werrorcount > savew)
    8501            0 :     *diagnostic_kind = diagnostics::kind::warning;
    8502     13286534 :   else if (errorcount > savee)
    8503           77 :     *diagnostic_kind = diagnostics::kind::error;
    8504     13286534 :   return expr;
    8505     13286534 : }
    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      2349260 : get_location_for_expr_unwinding_for_system_header (tree expr)
    8517              : {
    8518      2349260 :   location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
    8519      2349260 :   loc = expansion_point_location_if_in_system_header (loc);
    8520      2349260 :   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    514005576 : conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
    8530              : {
    8531              :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    8532    514005576 :   if (TREE_CODE (totype) != BOOLEAN_TYPE
    8533    310600658 :       && ARITHMETIC_TYPE_P (totype)
    8534    690413048 :       && 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    514005482 :   else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
    8553    514005482 :            && 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    473930564 :   else if ((TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype))
    8572    514309364 :            && null_ptr_cst_p (expr))
    8573              :     {
    8574      2349159 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8575      2349159 :       maybe_warn_zero_as_null_pointer_constant (expr, loc);
    8576              :     }
    8577    514005576 : }
    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      8652352 : 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      8652352 :   if (DECL_ARTIFICIAL (fndecl))
    8606          297 :     return DECL_SOURCE_LOCATION (fndecl);
    8607              : 
    8608      8652055 :   if (argnum == -1)
    8609           49 :     return DECL_SOURCE_LOCATION (fndecl);
    8610              : 
    8611      8652006 :   int i;
    8612      8652006 :   tree param;
    8613              : 
    8614              :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8615      8652006 :   for (i = 0, param = FUNCTION_FIRST_USER_PARM (fndecl);
    8616     21702978 :        i < argnum && param;
    8617     13050972 :        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      8652006 :   if (param == NULL)
    8623           32 :     return DECL_SOURCE_LOCATION (fndecl);
    8624              : 
    8625      8651974 :   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     37327090 : maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
    8650              : {
    8651     37327090 :   if (cxx_dialect >= cxx20)
    8652              :     return;
    8653              : 
    8654       429512 :   tree type = TREE_TYPE (expr);
    8655       429512 :   type = strip_pointer_operator (type);
    8656              : 
    8657       429512 :   if (TREE_CODE (type) != ARRAY_TYPE
    8658       429512 :       || 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    855163992 : maybe_adjust_type_name (tree type, tree expr, conversion_kind kind)
    8676              : {
    8677    855163992 :   if (expr == error_mark_node
    8678    855163941 :       || processing_template_decl)
    8679              :     return expr;
    8680              : 
    8681    750807876 :   tree etype = TREE_TYPE (expr);
    8682    750807876 :   if (etype == type)
    8683              :     return expr;
    8684              : 
    8685    102004986 :   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     99373465 :   if (SCALAR_TYPE_P (type)
    8690    195748717 :       && (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     86871721 :           || TREE_CODE (expr) == NON_LVALUE_EXPR))
    8697     10955885 :     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   1043407950 : 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   1043407950 :   tree totype = convs->type;
    8718   1043407950 :   enum diagnostics::kind diag_kind;
    8719   1043407950 :   int flags;
    8720   1043407950 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    8721   1043407950 :   const bool stub_object_p = is_stub_object (expr);
    8722              : 
    8723   1043407950 :   if (convs->bad_p && !(complain & tf_error))
    8724        42506 :     return error_mark_node;
    8725              : 
    8726   1043365444 :   gcc_checking_assert (!TYPE_REF_P (TREE_TYPE (expr)));
    8727              : 
    8728   1043365444 :   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   1043367031 :       && 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   1043363857 :   if (issue_conversion_warnings && (complain & tf_warning))
    8856    514005576 :     conversion_null_warnings (totype, expr, fn, argnum);
    8857              : 
    8858   1043363857 :   switch (convs->kind)
    8859              :     {
    8860      6440063 :     case ck_user:
    8861      6440063 :       {
    8862      6440063 :         struct z_candidate *cand = convs->cand;
    8863              : 
    8864      6440063 :         if (cand == NULL)
    8865              :           /* We chose the surrogate function from add_conv_candidate, now we
    8866              :              actually need to build the conversion.  */
    8867           56 :           cand = build_user_type_conversion_1 (totype, expr,
    8868              :                                                LOOKUP_NO_CONVERSION, complain);
    8869              : 
    8870      6440063 :         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      6904224 :         if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
    8875         9751 :             && BRACE_ENCLOSED_INITIALIZER_P (expr)
    8876              :             /* Unless this is for direct-list-initialization.  */
    8877         9748 :             && (!CONSTRUCTOR_IS_DIRECT_INIT (expr) || convs->need_temporary_p)
    8878              :             /* And in C++98 a default constructor can't be explicit.  */
    8879      6440299 :             && cxx_dialect >= cxx11)
    8880              :           {
    8881          235 :             if (!(complain & tf_error))
    8882           53 :               return error_mark_node;
    8883          182 :             location_t loc = location_of (expr);
    8884          182 :             if (CONSTRUCTOR_NELTS (expr) == 0
    8885          182 :                 && 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          175 :                 auto_diagnostic_group d;
    8901          175 :                 error ("converting to %qT from initializer list would use "
    8902              :                        "explicit constructor %qD", totype, convfn);
    8903          175 :                 inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8904              :                         convfn);
    8905          175 :               }
    8906              :           }
    8907              : 
    8908              :         /* If we're initializing from {}, it's value-initialization.  */
    8909       832520 :         if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8910       832512 :             && CONSTRUCTOR_NELTS (expr) == 0
    8911       141367 :             && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)
    8912      6581350 :             && !processing_template_decl)
    8913              :           {
    8914       141340 :             if (abstract_virtuals_error (NULL_TREE, totype, complain))
    8915           15 :               return error_mark_node;
    8916       141325 :             expr = build_value_init (totype, complain);
    8917       141325 :             expr = get_target_expr (expr, complain);
    8918       141325 :             if (expr != error_mark_node)
    8919       141185 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8920       141325 :             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      6298670 :         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      6298670 :         iloc_sentinel ils (loc);
    8930              : 
    8931              :         /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow
    8932              :            any more UDCs.  */
    8933      6298670 :         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     12597340 :         if (DECL_CONSTRUCTOR_P (convfn))
    8939              :           {
    8940      2931413 :             expr = build_cplus_new (totype, expr, complain);
    8941              : 
    8942              :             /* Remember that this was list-initialization.  */
    8943      2931413 :             if (convs->check_narrowing && expr != error_mark_node)
    8944       716828 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8945              :           }
    8946              : 
    8947      6298670 :         return expr;
    8948      6298670 :       }
    8949    732202416 :     case ck_identity:
    8950    732202416 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    8951              :         {
    8952      1060133 :           int nelts = CONSTRUCTOR_NELTS (expr);
    8953       164910 :           if (nelts == 0)
    8954       895223 :             expr = build_value_init (totype, complain);
    8955       164910 :           else if (nelts == 1)
    8956       164910 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    8957              :           else
    8958            0 :             gcc_unreachable ();
    8959              :         }
    8960    732202416 :       expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p,
    8961              :                        /*read_p=*/true, UNKNOWN_LOCATION,
    8962              :                        /*reject_builtin=*/true);
    8963              : 
    8964    732202416 :       if (type_unknown_p (expr))
    8965        19367 :         expr = instantiate_type (totype, expr, complain);
    8966    732202416 :       if (!nested_p && TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    8967        50032 :         expr = cp_convert (totype, TREE_OPERAND (expr, 0), complain);
    8968    732202416 :       if (expr == null_node
    8969    732202416 :           && 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       147986 :         expr = build_int_cst (totype, 0);
    8974    732202416 :       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         9840 :     case ck_list:
    8991         9840 :       {
    8992              :         /* Conversion to std::initializer_list<T>.  */
    8993         9840 :         tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (totype), 0);
    8994         9840 :         unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (expr);
    8995         9840 :         tree array;
    8996              : 
    8997         9840 :         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         9708 :         else if (len)
    9010              :           {
    9011         9326 :             tree val;
    9012         9326 :             unsigned ix;
    9013         9326 :             tree new_ctor = build_constructor (init_list_type_node, NULL);
    9014              : 
    9015              :             /* Convert all the elements.  */
    9016        69088 :             FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val)
    9017              :               {
    9018        59777 :                 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        59729 :                 tree sub = convert_like (convs->u.list[ix], val, fn,
    9102              :                                          argnum, false, false,
    9103              :                                          /*nested_p=*/true, complain);
    9104        59729 :                 if (sub == error_mark_node)
    9105              :                   return sub;
    9106         1501 :                 if (!BRACE_ENCLOSED_INITIALIZER_P (val)
    9107        59740 :                     && !check_narrowing (TREE_TYPE (sub), val, complain))
    9108            0 :                   return error_mark_node;
    9109        59720 :                 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    9110              :                                         NULL_TREE, sub);
    9111        59720 :                 if (!TREE_CONSTANT (sub))
    9112        10448 :                   TREE_CONSTANT (new_ctor) = false;
    9113              :               }
    9114              :             /* Build up the array.  */
    9115         9311 :             elttype
    9116         9311 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    9117              :                                                    | TYPE_QUAL_CONST));
    9118         9311 :             array = build_array_of_n_type (elttype, len);
    9119         9311 :             array = finish_compound_literal (array, new_ctor, complain);
    9120              :             /* This is dubious now, should be blessed by P2752.  */
    9121         9311 :             DECL_MERGEABLE (TARGET_EXPR_SLOT (array)) = true;
    9122         9311 :             array = cp_build_addr_expr (array, complain);
    9123              :           }
    9124              :         else
    9125          382 :           array = nullptr_node;
    9126              : 
    9127         9825 :         array = cp_convert (build_pointer_type (elttype), array, complain);
    9128         9825 :         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         9825 :         totype = complete_type_or_maybe_complain (totype, NULL_TREE, complain);
    9135         9825 :         if (!totype)
    9136            0 :           return error_mark_node;
    9137         9825 :         tree field = next_aggregate_field (TYPE_FIELDS (totype));
    9138         9825 :         vec<constructor_elt, va_gc> *vec = NULL;
    9139         9825 :         CONSTRUCTOR_APPEND_ELT (vec, field, array);
    9140         9825 :         field = next_aggregate_field (DECL_CHAIN (field));
    9141         9825 :         CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len));
    9142         9825 :         tree new_ctor = build_constructor (totype, vec);
    9143         9825 :         return get_target_expr (new_ctor, complain);
    9144              :       }
    9145              : 
    9146      1209408 :     case ck_aggr:
    9147      1209408 :       if (TREE_CODE (totype) == COMPLEX_TYPE)
    9148              :         {
    9149        27462 :           tree real = CONSTRUCTOR_ELT (expr, 0)->value;
    9150        27462 :           tree imag = CONSTRUCTOR_ELT (expr, 1)->value;
    9151        27462 :           real = perform_implicit_conversion (TREE_TYPE (totype),
    9152              :                                               real, complain);
    9153        27462 :           imag = perform_implicit_conversion (TREE_TYPE (totype),
    9154              :                                               imag, complain);
    9155        27462 :           expr = build2 (COMPLEX_EXPR, totype, real, imag);
    9156        27462 :           return expr;
    9157              :         }
    9158      1181946 :       expr = reshape_init (totype, expr, complain);
    9159      1181946 :       expr = get_target_expr (digest_init (totype, expr, complain),
    9160              :                                      complain);
    9161      1181946 :       if (expr != error_mark_node)
    9162      1181935 :         TARGET_EXPR_LIST_INIT_P (expr) = true;
    9163              :       return expr;
    9164              : 
    9165    303502083 :     default:
    9166    303502083 :       break;
    9167    303502083 :     };
    9168              : 
    9169    303502083 :   conversion *nc = next_conversion (convs);
    9170    303502083 :   if (convs->kind == ck_ref_bind && nc->kind == ck_qual
    9171        25540 :       && !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        23733 :     nc = next_conversion (nc);
    9176              : 
    9177    303502083 :   expr = convert_like (nc, expr, fn, argnum,
    9178              :                        convs->kind == ck_ref_bind
    9179    303502083 :                        ? issue_conversion_warnings : false,
    9180              :                        c_cast_p, /*nested_p=*/true, complain & ~tf_no_cleanup);
    9181    303502083 :   if (expr == error_mark_node)
    9182              :     return error_mark_node;
    9183              : 
    9184    303501610 :   switch (convs->kind)
    9185              :     {
    9186    136039393 :     case ck_rvalue:
    9187    136039393 :       expr = decay_conversion (expr, complain);
    9188    136039393 :       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    136039378 :       if ((complain & tf_warning) && fn
    9200     38328507 :           && 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    136039378 :       if (! MAYBE_CLASS_TYPE_P (totype))
    9214    122961576 :         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     13077802 :       if (current_function_decl
    9219     10334264 :           && flag_new_inheriting_ctors
    9220     33745850 :           && DECL_INHERITED_CTOR (current_function_decl))
    9221              :         return expr;
    9222              : 
    9223     13074137 :       if (TREE_CODE (expr) == TARGET_EXPR
    9224     13074137 :           && TARGET_EXPR_LIST_INIT_P (expr))
    9225              :         /* Copy-list-initialization doesn't actually involve a copy.  */
    9226              :         return expr;
    9227              : 
    9228              :       /* Fall through.  */
    9229     15018786 :     case ck_base:
    9230     15018786 :       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      1732249 :           expr = convert_to_base (expr, totype,
    9236      1732249 :                                   !c_cast_p, /*nonnull=*/true, complain);
    9237      1732249 :           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     13286537 :       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     13286537 :       if (convs->user_conv_p)
    9248       247478 :         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     13286537 :       if (convs->copy_init_p)
    9254     13029200 :         flags |= LOOKUP_ONLYCONVERTING;
    9255     13286537 :       expr = build_temp (expr, totype, flags, &diag_kind, complain);
    9256     13286537 :       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     13286537 :       return build_cplus_new (totype, expr, complain);
    9264              : 
    9265     56776439 :     case ck_ref_bind:
    9266     56776439 :       {
    9267     56776439 :         tree ref_type = totype;
    9268              : 
    9269     56776439 :         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     56771312 :         else if (complain & tf_warning)
    9319     35974064 :           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     56771312 :         if (convs->need_temporary_p
    9328     54369781 :             || TREE_CODE (expr) == CONSTRUCTOR
    9329     54369687 :             || 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      2401625 :             tree type = TREE_TYPE (ref_type);
    9336      2401625 :             cp_lvalue_kind lvalue = lvalue_kind (expr);
    9337              : 
    9338      2401625 :             gcc_assert (similar_type_p (type, next_conversion (convs)->type));
    9339      2401625 :             if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
    9340      3246159 :                 && !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      2401520 :             if ((lvalue & clk_packed)
    9365           20 :                 && CLASS_TYPE_P (type)
    9366      2401537 :                 && 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      2401514 :             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      2401514 :             if (processing_template_decl)
    9384         9316 :               return build1 (IMPLICIT_CONV_EXPR, totype, expr);
    9385      2392198 :             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     56761885 :         expr = cp_build_addr_expr (expr, complain);
    9391     56761885 :         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     56761885 :         expr = cp_convert (build_pointer_type (TREE_TYPE (ref_type)),
    9398              :                            expr, complain);
    9399              :         /* Convert the pointer to the desired reference type.  */
    9400     56761885 :         return build_nop (ref_type, expr);
    9401              :       }
    9402              : 
    9403      2660111 :     case ck_lvalue:
    9404      2660111 :       return decay_conversion (expr, complain);
    9405              : 
    9406       225562 :     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       225562 :       return build_nop (totype, expr);
    9410              : 
    9411      1548111 :     case ck_qual:
    9412              :       /* Warn about deprecated conversion if appropriate.  */
    9413      1548111 :       if (complain & tf_warning)
    9414              :         {
    9415      1353026 :           string_conv_p (totype, expr, 1);
    9416      1353026 :           maybe_warn_array_conv (loc, convs, expr);
    9417              :         }
    9418              :       break;
    9419              : 
    9420      2894616 :     case ck_ptr:
    9421      2894616 :       if (convs->base_p)
    9422       206891 :         expr = convert_to_base (expr, totype, !c_cast_p,
    9423              :                                 /*nonnull=*/false, complain);
    9424      2894616 :       return build_nop (totype, expr);
    9425              : 
    9426        27796 :     case ck_pmem:
    9427        27796 :       return convert_ptrmem (totype, expr, /*allow_inverse_p=*/false,
    9428        27796 :                              c_cast_p, complain);
    9429              : 
    9430              :     default:
    9431              :       break;
    9432              :     }
    9433              : 
    9434    102906758 :   if (convs->check_narrowing
    9435    156480941 :       && !check_narrowing (totype, expr, complain,
    9436     53574183 :                            convs->check_narrowing_const_only))
    9437          453 :     return error_mark_node;
    9438              : 
    9439    205812610 :   warning_sentinel w (warn_zero_as_null_pointer_constant);
    9440    102906305 :   if (issue_conversion_warnings)
    9441     80889958 :     expr = cp_convert_and_check (totype, expr, complain);
    9442              :   else
    9443              :     {
    9444     22016347 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9445           36 :         expr = TREE_OPERAND (expr, 0);
    9446     22016347 :       expr = cp_convert (totype, expr, complain);
    9447              :     }
    9448              : 
    9449    102906305 :   return expr;
    9450              : }
    9451              : 
    9452              : /* Return true if converting FROM to TO is unsafe in a template.  */
    9453              : 
    9454              : static bool
    9455      1824351 : conv_unsafe_in_template_p (tree to, tree from)
    9456              : {
    9457              :   /* Converting classes involves TARGET_EXPR.  */
    9458      1824351 :   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      1409985 :   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      1409982 :   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   1043822313 : 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   1043822313 :   tree conv_expr = NULL_TREE;
    9487   1043822313 :   if (processing_template_decl
    9488    105472043 :       && convs->kind != ck_identity
    9489   1045646664 :       && conv_unsafe_in_template_p (convs->type, TREE_TYPE (expr)))
    9490              :     {
    9491       414372 :       conv_expr = build1 (IMPLICIT_CONV_EXPR, convs->type, expr);
    9492       414372 :       if (convs->kind != ck_ref_bind)
    9493        46043 :         conv_expr = convert_from_reference (conv_expr);
    9494       414372 :       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   1043407950 :   expr = convert_like_internal (convs, expr, fn, argnum,
    9501              :                                 issue_conversion_warnings, c_cast_p,
    9502              :                                 nested_p, complain);
    9503   1043407950 :   if (expr == error_mark_node)
    9504              :     return error_mark_node;
    9505   1043358076 :   return conv_expr ? conv_expr : expr;
    9506              : }
    9507              : 
    9508              : /* Convenience wrapper for convert_like.  */
    9509              : 
    9510              : static inline tree
    9511    576204199 : convert_like (conversion *convs, tree expr, tsubst_flags_t complain)
    9512              : {
    9513    576204199 :   return convert_like (convs, expr, NULL_TREE, 0,
    9514              :                        /*issue_conversion_warnings=*/true,
    9515    576204199 :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9516              : }
    9517              : 
    9518              : /* Convenience wrapper for convert_like.  */
    9519              : 
    9520              : static inline tree
    9521    125738231 : 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      1335867 : convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
    9534              : {
    9535      1335867 :   tree arg_type = TREE_TYPE (arg);
    9536      1335867 :   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      1335867 :   if (SCALAR_FLOAT_TYPE_P (arg_type)
    9546        48011 :       && (TYPE_PRECISION (arg_type)
    9547        48011 :           < TYPE_PRECISION (double_type_node))
    9548        11859 :       && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (arg_type))
    9549      1347048 :       && !extended_float_type_p (arg_type))
    9550              :     {
    9551        11177 :       if ((complain & tf_warning)
    9552        11174 :           && 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        11177 :       if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    9558            3 :         arg = TREE_OPERAND (arg, 0);
    9559        11177 :       arg = mark_rvalue_use (arg);
    9560        11177 :       arg = convert_to_real_nofold (double_type_node, arg);
    9561              :     }
    9562      1324690 :   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      1324615 :   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type))
    9574              :     {
    9575       875463 :       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      1335867 :             arg = prom;
    9589              :         }
    9590              :       else
    9591       875407 :         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       449152 :     arg = decay_conversion (arg, complain);
    9599              : 
    9600      1335867 :   arg = require_complete_type (arg, complain);
    9601      1335867 :   arg_type = TREE_TYPE (arg);
    9602              : 
    9603      1335867 :   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      1335855 :       && COMPLETE_TYPE_P (arg_type)
    9608      2671722 :       && !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       635960 :       if (type_has_nontrivial_copy_init (arg_type)
    9622       635960 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))
    9623              :         {
    9624           35 :           arg = force_rvalue (arg, complain);
    9625           35 :           if (complain & tf_warning)
    9626           35 :             warning (OPT_Wconditionally_supported,
    9627              :                      "passing objects of non-trivially-copyable "
    9628              :                      "type %q#T through %<...%> is conditionally supported",
    9629              :                      arg_type);
    9630           35 :           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       635925 :       else if (CLASS_TYPE_P (arg_type))
    9635        44176 :         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      2586027 : cxx_type_promotes_to (tree type)
    9695              : {
    9696      2586027 :   tree promote;
    9697              : 
    9698              :   /* Perform the array-to-pointer and function-to-pointer
    9699              :      conversions.  */
    9700      2586027 :   type = type_decays_to (type);
    9701              : 
    9702      2586027 :   promote = type_promotes_to (type);
    9703      2586027 :   if (same_type_p (type, promote))
    9704      2586003 :     promote = type;
    9705              : 
    9706      2586027 :   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      7586208 : push_defarg_context (tree fn)
    9717      7586208 : { vec_safe_push (default_arg_context, fn); }
    9718              : 
    9719              : void
    9720      7586208 : pop_defarg_context (void)
    9721      7586208 : { default_arg_context->pop (); }
    9722              : 
    9723              : tree
    9724      1034093 : convert_default_arg (tree type, tree arg, tree fn, int parmnum,
    9725              :                      tsubst_flags_t complain)
    9726              : {
    9727      1034093 :   int i;
    9728      1034093 :   tree t;
    9729              : 
    9730              :   /* See through clones.  */
    9731      1034093 :   fn = DECL_ORIGIN (fn);
    9732              :   /* And inheriting ctors.  */
    9733      1034093 :   if (flag_new_inheriting_ctors)
    9734      1033453 :     fn = strip_inheriting_ctors (fn);
    9735              : 
    9736              :   /* Detect recursion.  */
    9737      1035983 :   FOR_EACH_VEC_SAFE_ELT (default_arg_context, i, t)
    9738         1896 :     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      1034087 :   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      1034072 :   push_defarg_context (fn);
    9756              : 
    9757      1034072 :   if (fn && DECL_TEMPLATE_INFO (fn))
    9758       750062 :     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      1034072 :   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      1034072 :   arg = break_out_target_exprs (arg, /*clear location*/true);
    9773              : 
    9774      1034072 :   arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT,
    9775              :                                     ICR_DEFAULT_ARGUMENT, fn, parmnum,
    9776              :                                     complain);
    9777      1034072 :   arg = convert_for_arg_passing (type, arg, complain);
    9778      1034072 :   pop_deferring_access_checks();
    9779              : 
    9780      1034072 :   pop_defarg_context ();
    9781              : 
    9782      1034072 :   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    638735392 : type_passed_as (tree type)
    9790              : {
    9791              :   /* Pass classes with copy ctors by invisible reference.  */
    9792    638735392 :   if (TREE_ADDRESSABLE (type))
    9793       603070 :     type = build_reference_type (type);
    9794              : 
    9795    638735392 :   return type;
    9796              : }
    9797              : 
    9798              : /* Actually perform the appropriate conversion.  */
    9799              : 
    9800              : tree
    9801    131361054 : convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain)
    9802              : {
    9803    131361054 :   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    131361054 :   bitfield_type = is_bitfield_expr_with_lowered_type (val);
    9820    131361054 :   if (bitfield_type
    9821    131361054 :       && TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type))
    9822            0 :     val = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type), val);
    9823              : 
    9824    131361054 :   if (val == error_mark_node)
    9825              :     ;
    9826              :   /* Pass classes with copy ctors by invisible reference.  */
    9827    131357980 :   else if (TREE_ADDRESSABLE (type))
    9828       194226 :     val = build1 (ADDR_EXPR, build_reference_type (type), val);
    9829    131361054 :   if (complain & tf_warning)
    9830    122387667 :     maybe_warn_parm_abi (type, cp_expr_loc_or_input_loc (val));
    9831              : 
    9832     98346061 :   if (complain & tf_warning)
    9833     98346061 :     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      7651003 :   if (SIMPLE_TARGET_EXPR_P (val)
    9839    137486112 :       && TREE_CODE (TARGET_EXPR_INITIAL (val)) != CONSTRUCTOR)
    9840      3593833 :     set_target_expr_eliding (val);
    9841              : 
    9842    131361054 :   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    157109305 : magic_varargs_p (tree fn)
    9856              : {
    9857    157109305 :   if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
    9858      5542108 :     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       179970 :       case BUILT_IN_ISFINITE:
    9872       179970 :       case BUILT_IN_ISINF:
    9873       179970 :       case BUILT_IN_ISINF_SIGN:
    9874       179970 :       case BUILT_IN_ISNAN:
    9875       179970 :       case BUILT_IN_ISNORMAL:
    9876       179970 :       case BUILT_IN_FPCLASSIFY:
    9877       179970 :         return 2;
    9878              : 
    9879        93002 :       case BUILT_IN_CLZG:
    9880        93002 :       case BUILT_IN_CTZG:
    9881        93002 :       case BUILT_IN_CLRSBG:
    9882        93002 :       case BUILT_IN_FFSG:
    9883        93002 :       case BUILT_IN_PARITYG:
    9884        93002 :       case BUILT_IN_POPCOUNTG:
    9885        93002 :         return 4;
    9886              : 
    9887      5036277 :       default:
    9888      5036277 :         return lookup_attribute ("type generic",
    9889     10072554 :                                  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     39598589 : unsafe_return_slot_p (tree t)
   10038              : {
   10039              :   /* Check empty bases separately, they don't have fields.  */
   10040     39598589 :   if (is_empty_base_ref (t))
   10041              :     return 2;
   10042              : 
   10043              :   /* A delegating constructor might be used to initialize a base.  */
   10044     39106709 :   if (current_function_decl
   10045     52942060 :       && DECL_CONSTRUCTOR_P (current_function_decl)
   10046     43011590 :       && (t == current_class_ref
   10047      3740783 :           || tree_strip_nop_conversions (t) == current_class_ptr))
   10048       212401 :     return 2;
   10049              : 
   10050     38894308 :   STRIP_NOPS (t);
   10051     38894308 :   if (TREE_CODE (t) == ADDR_EXPR)
   10052        61964 :     t = TREE_OPERAND (t, 0);
   10053     38894308 :   if (TREE_CODE (t) == COMPONENT_REF)
   10054      3265864 :     t = TREE_OPERAND (t, 1);
   10055     38894308 :   if (TREE_CODE (t) != FIELD_DECL)
   10056              :     return false;
   10057      3322233 :   if (!CLASS_TYPE_P (TREE_TYPE (t)))
   10058              :     /* The middle-end will do the right thing for scalar types.  */
   10059              :     return false;
   10060      2906429 :   if (DECL_FIELD_IS_BASE (t))
   10061              :     return 2;
   10062      2129085 :   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       276027 : init_by_return_slot_p (tree exp)
   10071              : {
   10072              :   /* Copy elision only happens with a TARGET_EXPR.  */
   10073       276030 :   if (TREE_CODE (exp) != TARGET_EXPR)
   10074              :     return false;
   10075        13732 :   tree init = TARGET_EXPR_INITIAL (exp);
   10076              :   /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR.  */
   10077        13738 :   while (TREE_CODE (init) == COMPOUND_EXPR)
   10078            6 :     init = TREE_OPERAND (init, 1);
   10079        13732 :   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        13726 :   return (TREE_CODE (init) == AGGR_INIT_EXPR
   10089        13726 :           && !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      2125915 : unsafe_copy_elision_p (tree target, tree exp)
   10101              : {
   10102      2125915 :   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      7568783 : unsafe_copy_elision_p_opt (tree target, tree exp)
   10109              : {
   10110      7568783 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
   10111              :   /* It's safe to elide the copy for a class with no tail padding.  */
   10112      7568783 :   if (!is_empty_class (type)
   10113      7568783 :       && tree_int_cst_equal (TYPE_SIZE (type), CLASSTYPE_SIZE (type)))
   10114              :     return false;
   10115      2069546 :   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     13278011 : conv_is_prvalue (conversion *c)
   10138              : {
   10139     13278011 :   if (c->kind == ck_rvalue)
   10140              :     return true;
   10141     13278011 :   if (c->kind == ck_base && c->need_temporary_p)
   10142              :     return true;
   10143     13278011 :   if (c->kind == ck_user && !TYPE_REF_P (c->type))
   10144              :     return true;
   10145     13148652 :   if (c->kind == ck_identity && c->u.expr
   10146     12912840 :       && 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     13279027 : conv_binds_ref_to_prvalue (conversion *c)
   10156              : {
   10157     13279027 :   if (c->kind != ck_ref_bind)
   10158              :     return false;
   10159     13279027 :   if (c->need_temporary_p)
   10160              :     return true;
   10161              : 
   10162     13278011 :   return conv_is_prvalue (next_conversion (c));
   10163              : }
   10164              : 
   10165              : /* True iff EXPR represents a (subobject of a) temporary.  */
   10166              : 
   10167              : static bool
   10168        13975 : expr_represents_temporary_p (tree expr)
   10169              : {
   10170        14079 :   while (handled_component_p (expr))
   10171          104 :     expr = TREE_OPERAND (expr, 0);
   10172        13975 :   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        13249 : conv_binds_ref_to_temporary (conversion *c)
   10181              : {
   10182        13249 :   if (conv_binds_ref_to_prvalue (c))
   10183              :     return true;
   10184        12822 :   if (c->kind != ck_ref_bind)
   10185              :     return false;
   10186        12822 :   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        12822 :   if (c->kind == ck_base)
   10196            8 :     c = next_conversion (c);
   10197        12754 :   if (c->kind == ck_identity && c->u.expr
   10198        25576 :       && 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        13750 : ref_conv_binds_to_temporary (tree type, tree expr, bool direct_init_p/*=false*/)
   10212              : {
   10213        13750 :   gcc_assert (TYPE_REF_P (type));
   10214              : 
   10215        13750 :   conversion_obstack_sentinel cos;
   10216              : 
   10217        13750 :   const int flags = direct_init_p ? LOOKUP_NORMAL : LOOKUP_IMPLICIT;
   10218        13750 :   conversion *conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   10219              :                                           /*c_cast_p=*/false, flags, tf_none);
   10220        13750 :   if (!conv || conv->bad_p)
   10221          501 :     return tristate::unknown ();
   10222              : 
   10223        13249 :   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        12816 :   return tristate (false);
   10233        13750 : }
   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      3331709 : build_trivial_dtor_call (tree instance, bool no_ptr_deref)
   10242              : {
   10243      3331709 :   gcc_assert (!is_dummy_object (instance));
   10244              : 
   10245      3331709 :   if (!flag_lifetime_dse)
   10246              :     {
   10247           58 :     no_clobber:
   10248           77 :       return fold_convert (void_type_node, instance);
   10249              :     }
   10250              : 
   10251      3382300 :   if (INDIRECT_TYPE_P (TREE_TYPE (instance))
   10252      3331651 :       && (!no_ptr_deref || TYPE_REF_P (TREE_TYPE (instance))))
   10253              :     {
   10254      3170635 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
   10255           19 :         goto no_clobber;
   10256      3170616 :       instance = cp_build_fold_indirect_ref (instance);
   10257              :     }
   10258              : 
   10259              :   /* A trivial destructor should still clobber the object.  */
   10260      3331632 :   tree clobber = build_clobber (TREE_TYPE (instance), CLOBBER_OBJECT_END);
   10261      3331632 :   return build2 (MODIFY_EXPR, void_type_node,
   10262      3331632 :                  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      9939588 : in_immediate_context ()
   10271              : {
   10272      9939588 :   return (cp_unevaluated_operand != 0
   10273      8543482 :           || (current_function_decl != NULL_TREE
   10274     14121972 :               && 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      8317358 :           || current_binding_level->kind == sk_function_parms
   10278      8316063 :           || current_binding_level->kind == sk_template_parms
   10279      8285352 :           || parsing_nsdmi ()
   10280     18223218 :           || 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    196041566 : immediate_invocation_p (tree fn)
   10288              : {
   10289    196041566 :   return (TREE_CODE (fn) == FUNCTION_DECL
   10290    196041566 :           && DECL_IMMEDIATE_FUNCTION_P (fn)
   10291    198882879 :           && !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    212258236 : build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
   10301              : {
   10302    212258236 :   tree fn = cand->fn;
   10303    212258236 :   const vec<tree, va_gc> *args = cand->args;
   10304    212258236 :   tree first_arg = cand->first_arg;
   10305    212258236 :   conversion **convs = cand->convs;
   10306    212258236 :   tree parm = TYPE_ARG_TYPES (TREE_TYPE (fn));
   10307    212258236 :   int parmlen;
   10308    212258236 :   tree val;
   10309    212258236 :   int nargs;
   10310    212258236 :   tree *argarray;
   10311    212258236 :   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    212258236 :   if (processing_template_decl)
   10318              :     {
   10319     29570380 :       if (undeduced_auto_decl (fn))
   10320        11324 :         mark_used (fn, complain);
   10321              :       else
   10322              :         /* Otherwise set TREE_USED for the benefit of -Wunused-function.
   10323              :            See PR80598.  */
   10324     29559056 :         TREE_USED (fn) = 1;
   10325              : 
   10326     29570380 :       tree return_type = TREE_TYPE (TREE_TYPE (fn));
   10327     29570380 :       tree callee;
   10328     29570380 :       if (first_arg == NULL_TREE)
   10329              :         {
   10330     21505605 :           callee = build_addr_func (fn, complain);
   10331     21505605 :           if (callee == error_mark_node)
   10332              :             return error_mark_node;
   10333              :         }
   10334              :       else
   10335              :         {
   10336      8064775 :           callee = build_baselink (cand->conversion_path, cand->access_path,
   10337              :                                    fn, NULL_TREE);
   10338      8064775 :           callee = build_min (COMPONENT_REF, TREE_TYPE (fn),
   10339              :                               first_arg, callee, NULL_TREE);
   10340              :         }
   10341              : 
   10342     29570380 :       tree expr = build_call_vec (return_type, callee, args);
   10343     29570380 :       SET_EXPR_LOCATION (expr, input_location);
   10344     29570380 :       if (TREE_THIS_VOLATILE (fn) && cfun)
   10345      2472253 :         current_function_returns_abnormally = 1;
   10346     29570380 :       if (TREE_DEPRECATED (fn)
   10347     29570380 :           && warning_suppressed_at (input_location,
   10348              :                                     OPT_Wdeprecated_declarations))
   10349              :         /* Make the expr consistent with the location.  */
   10350        19205 :         TREE_NO_WARNING (expr) = true;
   10351     29570380 :       if (immediate_invocation_p (fn))
   10352              :         {
   10353       193115 :           tree obj_arg = NULL_TREE;
   10354       386230 :           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       193115 :           fold_non_dependent_expr (expr, complain,
   10370              :                                    /*manifestly_const_eval=*/true,
   10371              :                                    obj_arg);
   10372              :         }
   10373     29570380 :       return convert_from_reference (expr);
   10374              :     }
   10375              : 
   10376              :   /* Give any warnings we noticed during overload resolution.  */
   10377    182687856 :   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    182687856 :   bool force_elide = false;
   10389    182687856 :   if (cxx_dialect >= cxx17
   10390    180692100 :       && cand->num_convs == 1
   10391    102721509 :       && DECL_COMPLETE_CONSTRUCTOR_P (fn)
   10392     37236040 :       && (DECL_COPY_CONSTRUCTOR_P (fn)
   10393     20480622 :           || DECL_MOVE_CONSTRUCTOR_P (fn))
   10394     13332132 :       && !unsafe_return_slot_p (first_arg)
   10395    195953580 :       && conv_binds_ref_to_prvalue (convs[0]))
   10396              :     {
   10397       130001 :       force_elide = true;
   10398       130001 :       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    365115710 :   if (DECL_INHERITED_CTOR (fn)
   10405     27494755 :       && !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    182557853 :   if (DECL_DELETED_FN (fn))
   10414              :     {
   10415       991993 :       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       991993 :       return error_mark_node;
   10429              :     }
   10430              : 
   10431    181565860 :   if (DECL_FUNCTION_MEMBER_P (fn))
   10432              :     {
   10433    100530337 :       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    100530337 :       if (DECL_TEMPLATE_INFO (fn)
   10460    100530337 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   10461      7292717 :         access_fn = DECL_TI_TEMPLATE (fn);
   10462              :       else
   10463              :         access_fn = fn;
   10464    100530337 :       if (!perform_or_defer_access_check (cand->access_path, access_fn,
   10465              :                                           fn, complain))
   10466        20301 :         return error_mark_node;
   10467              :     }
   10468              : 
   10469              :   /* If we're checking for implicit delete, don't bother with argument
   10470              :      conversions.  */
   10471    181545559 :   if (flags & LOOKUP_SPECULATIVE)
   10472              :     {
   10473     24563655 :       if (cand->viable == 1)
   10474              :         return fn;
   10475          121 :       else if (!(complain & tf_error))
   10476              :         /* Reject bad conversions now.  */
   10477          106 :         return error_mark_node;
   10478              :       /* else continue to get conversion error.  */
   10479              :     }
   10480              : 
   10481    156981904 :  not_really_used:
   10482              : 
   10483              :   /* N3276 magic doesn't apply to nested calls.  */
   10484    157111920 :   tsubst_flags_t decltype_flag = (complain & tf_decltype);
   10485    157111920 :   complain &= ~tf_decltype;
   10486              :   /* No-Cleanup doesn't apply to nested calls either.  */
   10487    157111920 :   tsubst_flags_t no_cleanup_complain = complain;
   10488    157111920 :   complain &= ~tf_no_cleanup;
   10489              : 
   10490              :   /* Find maximum size of vector to hold converted arguments.  */
   10491    157111920 :   parmlen = list_length (parm);
   10492    294638040 :   nargs = vec_safe_length (args) + (first_arg != NULL_TREE ? 1 : 0);
   10493    157111920 :   if (parmlen > nargs)
   10494              :     nargs = parmlen;
   10495    157111920 :   argarray = XALLOCAVEC (tree, nargs);
   10496              : 
   10497    314223837 :   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    157111920 :   if (immediate_invocation_p (STRIP_TEMPLATE (fn)))
   10501      1387503 :     in_consteval_if_p = true;
   10502              : 
   10503    157111920 :   int argarray_size = 0;
   10504    157111920 :   unsigned int arg_index = 0;
   10505    157111920 :   int conv_index = 0;
   10506    157111920 :   int param_index = 0;
   10507    157111920 :   tree parmd = DECL_ARGUMENTS (fn);
   10508              : 
   10509    220990234 :   auto consume_object_arg = [&arg_index, &first_arg, args]()
   10510              :     {
   10511     63878314 :       if (!first_arg)
   10512            0 :         return (*args)[arg_index++];
   10513     63878314 :       tree object_arg = first_arg;
   10514     63878314 :       first_arg = NULL_TREE;
   10515     63878314 :       return object_arg;
   10516    157111920 :     };
   10517              : 
   10518              :   /* The implicit parameters to a constructor are not considered by overload
   10519              :      resolution, and must be of the proper type.  */
   10520    157111920 :   if (DECL_CONSTRUCTOR_P (fn))
   10521              :     {
   10522     19530760 :       tree object_arg = consume_object_arg ();
   10523     19530760 :       argarray[argarray_size++] = build_this (object_arg);
   10524     19530760 :       parm = TREE_CHAIN (parm);
   10525     19530760 :       if (parmd)
   10526     19530760 :         parmd = DECL_CHAIN (parmd);
   10527              :       /* We should never try to call the abstract constructor.  */
   10528     19530760 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (fn));
   10529              : 
   10530     19530760 :       if (DECL_HAS_VTT_PARM_P (fn))
   10531              :         {
   10532        17027 :           argarray[argarray_size++] = (*args)[arg_index];
   10533        17027 :           ++arg_index;
   10534        17027 :           parm = TREE_CHAIN (parm);
   10535        17027 :           if (parmd)
   10536        17027 :             parmd = DECL_CHAIN (parmd);
   10537              :         }
   10538              :     }
   10539              :   /* Bypass access control for 'this' parameter.  */
   10540    137581160 :   else if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
   10541              :     {
   10542     44341436 :       tree arg = build_this (consume_object_arg ());
   10543     44341436 :       tree argtype = TREE_TYPE (arg);
   10544              : 
   10545     44341436 :       if (arg == error_mark_node)
   10546              :         return error_mark_node;
   10547     44341433 :       if (convs[conv_index++]->bad_p)
   10548              :         {
   10549         1109 :           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     44340427 :       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     44340427 :       if (DECL_FINAL_P (fn) || CLASSTYPE_FINAL (ctx))
   10567       124399 :         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     44340427 :       if (!accessible_base_p (TREE_TYPE (argtype),
   10577     44340427 :                               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     44340424 :       tree base_binfo = cand->conversion_path;
   10590     44340424 :       if (BINFO_TYPE (base_binfo) != ctx)
   10591              :         {
   10592       113472 :           base_binfo = lookup_base (base_binfo, ctx, ba_unique, NULL, complain);
   10593       113472 :           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     45199060 :       if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
   10600     44815138 :           && 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     44340418 :       tree converted_arg = build_base_path (PLUS_EXPR, arg,
   10620              :                                             base_binfo, 1, complain);
   10621              : 
   10622     44340418 :       argarray[argarray_size++] = converted_arg;
   10623     44340418 :       parm = TREE_CHAIN (parm);
   10624     44340418 :       if (parmd)
   10625     44340418 :         parmd = DECL_CHAIN (parmd);
   10626              :     }
   10627              : 
   10628    282849133 :   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    125738231 :       if (flags & LOOKUP_NO_CONVERSION)
   10638      3691111 :         conv->user_conv_p = true;
   10639              : 
   10640    125738231 :       if (arg_complain & tf_warning)
   10641     93138284 :         maybe_warn_pessimizing_move (arg, type, /*return_p=*/false);
   10642              : 
   10643    125738231 :       tree val = convert_like_with_context (conv, arg, fn,
   10644              :                                             param_index, arg_complain);
   10645    125738231 :       val = convert_for_arg_passing (type, val, arg_complain);
   10646    125738231 :       return val;
   10647    157110902 :     };
   10648              : 
   10649    283881612 :   auto handle_indeterminate_arg = [](tree parmd, tree val)
   10650              :     {
   10651    126770710 :       if (parmd
   10652    126770710 :           && 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    126770710 :     };
   10669              : 
   10670    157110902 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   10671              :     {
   10672         6118 :       gcc_assert (cand->num_convs > 0);
   10673         6118 :       tree object_arg = consume_object_arg ();
   10674         6118 :       val = handle_arg (TREE_VALUE (parm),
   10675              :                         object_arg,
   10676              :                         param_index++,
   10677         6118 :                         convs[conv_index++],
   10678              :                         complain);
   10679              : 
   10680         6118 :       if (val == error_mark_node)
   10681              :         return error_mark_node;
   10682              :       else
   10683              :         {
   10684         6006 :           argarray[argarray_size++] = val;
   10685         6006 :           handle_indeterminate_arg (parmd, val);
   10686              :         }
   10687         6006 :       parm = TREE_CHAIN (parm);
   10688         6006 :       if (parmd)
   10689         6006 :         parmd = DECL_CHAIN (parmd);
   10690              :     }
   10691              : 
   10692    157110790 :   gcc_assert (first_arg == NULL_TREE);
   10693    282841511 :   for (; arg_index < vec_safe_length (args) && parm;
   10694    125730721 :        parm = TREE_CHAIN (parm), ++arg_index, ++param_index, ++conv_index)
   10695              :     {
   10696    125732113 :       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    125732113 :       bool const conversion_warning = !(null_node_p (current_arg)
   10719        46527 :                                         && DECL_TEMPLATE_INFO (fn)
   10720           61 :                                         && 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    125732113 :       val = handle_arg (TREE_VALUE (parm),
   10727              :                         current_arg,
   10728              :                         param_index,
   10729    125732113 :                         convs[conv_index],
   10730              :                         arg_complain);
   10731              : 
   10732    125732113 :       if (val == error_mark_node)
   10733              :         return error_mark_node;
   10734              :       else
   10735              :         {
   10736    125730721 :           argarray[argarray_size++] = val;
   10737    125730721 :           handle_indeterminate_arg (parmd, val);
   10738              :         }
   10739    125730721 :       if (parmd)
   10740    115150561 :         parmd = DECL_CHAIN (parmd);
   10741              :     }
   10742              : 
   10743              :   /* Default arguments */
   10744    158143381 :   for (; parm && parm != void_list_node;
   10745      1033983 :        parm = TREE_CHAIN (parm), param_index++)
   10746              :     {
   10747      1034097 :       if (TREE_VALUE (parm) == error_mark_node)
   10748              :         return error_mark_node;
   10749      2068170 :       val = convert_default_arg (TREE_VALUE (parm),
   10750      1034085 :                                  TREE_PURPOSE (parm),
   10751              :                                  fn, param_index,
   10752              :                                  complain);
   10753      1034085 :       if (val == error_mark_node)
   10754              :         return error_mark_node;
   10755      1033983 :       argarray[argarray_size++] = val;
   10756      1033983 :       handle_indeterminate_arg (parmd, val);
   10757      1033983 :       if (parmd)
   10758      1033983 :         parmd = DECL_CHAIN (parmd);
   10759              :     }
   10760              : 
   10761              :   /* Ellipsis */
   10762    157109284 :   int magic = magic_varargs_p (fn);
   10763    159844782 :   for (; arg_index < vec_safe_length (args); ++arg_index)
   10764              :     {
   10765      2735519 :       tree a = (*args)[arg_index];
   10766      2735519 :       if ((magic == 3 && arg_index == 2) || (magic == 4 && arg_index == 0))
   10767              :         {
   10768              :           /* Do no conversions for certain magic varargs.  */
   10769       113808 :           a = mark_type_use (a);
   10770       113808 :           if (TREE_CODE (a) == FUNCTION_DECL && reject_gcc_builtin (a))
   10771            0 :             return error_mark_node;
   10772              :         }
   10773      2621711 :       else if (magic != 0)
   10774              :         {
   10775              :           /* Don't truncate excess precision to the semantic type.  */
   10776      1286287 :           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      1286287 :           a = decay_conversion (a, complain);
   10780              :         }
   10781      1335424 :       else if (DECL_CONSTRUCTOR_P (fn)
   10782          336 :                && vec_safe_length (args) == 1
   10783      1335584 :                && 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      1335421 :         a = convert_arg_to_ellipsis (a, complain);
   10794      2735516 :       if (a == error_mark_node)
   10795              :         return error_mark_node;
   10796      2735498 :       argarray[argarray_size++] = a;
   10797              :     }
   10798              : 
   10799    157109263 :   gcc_assert (argarray_size <= nargs);
   10800    157109263 :   nargs = argarray_size;
   10801    157109263 :   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    157109263 :   bool warned_p = false;
   10808    157109263 :   if ((complain & tf_warning)
   10809    106344476 :       && (warn_nonnull
   10810    104391683 :           || warn_format
   10811    104391680 :           || warn_suggest_attribute_format
   10812    104391584 :           || warn_restrict))
   10813              :     {
   10814      1955139 :       tree *fargs = (!nargs ? argarray
   10815      1614937 :                             : (tree *) alloca (nargs * sizeof (tree)));
   10816      5948680 :       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      3993541 :           if (TREE_CODE (argarray[j]) == ADDR_EXPR
   10821      3993541 :               && TYPE_REF_P (TREE_TYPE (argarray[j])))
   10822         1512 :             fargs[j] = TREE_OPERAND (argarray[j], 0);
   10823              :           else
   10824      3992029 :             fargs[j] = argarray[j];
   10825              :         }
   10826              : 
   10827      1955139 :       warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn),
   10828              :                                            nargs, fargs, NULL,
   10829              :                                            cp_comp_parm_types);
   10830              :     }
   10831              : 
   10832    314218526 :   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        60718 :       if (!cp_unevaluated_operand
   10838        60457 :           && cand->num_convs
   10839        60457 :           && 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        60703 :       if (ctor_omit_inherited_parms (fn))
   10853    157109248 :         nargs = 2;
   10854              :     }
   10855              : 
   10856              :   /* Avoid actually calling copy constructors and copy assignment operators,
   10857              :      if possible.  */
   10858              : 
   10859    157109248 :   if (!force_elide
   10860    156979497 :       && (!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    156979293 :           || cp_noexcept_operand != 0))
   10865              :     /* Do things the hard way.  */;
   10866    154533292 :   else if (cand->num_convs == 1
   10867    236095832 :            && (DECL_COPY_CONSTRUCTOR_P (fn)
   10868    153165898 :                || DECL_MOVE_CONSTRUCTOR_P (fn)))
   10869              :     {
   10870      7568783 :       tree targ;
   10871      7568783 :       tree arg = argarray[num_artificial_parms_for (fn)];
   10872      7568783 :       tree fa = argarray[0];
   10873      7568783 :       bool trivial = trivial_fn_p (fn);
   10874              : 
   10875              :       /* Pull out the real argument, disregarding const-correctness.  */
   10876      7568783 :       targ = arg;
   10877              :       /* Strip the reference binding for the constructor parameter.  */
   10878            0 :       if (CONVERT_EXPR_P (targ)
   10879      7568783 :           && TYPE_REF_P (TREE_TYPE (targ)))
   10880      7568783 :         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     12529403 :       while ((CONVERT_EXPR_P (targ)
   10884     10545010 :               && !TYPE_REF_P (TREE_TYPE (targ)))
   10885     26198502 :              || TREE_CODE (targ) == NON_LVALUE_EXPR)
   10886      9422837 :         targ = TREE_OPERAND (targ, 0);
   10887      7568783 :       if (TREE_CODE (targ) == ADDR_EXPR)
   10888              :         {
   10889      2293294 :           targ = TREE_OPERAND (targ, 0);
   10890      2293294 :           if (!same_type_ignoring_top_level_qualifiers_p
   10891      2293294 :               (TREE_TYPE (TREE_TYPE (arg)), TREE_TYPE (targ)))
   10892              :             targ = NULL_TREE;
   10893              :         }
   10894              :       else
   10895              :         targ = NULL_TREE;
   10896              : 
   10897      2292847 :       if (targ)
   10898              :         arg = targ;
   10899              :       else
   10900      5275936 :         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      7568783 :       if (CHECKING_P && cxx_dialect >= cxx17)
   10905      7491949 :         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      7568783 :       bool unsafe = unsafe_copy_elision_p_opt (fa, arg);
   10914      7568783 :       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      7568783 :       warning_sentinel s (warn_deprecated_copy, eliding_temp);
   10920      7568783 :       if (force_elide)
   10921              :         /* The language says this isn't called.  */;
   10922      7439032 :       else if (!trivial)
   10923              :         {
   10924      1270385 :           if (!mark_used (fn, complain) && !(complain & tf_error))
   10925            0 :             return error_mark_node;
   10926              :           already_used = true;
   10927              :         }
   10928              :       else
   10929      6168647 :         cp_handle_deprecated_or_unavailable (fn, complain);
   10930              : 
   10931       188940 :       if (eliding_temp && DECL_BASE_CONSTRUCTOR_P (fn)
   10932      7568964 :           && !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      7568783 :       if (is_dummy_object (fa))
   10941              :         {
   10942      5528400 :           if (TREE_CODE (arg) == TARGET_EXPR)
   10943              :             return arg;
   10944      5369511 :           else if (trivial)
   10945      4840481 :             return force_target_expr (DECL_CONTEXT (fn), arg, complain);
   10946              :         }
   10947      2040383 :       else if ((trivial || TREE_CODE (arg) == TARGET_EXPR)
   10948      1305346 :                && !unsafe)
   10949              :         {
   10950      1305258 :           tree to = cp_build_fold_indirect_ref (fa);
   10951      1305258 :           val = cp_build_init_expr (to, arg);
   10952      1305258 :           return val;
   10953              :         }
   10954      7568783 :     }
   10955    146964509 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
   10956      3102431 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR)
   10957    149046695 :            && trivial_fn_p (fn))
   10958              :     {
   10959      1398395 :       tree to = cp_build_fold_indirect_ref (argarray[0]);
   10960      1398395 :       tree type = TREE_TYPE (to);
   10961      1398395 :       tree as_base = CLASSTYPE_AS_BASE (type);
   10962      1398395 :       tree arg = argarray[1];
   10963      1398395 :       location_t loc = cp_expr_loc_or_input_loc (arg);
   10964              : 
   10965      1398395 :       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       227200 :           to = force_lvalue (to, complain);
   10970       227200 :           val = build2 (COMPOUND_EXPR, type, arg, to);
   10971       227200 :           suppress_warning (val, OPT_Wunused);
   10972              :         }
   10973      1171195 :       else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
   10974              :         {
   10975       909200 :           if (is_std_init_list (type)
   10976       909200 :               && 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       909200 :           arg = cp_build_fold_indirect_ref (arg);
   10981       909200 :           val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
   10982              :         }
   10983              :       else
   10984              :         {
   10985              :           /* We must only copy the non-tail padding parts.  */
   10986       261995 :           tree arg0, arg2, t;
   10987       261995 :           tree array_type, alias_set;
   10988              : 
   10989       261995 :           arg2 = TYPE_SIZE_UNIT (as_base);
   10990              :           /* Ensure op= returns an lvalue even if the object argument isn't
   10991              :              one.  */
   10992       261995 :           to = force_lvalue (to, complain);
   10993       261995 :           to = cp_stabilize_reference (to);
   10994       261995 :           arg0 = cp_build_addr_expr (to, complain);
   10995              : 
   10996       261995 :           array_type = build_array_type (unsigned_char_type_node,
   10997              :                                          build_index_type
   10998              :                                            (size_binop (MINUS_EXPR,
   10999              :                                                         arg2, size_int (1))));
   11000       261995 :           alias_set = build_int_cst (build_pointer_type (type), 0);
   11001       261995 :           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       261995 :           val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to);
   11005       261995 :           suppress_warning (val, OPT_Wunused);
   11006              :         }
   11007              : 
   11008      1398395 :       cp_handle_deprecated_or_unavailable (fn, complain);
   11009              : 
   11010      1398395 :       return val;
   11011              :     }
   11012    145566114 :   else if (trivial_fn_p (fn))
   11013              :     {
   11014      7725920 :       if (DECL_DESTRUCTOR_P (fn))
   11015      3154969 :         return build_trivial_dtor_call (argarray[0]);
   11016       707991 :       else if (default_ctor_p (fn))
   11017              :         {
   11018       707991 :           if (is_dummy_object (argarray[0]))
   11019       264750 :             return force_target_expr (DECL_CONTEXT (fn), void_node,
   11020       264750 :                                       no_cleanup_complain);
   11021              :           else
   11022       443241 :             return cp_build_fold_indirect_ref (argarray[0]);
   11023              :         }
   11024              :     }
   11025              : 
   11026    145543265 :   gcc_assert (!force_elide);
   11027              : 
   11028    145543265 :   if (!already_used
   11029    145543265 :       && !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    145542489 :   if (warn_class_memaccess
   11034      1986058 :       && vec_safe_length (args) >= 2
   11035    146502610 :       && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
   11036        69416 :     maybe_warn_class_memaccess (input_location, fn, args);
   11037              : 
   11038    145542489 :   if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
   11039              :     {
   11040       473654 :       tree t;
   11041       473654 :       tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (argarray[0])),
   11042       473654 :                                 DECL_CONTEXT (fn),
   11043              :                                 ba_any, NULL, complain);
   11044       473654 :       gcc_assert (binfo && binfo != error_mark_node);
   11045              : 
   11046       473654 :       argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1,
   11047              :                                      complain);
   11048       473654 :       if (TREE_SIDE_EFFECTS (argarray[0]))
   11049        45638 :         argarray[0] = save_expr (argarray[0]);
   11050       473654 :       t = build_pointer_type (TREE_TYPE (fn));
   11051       473654 :       fn = build_vfn_ref (argarray[0], DECL_VINDEX (fn));
   11052       473654 :       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    145068835 :       auto w = make_temp_override (deprecated_state,
   11060    145068835 :                                    UNAVAILABLE_DEPRECATED_SUPPRESS);
   11061              : 
   11062    145068835 :       fn = build_addr_func (fn, complain);
   11063    145068835 :       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    145068835 :       ADDR_EXPR_DENOTES_CALL_P (fn) = true;
   11069    145068835 :     }
   11070              : 
   11071    145542489 :   tree call = build_cxx_call (fn, nargs, argarray, complain|decltype_flag);
   11072    145542489 :   if (call == error_mark_node)
   11073              :     return call;
   11074    145541638 :   if (cand->flags & LOOKUP_LIST_INIT_CTOR)
   11075              :     {
   11076      1937177 :       tree c = extract_call_expr (call);
   11077              :       /* build_new_op will clear this when appropriate.  */
   11078      1937177 :       CALL_EXPR_ORDERED_ARGS (c) = true;
   11079              :     }
   11080    145541638 :   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    145541385 :   else if (TREE_DEPRECATED (fn)
   11087    145541385 :            && 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         3556 : first_non_static_field (tree type, Predicate pred)
   11107              : {
   11108         3556 :   if (!type || !CLASS_TYPE_P (type))
   11109              :     return NULL_TREE;
   11110              : 
   11111        71398 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   11112              :     {
   11113        68436 :       if (TREE_CODE (field) != FIELD_DECL)
   11114        43330 :         continue;
   11115        25106 :       if (TREE_STATIC (field))
   11116            0 :         continue;
   11117        25106 :       if (pred (field))
   11118              :         return field;
   11119              :     }
   11120              : 
   11121         2962 :   int i = 0;
   11122              : 
   11123         3082 :   for (tree base_binfo, binfo = TYPE_BINFO (type);
   11124         3082 :        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        24356 :   bool operator() (const_tree t) const
   11139              :   {
   11140        24356 :     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         3262 : first_non_public_field (tree type)
   11149              : {
   11150         3262 :   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         5021 : has_trivial_copy_assign_p (tree type, bool access, bool *hasassign)
   11180              : {
   11181         5021 :   tree fns = get_class_binding (type, assign_op_identifier);
   11182         5021 :   bool all_trivial = true;
   11183              : 
   11184              :   /* Iterate over overloads of the assignment operator, checking
   11185              :      accessible copy assignments for triviality.  */
   11186              : 
   11187        16515 :   for (tree f : ovl_range (fns))
   11188              :     {
   11189              :       /* Skip operators that aren't copy assignments.  */
   11190         8571 :       if (!copy_fn_p (f))
   11191         3046 :         continue;
   11192              : 
   11193         5525 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11194         5813 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11195              : 
   11196              :       /* Skip template assignment operators and deleted functions.  */
   11197         5525 :       if (TREE_CODE (f) != FUNCTION_DECL || DECL_DELETED_FN (f))
   11198          694 :         continue;
   11199              : 
   11200         4831 :       if (accessible)
   11201         4579 :         *hasassign = true;
   11202              : 
   11203         4579 :       if (!accessible || !trivial_fn_p (f))
   11204              :         all_trivial = false;
   11205              : 
   11206              :       /* Break early when both properties have been determined.  */
   11207         4831 :       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         5021 :   tree ref = cp_build_reference_type (type, false);
   11214         5021 :   return (all_trivial
   11215         5021 :           && (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         5021 : has_trivial_copy_p (tree type, bool access, bool hasctor[2])
   11227              : {
   11228         5021 :   tree fns = get_class_binding (type, complete_ctor_identifier);
   11229         5021 :   bool all_trivial = true;
   11230              : 
   11231        25141 :   for (tree f : ovl_range (fns))
   11232              :     {
   11233              :       /* Skip template constructors.  */
   11234        12602 :       if (TREE_CODE (f) != FUNCTION_DECL)
   11235          105 :         continue;
   11236              : 
   11237        12497 :       bool cpy_or_move_ctor_p = copy_fn_p (f);
   11238              : 
   11239              :       /* Skip ctors other than default, copy, and move.  */
   11240        12497 :       if (!cpy_or_move_ctor_p && !default_ctor_p (f))
   11241         2757 :         continue;
   11242              : 
   11243         9740 :       if (DECL_DELETED_FN (f))
   11244          306 :         continue;
   11245              : 
   11246         9434 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11247         9626 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11248              : 
   11249         9314 :       if (accessible)
   11250         9314 :         hasctor[cpy_or_move_ctor_p] = true;
   11251              : 
   11252         9434 :       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         9434 :       if (hasctor[0] && hasctor[1] && !all_trivial)
   11257              :         break;
   11258              :     }
   11259              : 
   11260         5021 :   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        69416 : 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        69416 :   unsigned dstidx = DECL_FUNCTION_CODE (fndecl) == BUILT_IN_BCOPY;
   11278        69416 :   unsigned srcidx = !dstidx;
   11279              : 
   11280        69416 :   tree dest = (*args)[dstidx];
   11281        69416 :   if (!TREE_TYPE (dest)
   11282        69416 :       || (TREE_CODE (TREE_TYPE (dest)) != ARRAY_TYPE
   11283        68251 :           && !INDIRECT_TYPE_P (TREE_TYPE (dest))))
   11284        66041 :     return;
   11285              : 
   11286        22361 :   tree srctype = NULL_TREE;
   11287              : 
   11288              :   /* Determine the type of the pointed-to object and whether it's
   11289              :      a complete class type.  */
   11290        22361 :   tree desttype = TREE_TYPE (TREE_TYPE (dest));
   11291              : 
   11292        22361 :   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         5123 :   if (current_function_decl
   11300         5123 :       && DECL_OBJECT_MEMBER_FUNCTION_P (current_function_decl)
   11301         5390 :       && 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         5021 :   bool trivial = trivial_type_p (desttype);
   11315              : 
   11316              :   /* Set to true if DESTYPE has an accessible copy assignment.  */
   11317         5021 :   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         5021 :   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         5021 :   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         5021 :   bool trivcopy = has_trivial_copy_p (desttype, true, hasctors);
   11330              : 
   11331              :   /* Set FLD to the first private/protected member of the class.  */
   11332         5021 :   tree fld = trivial ? first_non_public_field (desttype) : NULL_TREE;
   11333              : 
   11334              :   /* The warning format string.  */
   11335         5021 :   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         5021 :   const char *suggest = "";
   11339         5021 :   bool warned = false;
   11340              : 
   11341         5021 :   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    154146312 : build_cxx_call (tree fn, int nargs, tree *argarray,
   11533              :                 tsubst_flags_t complain, tree orig_fndecl)
   11534              : {
   11535    154146312 :   tree fndecl;
   11536              : 
   11537              :   /* Remember roughly where this call is.  */
   11538    154146312 :   location_t loc = cp_expr_loc_or_input_loc (fn);
   11539    154146312 :   fn = build_call_a (fn, nargs, argarray);
   11540    154146312 :   SET_EXPR_LOCATION (fn, loc);
   11541              : 
   11542    154146312 :   fndecl = get_callee_fndecl (fn);
   11543    154146312 :   if (!orig_fndecl)
   11544    154146312 :     orig_fndecl = fndecl;
   11545              : 
   11546              :   /* Check that arguments to builtin functions match the expectations.  */
   11547    154146312 :   if (fndecl
   11548    147613088 :       && !processing_template_decl
   11549    301706790 :       && 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     20963047 :       for (i = 0; i < nargs; i++)
   11556     13786192 :         argarray[i] = maybe_constant_value (argarray[i]);
   11557              : 
   11558      7176855 :       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      7176051 :       else if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING))
   11563              :         {
   11564        12789 :           tree arg0 = argarray[0];
   11565        12789 :           STRIP_NOPS (arg0);
   11566        12789 :           if (TREE_CODE (arg0) == ADDR_EXPR
   11567          264 :               && DECL_P (TREE_OPERAND (arg0, 0))
   11568        13032 :               && 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        12553 :           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    154145490 :   if (VOID_TYPE_P (TREE_TYPE (fn)))
   11586     35519085 :     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    118626405 :   if (!(complain & tf_decltype))
   11594              :     {
   11595    100784579 :       fn = require_complete_type (fn, complain);
   11596    100784579 :       if (fn == error_mark_node)
   11597              :         return error_mark_node;
   11598    100784553 :       fn = maybe_contract_wrap_call (fndecl, fn);
   11599              : 
   11600    100784553 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (fn)))
   11601              :         {
   11602     11620600 :           fn = build_cplus_new (TREE_TYPE (fn), fn, complain);
   11603     11620600 :           maybe_warn_parm_abi (TREE_TYPE (fn), loc);
   11604              :         }
   11605              :     }
   11606              :   else
   11607     17841826 :     fn = maybe_contract_wrap_call (fndecl, fn);
   11608    118626379 :   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        33652 : in_charge_arg_for_name (tree name)
   11618              : {
   11619        33652 :   if (IDENTIFIER_CTOR_P (name))
   11620              :     {
   11621        19254 :       if (name == complete_ctor_identifier)
   11622         9627 :         return integer_one_node;
   11623         9627 :       gcc_checking_assert (name == base_ctor_identifier);
   11624              :     }
   11625              :   else
   11626              :     {
   11627        14398 :       if (name == complete_dtor_identifier)
   11628         7199 :         return integer_two_node;
   11629         7199 :       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         7199 :       gcc_checking_assert (name == base_dtor_identifier);
   11634              :     }
   11635              : 
   11636        16826 :   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       348923 : check_self_delegation (tree ret)
   11644              : {
   11645       348923 :   if (TREE_CODE (ret) == TARGET_EXPR)
   11646            0 :     ret = TARGET_EXPR_INITIAL (ret);
   11647       348923 :   tree fn = cp_get_callee_fndecl_nofold (ret);
   11648       348923 :   if (fn && DECL_ABSTRACT_ORIGIN (fn) == current_function_decl)
   11649           46 :     error ("constructor delegates to itself");
   11650       348923 : }
   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     37684853 : build_special_member_call (tree instance, tree name, vec<tree, va_gc> **args,
   11667              :                            tree binfo, int flags, tsubst_flags_t complain)
   11668              : {
   11669     37684853 :   tree fns;
   11670              :   /* The type of the subobject to be constructed or destroyed.  */
   11671     37684853 :   tree class_type;
   11672     37684853 :   vec<tree, va_gc> *allocated = NULL;
   11673     37684853 :   tree ret;
   11674              : 
   11675     37684853 :   gcc_assert (IDENTIFIER_CDTOR_P (name) || name == assign_op_identifier);
   11676              : 
   11677     37684853 :   if (error_operand_p (instance))
   11678            0 :     return error_mark_node;
   11679              : 
   11680     37684853 :   if (IDENTIFIER_DTOR_P (name))
   11681              :     {
   11682     10481823 :       gcc_assert (args == NULL || vec_safe_is_empty (*args));
   11683     10481823 :       if (!type_build_dtor_call (TREE_TYPE (instance)))
   11684              :         /* Shortcut to avoid lazy destructor declaration.  */
   11685         9757 :         return build_trivial_dtor_call (instance);
   11686              :     }
   11687              : 
   11688     37675096 :   if (TYPE_P (binfo))
   11689              :     {
   11690              :       /* Resolve the name.  */
   11691     30094984 :       if (!complete_type_or_maybe_complain (binfo, NULL_TREE, complain))
   11692           24 :         return error_mark_node;
   11693              : 
   11694     30094960 :       binfo = TYPE_BINFO (binfo);
   11695              :     }
   11696              : 
   11697     30094960 :   gcc_assert (binfo != NULL_TREE);
   11698              : 
   11699     37675072 :   class_type = BINFO_TYPE (binfo);
   11700              : 
   11701              :   /* Handle the special case where INSTANCE is NULL_TREE.  */
   11702     37675072 :   if (name == complete_ctor_identifier && !instance)
   11703     19767513 :     instance = build_dummy_object (class_type);
   11704              :   else
   11705              :     {
   11706              :       /* Convert to the base class, if necessary.  */
   11707     17907559 :       if (!same_type_ignoring_top_level_qualifiers_p
   11708     17907559 :           (TREE_TYPE (instance), BINFO_TYPE (binfo)))
   11709              :         {
   11710      1560140 :           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      1540949 :             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        19191 :               gcc_checking_assert (name == assign_op_identifier);
   11722        19191 :               instance = build_base_path (PLUS_EXPR, instance,
   11723              :                                           binfo, /*nonnull=*/1, complain);
   11724              :             }
   11725              :         }
   11726              :     }
   11727              : 
   11728     37675072 :   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     37675072 :   if (cxx_dialect >= cxx17
   11736     37480787 :       && args && vec_safe_length (*args) == 1
   11737     60037408 :       && !unsafe_return_slot_p (instance))
   11738              :     {
   11739     21104428 :       tree arg = (**args)[0];
   11740              : 
   11741      1636947 :       if (BRACE_ENCLOSED_INITIALIZER_P (arg)
   11742      1636742 :           && !TYPE_HAS_LIST_CTOR (class_type)
   11743      1570600 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (arg)
   11744     22675014 :           && CONSTRUCTOR_NELTS (arg) == 1)
   11745      1119591 :         arg = CONSTRUCTOR_ELT (arg, 0)->value;
   11746              : 
   11747     21104428 :       if ((TREE_CODE (arg) == TARGET_EXPR
   11748     10234206 :            || TREE_CODE (arg) == CONSTRUCTOR)
   11749     32492080 :           && (same_type_ignoring_top_level_qualifiers_p
   11750     11387652 :               (class_type, TREE_TYPE (arg))))
   11751              :         {
   11752     10275922 :           if (is_dummy_object (instance))
   11753              :             return arg;
   11754       214134 :           else if (TREE_CODE (arg) == TARGET_EXPR)
   11755       214134 :             TARGET_EXPR_DIRECT_INIT_P (arg) = true;
   11756              : 
   11757       214134 :           if ((complain & tf_error)
   11758       214132 :               && (flags & LOOKUP_DELEGATING_CONS))
   11759            0 :             check_self_delegation (arg);
   11760              :           /* Avoid change of behavior on Wunused-var-2.C.  */
   11761       214134 :           instance = mark_lvalue_use (instance);
   11762       214134 :           return cp_build_init_expr (instance, arg);
   11763              :         }
   11764              :     }
   11765              : 
   11766     27399150 :   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     27399150 :   if ((name == base_ctor_identifier
   11772     25108932 :        || name == base_dtor_identifier)
   11773     28940165 :       && CLASSTYPE_VBASECLASSES (class_type))
   11774              :     {
   11775        46906 :       tree vtt;
   11776        46906 :       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        46906 :       vtt = DECL_CHAIN (CLASSTYPE_VTABLES (current_class_type));
   11782        46906 :       vtt = decay_conversion (vtt, complain);
   11783        46906 :       if (vtt == error_mark_node)
   11784            0 :         return error_mark_node;
   11785        46906 :       vtt = build_if_in_charge (vtt, current_vtt_parm);
   11786        46906 :       if (BINFO_SUBVTT_INDEX (binfo))
   11787        46754 :         sub_vtt = fold_build_pointer_plus (vtt, BINFO_SUBVTT_INDEX (binfo));
   11788              :       else
   11789          152 :         sub_vtt = vtt;
   11790              : 
   11791        46906 :       if (args == NULL)
   11792              :         {
   11793        29875 :           allocated = make_tree_vector ();
   11794        29875 :           args = &allocated;
   11795              :         }
   11796              : 
   11797        46906 :       vec_safe_insert (*args, 0, sub_vtt);
   11798              :     }
   11799              : 
   11800     54798300 :   ret = build_new_method_call (instance, fns, args,
   11801     27399150 :                                TYPE_BINFO (BINFO_TYPE (binfo)),
   11802              :                                flags, /*fn=*/NULL,
   11803              :                                complain);
   11804              : 
   11805     27399150 :   if (allocated != NULL)
   11806        29875 :     release_tree_vector (allocated);
   11807              : 
   11808     27399150 :   if ((complain & tf_error)
   11809     24490357 :       && (flags & LOOKUP_DELEGATING_CONS)
   11810       349009 :       && name == complete_ctor_identifier)
   11811       348923 :     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     96093976 : 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     96093976 :   struct z_candidate *candidates = 0, *cand;
   11997     96093976 :   tree explicit_targs = NULL_TREE;
   11998     96093976 :   tree basetype = NULL_TREE;
   11999     96093976 :   tree access_binfo;
   12000     96093976 :   tree optype;
   12001     96093976 :   tree first_mem_arg = NULL_TREE;
   12002     96093976 :   tree name;
   12003     96093976 :   bool skip_first_for_error;
   12004     96093976 :   vec<tree, va_gc> *user_args;
   12005     96093976 :   tree call;
   12006     96093976 :   tree fn;
   12007     96093976 :   int template_only = 0;
   12008     96093976 :   bool any_viable_p;
   12009     96093976 :   tree orig_instance;
   12010     96093976 :   tree orig_fns;
   12011     96093976 :   vec<tree, va_gc> *orig_args = NULL;
   12012              : 
   12013     96093976 :   auto_cond_timevar tv (TV_OVERLOAD);
   12014              : 
   12015     96093976 :   gcc_assert (instance != NULL_TREE);
   12016              : 
   12017              :   /* We don't know what function we're going to call, yet.  */
   12018     96093976 :   if (fn_p)
   12019     26951153 :     *fn_p = NULL_TREE;
   12020              : 
   12021     96093976 :   if (error_operand_p (instance)
   12022     96093976 :       || !fns || error_operand_p (fns))
   12023      1410077 :     return error_mark_node;
   12024              : 
   12025     94683899 :   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     94683899 :   orig_instance = instance;
   12033     94683899 :   orig_fns = fns;
   12034              : 
   12035              :   /* Dismantle the baselink to collect all the information we need.  */
   12036     94683899 :   if (!conversion_path)
   12037     41757655 :     conversion_path = BASELINK_BINFO (fns);
   12038     94683899 :   access_binfo = BASELINK_ACCESS_BINFO (fns);
   12039     94683899 :   optype = BASELINK_OPTYPE (fns);
   12040     94683899 :   fns = BASELINK_FUNCTIONS (fns);
   12041     94683899 :   if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
   12042              :     {
   12043      2542320 :       explicit_targs = TREE_OPERAND (fns, 1);
   12044      2542320 :       fns = TREE_OPERAND (fns, 0);
   12045      2542320 :       template_only = 1;
   12046              :     }
   12047     94683899 :   gcc_assert (OVL_P (fns));
   12048     94683899 :   fn = OVL_FIRST (fns);
   12049     94683899 :   name = DECL_NAME (fn);
   12050              : 
   12051     94683899 :   basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
   12052     94683899 :   gcc_assert (CLASS_TYPE_P (basetype));
   12053              : 
   12054     94683899 :   user_args = args == NULL ? NULL : *args;
   12055              :   /* Under DR 147 A::A() is an invalid constructor call,
   12056              :      not a functional cast.  */
   12057     94683899 :   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     94683845 :   if (processing_template_decl)
   12077      7521214 :     orig_args = args == NULL ? NULL : make_tree_vector_copy (*args);
   12078              : 
   12079              :   /* Process the argument list.  */
   12080     94547159 :   if (args != NULL && *args != NULL)
   12081              :     {
   12082     80637121 :       *args = resolve_args (*args, complain);
   12083     80637121 :       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     94683692 :   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     94683692 :   skip_first_for_error = false;
   12099     94683692 :   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     50341449 :       gcc_assert (name != ctor_identifier);
   12104              : 
   12105              :       /* Remove the VTT pointer, if present.  */
   12106     48051237 :       if ((name == base_ctor_identifier || name == base_dtor_identifier)
   12107     51882464 :           && 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     50341449 :       if (!same_type_p (basetype, TREE_TYPE (instance)))
   12114              :         {
   12115       658790 :           instance = build_this (instance);
   12116       658790 :           instance = build_nop (build_pointer_type (basetype), instance);
   12117       658790 :           instance = build_fold_indirect_ref (instance);
   12118              :         }
   12119              :     }
   12120              :   else
   12121     88684486 :     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    189367384 :   if (DECL_CONSTRUCTOR_P (fn))
   12128              :     /* Constructors don't use the enclosing 'this'.  */
   12129              :     first_mem_arg = instance;
   12130              :   else
   12131     69671721 :     first_mem_arg = maybe_resolve_dummy (instance, false);
   12132              : 
   12133     94683692 :   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     94683692 :   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     94683692 :   if (DECL_CONSTRUCTOR_P (fn)
   12142     21427655 :       && vec_safe_length (user_args) > skip
   12143    113990904 :       && DIRECT_LIST_INIT_P ((*user_args)[skip]))
   12144              :     {
   12145      1639005 :       tree init_list = (*user_args)[skip];
   12146      1639005 :       tree init = NULL_TREE;
   12147              : 
   12148      1639005 :       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      1639005 :       if (CONSTRUCTOR_NELTS (init_list) == 0
   12156       184826 :           && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
   12157              :           /* For a user-provided default constructor, use the normal
   12158              :              mechanisms so that protected access works.  */
   12159       184826 :           && type_has_non_user_provided_default_constructor (basetype)
   12160      1564896 :           && !processing_template_decl)
   12161       110714 :         init = build_value_init (basetype, complain);
   12162              : 
   12163              :       /* If BASETYPE is an aggregate, we need to do aggregate
   12164              :          initialization.  */
   12165      1528291 :       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       110755 :       if (init)
   12172              :         {
   12173       110755 :           if (is_dummy_object (instance))
   12174        31136 :             return get_target_expr (init, complain);
   12175        79619 :           return cp_build_init_expr (instance, init);
   12176              :         }
   12177              : 
   12178              :       /* Otherwise go ahead with overload resolution.  */
   12179      1528250 :       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     93044687 :     add_candidates (fns, first_mem_arg, user_args, optype,
   12186              :                     explicit_targs, template_only, conversion_path,
   12187              :                     access_binfo, flags, &candidates, complain);
   12188              : 
   12189     94572937 :   any_viable_p = false;
   12190     94572937 :   candidates = splice_viable (candidates, false, &any_viable_p);
   12191              : 
   12192     94572937 :   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        23896 :       if (DECL_CONSTRUCTOR_P (fn)
   12205        17858 :           && !(flags & LOOKUP_ONLYCONVERTING)
   12206        17834 :           && cxx_dialect >= cxx20
   12207        17224 :           && CP_AGGREGATE_TYPE_P (basetype)
   12208        23896 :           && !vec_safe_is_empty (user_args))
   12209              :         {
   12210              :           /* Create a CONSTRUCTOR from ARGS, e.g. {1, 2} from <1, 2>.  */
   12211          926 :           tree ctor = build_constructor_from_vec (init_list_type_node,
   12212              :                                                   user_args);
   12213          926 :           CONSTRUCTOR_IS_DIRECT_INIT (ctor) = true;
   12214          926 :           CONSTRUCTOR_IS_PAREN_INIT (ctor) = true;
   12215          926 :           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        22970 :       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        22970 :       call = error_mark_node;
   12232              :     }
   12233              :   else
   12234              :     {
   12235     94549041 :       cand = tourney (candidates, complain);
   12236     94549041 :       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     94548854 :           fn = cand->fn;
   12266     94548854 :           call = NULL_TREE;
   12267              : 
   12268     94548854 :           if (!(flags & LOOKUP_NONVIRTUAL)
   12269     72539350 :               && DECL_PURE_VIRTUAL_P (fn)
   12270       198890 :               && instance == current_class_ref
   12271     94704399 :               && (complain & tf_warning))
   12272              :             {
   12273              :               /* This is not an error, it is runtime undefined
   12274              :                  behavior.  */
   12275       155545 :               if (!current_function_decl)
   12276            3 :                 warning (0, "pure virtual %q#D called from "
   12277              :                          "non-static data member initializer", fn);
   12278       155542 :               else if (DECL_CONSTRUCTOR_P (current_function_decl)
   12279       155542 :                        || 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    108400493 :           if (DECL_OBJECT_MEMBER_FUNCTION_P (fn)
   12287    161396368 :               && !DECL_CONSTRUCTOR_P (fn)
   12288    150363816 :               && is_dummy_object (instance))
   12289              :             {
   12290        49468 :               instance = maybe_resolve_dummy (instance, true);
   12291        49468 :               if (instance == error_mark_node)
   12292              :                 call = error_mark_node;
   12293        49468 :               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        49097 :                   cand->first_arg = instance;
   12298              :                 }
   12299          371 :               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          333 :                   if (complain & tf_error)
   12305           60 :                     error ("cannot call member function %qD without object",
   12306              :                            fn);
   12307          333 :                   call = error_mark_node;
   12308              :                 }
   12309              :             }
   12310              : 
   12311     94548854 :           if (call != error_mark_node)
   12312              :             {
   12313              :               /* Now we know what function is being called.  */
   12314     94548521 :               if (fn_p)
   12315     25528154 :                 *fn_p = fn;
   12316              :               /* Build the actual CALL_EXPR.  */
   12317     94548521 :               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     94548521 :               if (TREE_CODE (call) == MODIFY_EXPR)
   12322      3173455 :                 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     94548521 :               if (!is_dummy_object (instance))
   12328     73448741 :                 call = keep_unused_object_arg (call, instance, fn);
   12329     94548521 :               if (call != error_mark_node
   12330    187191016 :                   && DECL_DESTRUCTOR_P (cand->fn)
   12331    119877332 :                   && !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     14645496 :                 call = build_nop (void_type_node, call);
   12343              :             }
   12344              :         }
   12345              :     }
   12346              : 
   12347     94572011 :   if (processing_template_decl && call != error_mark_node)
   12348              :     {
   12349      7521162 :       bool cast_to_void = false;
   12350              : 
   12351      7521162 :       if (TREE_CODE (call) == COMPOUND_EXPR)
   12352            8 :         call = TREE_OPERAND (call, 1);
   12353      7521154 :       else if (TREE_CODE (call) == NOP_EXPR)
   12354              :         {
   12355            0 :           cast_to_void = true;
   12356            0 :           call = TREE_OPERAND (call, 0);
   12357              :         }
   12358      7521162 :       if (INDIRECT_REF_P (call))
   12359       588851 :         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      7521162 :       if (really_overloaded_fn (fns))
   12364              :         {
   12365      1835639 :           if (DECL_TEMPLATE_INFO (fn)
   12366      1835639 :               && 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       266465 :               if (OVL_SINGLE_P (fns))
   12373              :                 /* If the original overload set consists of a single function
   12374              :                    template, this isn't beneficial.  */
   12375       228240 :                 goto skip_prune;
   12376              : 
   12377        38225 :               fn = ovl_make (DECL_TI_TEMPLATE (fn));
   12378        38225 :               if (template_only)
   12379        28924 :                 fn = lookup_template_function (fn, explicit_targs);
   12380              :             }
   12381      1607399 :           orig_fns = copy_node (orig_fns);
   12382      1607399 :           BASELINK_FUNCTIONS (orig_fns) = fn;
   12383      1607399 :           BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (orig_fns) = true;
   12384              :         }
   12385              : 
   12386      5685523 : skip_prune:
   12387      7521162 :       call = (build_min_non_dep_call_vec
   12388      7521162 :               (call,
   12389      7521162 :                build_min (COMPONENT_REF, TREE_TYPE (CALL_EXPR_FN (call)),
   12390              :                           orig_instance, orig_fns, NULL_TREE),
   12391              :                orig_args));
   12392      7521162 :       SET_EXPR_LOCATION (call, input_location);
   12393      7521162 :       call = convert_from_reference (call);
   12394      7521162 :       if (cast_to_void)
   12395            0 :         call = build_nop (void_type_node, call);
   12396              :     }
   12397              : 
   12398     94572011 :   if (orig_args != NULL)
   12399      7384522 :     release_tree_vector (orig_args);
   12400              : 
   12401              :   return call;
   12402     96093976 : }
   12403              : 
   12404              : /* Returns true iff standard conversion sequence ICS1 is a proper
   12405              :    subsequence of ICS2.  */
   12406              : 
   12407              : static bool
   12408     75475535 : 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     75475535 :   while (ics1->kind == ck_rvalue
   12415     87484027 :          || ics1->kind == ck_lvalue)
   12416     12008492 :     ics1 = next_conversion (ics1);
   12417              : 
   12418              :   while (1)
   12419              :     {
   12420     98830425 :       while (ics2->kind == ck_rvalue
   12421     98830425 :              || ics2->kind == ck_lvalue)
   12422     12008492 :         ics2 = next_conversion (ics2);
   12423              : 
   12424     86821933 :       if (ics2->kind == ck_user
   12425     86821933 :           || !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     11350715 :       ics2 = next_conversion (ics2);
   12433              : 
   12434     11350715 :       while (ics2->kind == ck_rvalue
   12435     17815675 :              || ics2->kind == ck_lvalue)
   12436      6464960 :         ics2 = next_conversion (ics2);
   12437              : 
   12438     11350715 :       if (ics2->kind == ics1->kind
   12439         4362 :           && same_type_p (ics2->type, ics1->type)
   12440     11355032 :           && (ics1->kind == ck_identity
   12441         4317 :               || same_type_p (next_conversion (ics2)->type,
   12442              :                               next_conversion (ics1)->type)))
   12443         4317 :         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    372708332 : is_properly_derived_from (tree derived, tree base)
   12452              : {
   12453    372708332 :   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    353528694 :   return (!same_type_ignoring_top_level_qualifiers_p (derived, base)
   12459    353528694 :           && 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    157541872 : maybe_handle_implicit_object (conversion **ics)
   12470              : {
   12471    157541872 :   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     12936068 :       conversion *t = *ics;
   12481     12936068 :       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     12936068 :       reference_type = TREE_TYPE (t->type);
   12487     12936068 :       reference_type = build_reference_type (reference_type);
   12488              : 
   12489     12936068 :       if (t->kind == ck_qual)
   12490      3263250 :         t = next_conversion (t);
   12491     12936068 :       if (t->kind == ck_ptr)
   12492       584883 :         t = next_conversion (t);
   12493     12936068 :       t = build_identity_conv (TREE_TYPE (t->type), NULL_TREE);
   12494     12936068 :       t = direct_reference_binding (reference_type, t);
   12495     12936068 :       t->this_p = 1;
   12496     12936068 :       t->rvaluedness_matches_p = 0;
   12497     12936068 :       *ics = t;
   12498              :     }
   12499    157541872 : }
   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    157541872 : maybe_handle_ref_bind (conversion **ics)
   12507              : {
   12508    157541872 :   if ((*ics)->kind == ck_ref_bind)
   12509              :     {
   12510     61589228 :       conversion *old_ics = *ics;
   12511     61589228 :       *ics = next_conversion (old_ics);
   12512     61589228 :       (*ics)->user_conv_p = old_ics->user_conv_p;
   12513     61589228 :       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     32272888 : conv_binds_to_array_of_unknown_bound (conversion *c)
   12554              : {
   12555              :   /* ck_ref_bind won't have the reference stripped.  */
   12556     32272888 :   tree type = non_reference (c->type);
   12557              :   /* ck_qual won't have the pointer stripped.  */
   12558     32272888 :   type = strip_pointer_operator (type);
   12559     32272888 :   return (TREE_CODE (type) == ARRAY_TYPE
   12560     32272888 :           && 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     78770977 : compare_ics (conversion *ics1, conversion *ics2)
   12572              : {
   12573     78770977 :   tree from_type1;
   12574     78770977 :   tree from_type2;
   12575     78770977 :   tree to_type1;
   12576     78770977 :   tree to_type2;
   12577     78770977 :   tree deref_from_type1 = NULL_TREE;
   12578     78770977 :   tree deref_from_type2 = NULL_TREE;
   12579     78770977 :   tree deref_to_type1 = NULL_TREE;
   12580     78770977 :   tree deref_to_type2 = NULL_TREE;
   12581     78770977 :   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     78770977 :   conversion *ref_conv1;
   12587     78770977 :   conversion *ref_conv2;
   12588              : 
   12589              :   /* Compare badness before stripping the reference conversion.  */
   12590     78770977 :   if (ics1->bad_p > ics2->bad_p)
   12591              :     return -1;
   12592     78770963 :   else if (ics1->bad_p < ics2->bad_p)
   12593              :     return 1;
   12594              : 
   12595              :   /* Handle implicit object parameters.  */
   12596     78770936 :   maybe_handle_implicit_object (&ics1);
   12597     78770936 :   maybe_handle_implicit_object (&ics2);
   12598              : 
   12599              :   /* Handle reference parameters.  */
   12600     78770936 :   ref_conv1 = maybe_handle_ref_bind (&ics1);
   12601     78770936 :   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     78770936 :   if (ics1->kind == ck_list && ics2->kind != ck_list)
   12607              :     return 1;
   12608     78770435 :   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     78770190 :   rank1 = BAD_CONVERSION_RANK (ics1);
   12629     78770190 :   rank2 = BAD_CONVERSION_RANK (ics2);
   12630              : 
   12631     78770190 :   if (rank1 > rank2)
   12632              :     return -1;
   12633     68227995 :   else if (rank1 < rank2)
   12634              :     return 1;
   12635              : 
   12636     38135640 :   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     38135594 :   if (ics1->user_conv_p || ics1->kind == ck_list
   12653     37480095 :       || ics1->kind == ck_aggr || ics2->kind == ck_aggr)
   12654              :     {
   12655       655568 :       conversion *t1 = strip_standard_conversion (ics1);
   12656       655568 :       conversion *t2 = strip_standard_conversion (ics2);
   12657              : 
   12658       655568 :       if (!t1 || !t2 || t1->kind != t2->kind)
   12659              :         return 0;
   12660       655549 :       else if (t1->kind == ck_user)
   12661              :         {
   12662       642244 :           tree f1 = t1->cand ? t1->cand->fn : t1->type;
   12663       642244 :           tree f2 = t2->cand ? t2->cand->fn : t2->type;
   12664       642244 :           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        13305 :       else if (t1->kind == ck_aggr
   12676        12512 :                && TREE_CODE (t1->type) == ARRAY_TYPE
   12677           66 :                && TREE_CODE (t2->type) == ARRAY_TYPE
   12678        13371 :                && 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        13242 :           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       652785 :       from_type1 = t1->type;
   12707       652785 :       from_type2 = t2->type;
   12708       652785 :     }
   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     52478725 :       while (t1->kind != ck_identity)
   12729     14998699 :         t1 = next_conversion (t1);
   12730     37480026 :       from_type1 = t1->type;
   12731              : 
   12732     37480026 :       t2 = ics2;
   12733     52377656 :       while (t2->kind != ck_identity)
   12734     14897630 :         t2 = next_conversion (t2);
   12735     37480026 :       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     38132811 :   if (same_type_p (from_type1, from_type2))
   12743              :     {
   12744     37739897 :       if (is_subseq (ics1, ics2))
   12745              :         return 1;
   12746     37735638 :       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     38128494 :   if (ics1->rank < ics2->rank)
   12770              :     return 1;
   12771     38128414 :   else if (ics2->rank < ics1->rank)
   12772              :     return -1;
   12773              : 
   12774     38128414 :   to_type1 = ics1->type;
   12775     38128414 :   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     38128414 :   if (same_type_p (from_type1, from_type2)
   12780     37735500 :       && ARITHMETIC_TYPE_P (from_type1)
   12781      7361919 :       && ARITHMETIC_TYPE_P (to_type1)
   12782      7361752 :       && ARITHMETIC_TYPE_P (to_type2)
   12783     38128414 :       && ((TREE_CODE (to_type1) == COMPLEX_TYPE)
   12784      7361710 :           != (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     38128308 :   {
   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     38128308 :     tree fp1 = from_type1;
   12802     38128308 :     tree fp2 = to_type1;
   12803     38128308 :     tree fp3 = from_type2;
   12804     38128308 :     tree t3 = to_type2;
   12805     38128308 :     int ret = 1;
   12806     38128308 :     if (TYPE_MAIN_VARIANT (fp2) == TYPE_MAIN_VARIANT (t3))
   12807              :       {
   12808     33501859 :         std::swap (fp1, fp2);
   12809     33501859 :         std::swap (fp3, t3);
   12810              :       }
   12811     38128308 :     if (TYPE_MAIN_VARIANT (fp1) == TYPE_MAIN_VARIANT (fp3)
   12812     38128223 :         && 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     42273021 :         && (extended_float_type_p (fp1)
   12820      4090991 :             || (SCALAR_FLOAT_TYPE_P (fp2) && extended_float_type_p (fp2))
   12821      4023791 :             || (SCALAR_FLOAT_TYPE_P (t3) && extended_float_type_p (t3))))
   12822              :       {
   12823       120922 :         if (TREE_CODE (fp2) != REAL_TYPE)
   12824              :           {
   12825        23920 :             ret = -ret;
   12826        23920 :             std::swap (fp2, t3);
   12827              :           }
   12828       120922 :         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       107849 :             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        70076 :                 if (TREE_CODE (t3) != REAL_TYPE
   12839        70076 :                     || !IN_RANGE (cp_compare_floating_point_conversion_ranks
   12840              :                                                                 (fp1, t3),
   12841              :                                   -1, 1))
   12842              :                   /* FP1 <-> FP2 conversion is better.  */
   12843        69606 :                   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        37773 :             else if (SCALAR_FLOAT_TYPE_P (t3)
   12856        37773 :                      && 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         7597 :               return -ret;
   12863              :           }
   12864              :       }
   12865              :   }
   12866              : 
   12867     38051105 :   if (TYPE_PTR_P (from_type1)
   12868      3800055 :       && TYPE_PTR_P (from_type2)
   12869      3800039 :       && TYPE_PTR_P (to_type1)
   12870      3800015 :       && TYPE_PTR_P (to_type2))
   12871              :     {
   12872      3800015 :       deref_from_type1 = TREE_TYPE (from_type1);
   12873      3800015 :       deref_from_type2 = TREE_TYPE (from_type2);
   12874      3800015 :       deref_to_type1 = TREE_TYPE (to_type1);
   12875      3800015 :       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     34251090 :            || (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      3800510 :   if (deref_from_type1 != NULL_TREE
   12895      3800510 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type1))
   12896       293743 :       && 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       293743 :       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       293729 :       else if (VOID_TYPE_P (deref_to_type1)
   12917       293686 :                || 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       293682 :       else if (RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type1))
   12934       293682 :                && 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       293682 :           if (same_type_p (deref_from_type1, deref_from_type2))
   12947              :             {
   12948       293676 :               if (is_properly_derived_from (deref_to_type1,
   12949              :                                             deref_to_type2))
   12950              :                 return 1;
   12951       293676 :               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     75514724 :   else if (CLASS_TYPE_P (non_reference (from_type1))
   12967     62520448 :            && same_type_p (from_type1, from_type2))
   12968              :     {
   12969     24427872 :       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     24427872 :       if (is_properly_derived_from (from, to_type1)
   12979     24427872 :           && is_properly_derived_from (from, to_type2))
   12980              :         {
   12981       939568 :           if (is_properly_derived_from (to_type1, to_type2))
   12982              :             return 1;
   12983       935953 :           else if (is_properly_derived_from (to_type2, to_type1))
   12984              :             return -1;
   12985              :         }
   12986              :     }
   12987     26658980 :   else if (CLASS_TYPE_P (non_reference (to_type1))
   12988     13664704 :            && 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     37957356 :   if (ics1->kind == ck_qual
   13016          351 :       && ics2->kind == ck_qual
   13017     37957707 :       && 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     37957270 :   if (ref_conv1 && ref_conv2)
   13046              :     {
   13047     18825474 :       if (!ref_conv1->this_p && !ref_conv2->this_p
   13048     18594910 :           && (ref_conv1->rvaluedness_matches_p
   13049     18594910 :               != ref_conv2->rvaluedness_matches_p)
   13050     34323416 :           && (same_type_p (ref_conv1->type, ref_conv2->type)
   13051      9093535 :               || (TYPE_REF_IS_RVALUE (ref_conv1->type)
   13052      9093535 :                   != TYPE_REF_IS_RVALUE (ref_conv2->type))))
   13053              :         {
   13054      9093263 :           if (ref_conv1->bad_p
   13055      9093263 :               && !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      9091804 :           return (ref_conv1->rvaluedness_matches_p
   13061      9091804 :                   - ref_conv2->rvaluedness_matches_p);
   13062              :         }
   13063              : 
   13064     16136615 :       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     16136184 :           bool c1 = conv_binds_to_array_of_unknown_bound (ref_conv1);
   13082     16136184 :           bool c2 = conv_binds_to_array_of_unknown_bound (ref_conv2);
   13083     16136184 :           if (c1 && !c2)
   13084              :             return -1;
   13085     16136178 :           else if (!c1 && c2)
   13086              :             return 1;
   13087              : 
   13088     16136178 :           int q1 = cp_type_quals (TREE_TYPE (ref_conv1->type));
   13089     16136178 :           int q2 = cp_type_quals (TREE_TYPE (ref_conv2->type));
   13090     16136178 :           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     16136178 :           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     12727823 :   if (ics1->rank == cr_promotion
   13109          144 :       && ics2->rank == cr_promotion
   13110          144 :       && UNSCOPED_ENUM_P (from_type1)
   13111           27 :       && ENUM_FIXED_UNDERLYING_TYPE_P (from_type1)
   13112     12727847 :       && 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       844964 : joust_maybe_elide_copy (z_candidate *cand)
   13159              : {
   13160       844964 :   tree fn = cand->fn;
   13161      2120698 :   if (!DECL_COPY_CONSTRUCTOR_P (fn) && !DECL_MOVE_CONSTRUCTOR_P (fn))
   13162       430689 :     return false;
   13163       414275 :   conversion *conv = cand->convs[0];
   13164       414275 :   if (conv->kind == ck_ambig)
   13165              :     return false;
   13166       414273 :   gcc_checking_assert (conv->kind == ck_ref_bind);
   13167       414273 :   conv = next_conversion (conv);
   13168       414273 :   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       284291 : class_of_implicit_object (z_candidate *cand)
   13183              : {
   13184       284291 :   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       284291 :   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       284291 :   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       534311 : reversed_match (z_candidate *c1, z_candidate *c2)
   13208              : {
   13209       534311 :   tree fn1 = c1->fn;
   13210       534311 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (c2->fn));
   13211       534311 :   tree parm2 = TREE_VALUE (TREE_CHAIN (parms2));
   13212       534311 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn1))
   13213              :     {
   13214       284291 :       tree ctx = class_of_implicit_object (c1);
   13215       284291 :       return iobj_parm_corresponds_to (fn1, parm2, ctx);
   13216              :     }
   13217              :   else
   13218              :     {
   13219       250020 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13220       250020 :       tree parm1 = TREE_VALUE (parms1);
   13221       250020 :       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      4652055 : cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
   13233              : {
   13234      4652055 :   tree fn1 = c1->fn;
   13235      4652055 :   tree fn2 = c2->fn;
   13236      4652055 :   bool reversed = (match_kind == pmatch::current
   13237      4652055 :                    && c1->reversed () != c2->reversed ());
   13238      4652055 :   if (fn1 == fn2 && !reversed)
   13239              :     return true;
   13240      4651806 :   if (identifier_p (fn1) || identifier_p (fn2))
   13241              :     return false;
   13242      4651789 :   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      4651777 :   tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13261      4651777 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2));
   13262              : 
   13263      9095272 :   if (DECL_FUNCTION_MEMBER_P (fn1)
   13264      4652190 :       && DECL_FUNCTION_MEMBER_P (fn2))
   13265              :     {
   13266       208681 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (fn1));
   13267       208681 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (fn2));
   13268       208681 :       if (base1 != base2)
   13269       142605 :         return false;
   13270              : 
   13271       208504 :       if (reversed)
   13272       142428 :         return (reversed_match (c1, c2)
   13273       142428 :                 && reversed_match (c2, c1));
   13274              : 
   13275              :       /* Use object_parms_correspond to simplify comparing iobj/xobj/static
   13276              :          member functions.  */
   13277        66076 :       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       198228 :       auto skip_parms = [] (tree fn, tree parms)
   13283              :         {
   13284       132152 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   13285          680 :             return TREE_CHAIN (parms);
   13286              :           else
   13287       131472 :             return skip_artificial_parms_for (fn, parms);
   13288              :         };
   13289        66076 :       parms1 = skip_parms (fn1, parms1);
   13290        66076 :       parms2 = skip_parms (fn2, parms2);
   13291              :     }
   13292      4443096 :   else if (reversed)
   13293       124991 :     return (reversed_match (c1, c2)
   13294       124991 :             && reversed_match (c2, c1));
   13295      4384181 :   return compparms (parms1, parms2);
   13296              : }
   13297              : 
   13298              : /* True iff FN is a copy or move constructor or assignment operator.  */
   13299              : 
   13300              : static bool
   13301     20998964 : sfk_copy_or_move (tree fn)
   13302              : {
   13303     20998964 :   if (TREE_CODE (fn) != FUNCTION_DECL)
   13304              :     return false;
   13305     20998874 :   special_function_kind sfk = special_function_p (fn);
   13306     20998874 :   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     74407775 : joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn,
   13318              :        tsubst_flags_t complain)
   13319              : {
   13320     74407775 :   int winner = 0;
   13321     74407775 :   int off1 = 0, off2 = 0;
   13322     74407775 :   size_t i;
   13323     74407775 :   size_t len;
   13324              : 
   13325              :   /* Candidates that involve bad conversions are always worse than those
   13326              :      that don't.  */
   13327     74407775 :   if (cand1->viable > cand2->viable)
   13328              :     return 1;
   13329     60077382 :   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     60077382 :   if (cand1->fn == cand2->fn
   13335      2161499 :       && cand1->reversed () == cand2->reversed ()
   13336     60867102 :       && (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     60077382 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13344     55929054 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13345    115999307 :       && DECL_DELETED_FN (cand1->fn) != DECL_DELETED_FN (cand2->fn))
   13346              :     {
   13347      2363965 :       if (DECL_DELETED_FN (cand1->fn) && DECL_DEFAULTED_FN (cand1->fn)
   13348      1967951 :           && move_fn_p (cand1->fn))
   13349              :         return -1;
   13350      3532723 :       if (DECL_DELETED_FN (cand2->fn) && DECL_DEFAULTED_FN (cand2->fn)
   13351      2873570 :           && 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     60063825 :   len = cand1->num_convs;
   13368     60063825 :   if (len != cand2->num_convs)
   13369              :     {
   13370          439 :       int static_1 = (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13371          439 :                       && DECL_STATIC_FUNCTION_P (cand1->fn));
   13372          439 :       int static_2 = (TREE_CODE (cand2->fn) == FUNCTION_DECL
   13373          439 :                       && DECL_STATIC_FUNCTION_P (cand2->fn));
   13374              : 
   13375          439 :       if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13376          139 :           && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13377          139 :           && DECL_CONSTRUCTOR_P (cand1->fn)
   13378          445 :           && 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          433 :       gcc_assert (static_1 != static_2);
   13384              : 
   13385          433 :       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          387 :           if (CONVERSION_RANK (cand1->convs[0]) >= cr_user)
   13399          300 :             winner = -1;
   13400          387 :           off1 = 1;
   13401          387 :           --len;
   13402              :         }
   13403              :     }
   13404              : 
   13405    138783209 :   for (i = 0; i < len; ++i)
   13406              :     {
   13407     78720631 :       conversion *t1 = cand1->convs[i + off1];
   13408     78720631 :       conversion *t2 = cand2->convs[i + off2];
   13409     78720631 :       int comp = compare_ics (t1, t2);
   13410              : 
   13411     78720631 :       if (comp != 0)
   13412              :         {
   13413     53432034 :           if ((complain & tf_warning)
   13414     43956165 :               && 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     53432065 :               && (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     53432034 :           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     60062578 :   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     48479648 :       && winner && warn_conversion && cand1->second_conv && cand2->second_conv
   13512           54 :       && (!DECL_CONSTRUCTOR_P (cand1->fn) || !DECL_CONSTRUCTOR_P (cand2->fn))
   13513     60062605 :       && 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     60062578 :   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     10499622 :   if (cand1->second_conv)
   13576              :     {
   13577        50319 :       winner = compare_ics (cand1->second_conv, cand2->second_conv);
   13578        50319 :       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     10499482 :   {
   13585     10499482 :     z_candidate *sp = nullptr;
   13586     10499482 :     if (sfk_copy_or_move (cand1->fn))
   13587          536 :       sp = cand1;
   13588     10499482 :     if (sfk_copy_or_move (cand2->fn))
   13589       949827 :       sp = sp ? nullptr : cand2;
   13590     10499433 :     if (sp)
   13591              :       {
   13592      1900530 :         conversion *conv = sp->convs[!DECL_CONSTRUCTOR_P (sp->fn)];
   13593       950265 :         if (conv->user_conv_p)
   13594         1330 :           for (; conv; conv = next_conversion (conv))
   13595         1196 :             if (conv->kind == ck_user
   13596          531 :                 && DECL_P (conv->cand->fn)
   13597         1727 :                 && DECL_NONCONVERTING_P (conv->cand->fn))
   13598          403 :               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      6550158 :   if (len == 1 && cxx_dialect >= cxx17
   13610      6535948 :       && DECL_P (cand1->fn)
   13611      6535948 :       && DECL_COMPLETE_CONSTRUCTOR_P (cand1->fn)
   13612     11379032 :       && !(cand1->flags & LOOKUP_ONLYCONVERTING))
   13613              :     {
   13614       422482 :       bool elided1 = joust_maybe_elide_copy (cand1);
   13615       422482 :       bool elided2 = joust_maybe_elide_copy (cand2);
   13616       422482 :       winner = elided1 - elided2;
   13617       422482 :       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     10499068 :   if (!cand1->template_decl && cand2->template_decl)
   13626              :     return 1;
   13627     10409215 :   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      9150903 :   if (cand1->template_decl && cand2->template_decl)
   13636              :     {
   13637      4487349 :       winner = more_specialized_fn
   13638      4487349 :         (TI_TEMPLATE (cand1->template_decl),
   13639      4487349 :          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      8974698 :          cand1->num_convs + DECL_CONSTRUCTOR_P (cand1->fn));
   13645      4487349 :       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      6110027 :   if (flag_concepts && DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13658      6109979 :       && !cand1->template_decl && !cand2->template_decl
   13659     10773938 :       && cand_parms_match (cand1, cand2, pmatch::current))
   13660              :     {
   13661       383057 :       winner = more_constrained (cand1->fn, cand2->fn);
   13662       383057 :       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      6115817 :   if (cand1->rewritten ())
   13670              :     {
   13671      1603100 :       if (!cand2->rewritten ())
   13672              :         return -1;
   13673      1049778 :       if (!cand1->reversed () && cand2->reversed ())
   13674              :         return 1;
   13675      1049778 :       if (cand1->reversed () && !cand2->reversed ())
   13676              :         return -1;
   13677              :     }
   13678      4512717 :   else if (cand2->rewritten ())
   13679              :     return 1;
   13680              : 
   13681      4449364 :   if (deduction_guide_p (cand1->fn))
   13682              :     {
   13683         3054 :       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         3054 :       bool inherited1 = inherited_guide_p (cand1->fn);
   13691         3054 :       bool inherited2 = inherited_guide_p (cand2->fn);
   13692         3054 :       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         3017 :       int art1 = DECL_ARTIFICIAL (cand1->fn);
   13713         3017 :       int art2 = DECL_ARTIFICIAL (cand2->fn);
   13714         3017 :       if (art1 != art2)
   13715         1052 :         return art2 - art1;
   13716              : 
   13717         1965 :       if (art1)
   13718              :         {
   13719              :           /* Prefer the special copy guide over a declared copy/move
   13720              :              constructor.  */
   13721         1962 :           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     13338844 :   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      4446264 :   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     17361463 :           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      4446240 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13802      4446218 :       && DECL_FUNCTION_VERSIONED (cand1->fn)
   13803          902 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13804      4447142 :       && 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      4445316 :   if (DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13833      8890654 :       && 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      4446273 : 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      4446273 :   if (!pedantic && (complain & tf_warning_or_error))
   13893              :     {
   13894              :       conversion_rank rank1 = cr_identity, rank2 = cr_identity;
   13895      9429702 :       struct z_candidate *w = 0, *l = 0;
   13896              : 
   13897      9429702 :       for (i = 0; i < len; ++i)
   13898              :         {
   13899      5184539 :           if (CONVERSION_RANK (cand1->convs[i+off1]) > rank1)
   13900      4161971 :             rank1 = CONVERSION_RANK (cand1->convs[i+off1]);
   13901      5184539 :           if (CONVERSION_RANK (cand2->convs[i + off2]) > rank2)
   13902      4161988 :             rank2 = CONVERSION_RANK (cand2->convs[i + off2]);
   13903              :         }
   13904      4245163 :       if (rank1 < rank2)
   13905           56 :         winner = 1, w = cand1, l = cand2;
   13906      4245163 :       if (rank1 > rank2)
   13907              :         winner = -1, w = cand2, l = cand1;
   13908      4245055 :       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    224185555 : tourney (struct z_candidate *candidates, tsubst_flags_t complain)
   13943              : {
   13944    224185555 :   struct z_candidate **champ = &candidates, **challenger;
   13945    224185555 :   int fate;
   13946    224185555 :   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    288245792 :   for (challenger = &candidates->next; *challenger && (*challenger)->viable; )
   13952              :     {
   13953     64070206 :       fate = joust (*champ, *challenger, 0, complain);
   13954     64070206 :       if (fate == 1)
   13955     41146490 :         challenger = &(*challenger)->next;
   13956     22923716 :       else if (fate == -1)
   13957              :         {
   13958     18479307 :           previous_worse_champ = *champ;
   13959     18479307 :           champ = challenger;
   13960     18479307 :           challenger = &(*challenger)->next;
   13961              :         }
   13962              :       else
   13963              :         {
   13964      4444409 :           previous_worse_champ = nullptr;
   13965      4444409 :           champ = &(*challenger)->next;
   13966      4444409 :           if (!*champ || !(*champ)->viable
   13967      4434534 :               || (*champ)->viable < (*challenger)->viable)
   13968              :             {
   13969              :               champ = nullptr;
   13970              :               break;
   13971              :             }
   13972      4434440 :           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    224185555 :   if (champ)
   13980     27620115 :     for (challenger = &candidates;
   13981    251795701 :          challenger != champ;
   13982     27620115 :          challenger = &(*challenger)->next)
   13983              :       {
   13984     27622015 :         if (*challenger == previous_worse_champ)
   13985              :           /* We already know this candidate is worse than the champ.  */
   13986     17284495 :           continue;
   13987     10337520 :         fate = joust (*champ, *challenger, 0, complain);
   13988     10337520 :         if (fate != 1)
   13989              :           {
   13990              :             champ = nullptr;
   13991              :             break;
   13992              :           }
   13993              :       }
   13994              : 
   13995    224175586 :   if (!champ)
   13996        11869 :     return nullptr;
   13997              : 
   13998              :   /* Move the champ to the front of the candidate list.  */
   13999              : 
   14000    224173686 :   if (champ != &candidates)
   14001              :     {
   14002     18881089 :       z_candidate *saved_champ = *champ;
   14003     18881089 :       *champ = saved_champ->next;
   14004     18881089 :       saved_champ->next = candidates;
   14005     18881089 :       candidates = saved_champ;
   14006              :     }
   14007              : 
   14008    224173686 :   return candidates;
   14009              : }
   14010              : 
   14011              : /* Returns nonzero if things of type FROM can be converted to TO.  */
   14012              : 
   14013              : bool
   14014      4216069 : can_convert (tree to, tree from, tsubst_flags_t complain)
   14015              : {
   14016      4216069 :   tree arg = NULL_TREE;
   14017              :   /* implicit_conversion only considers user-defined conversions
   14018              :      if it has an expression for the call argument list.  */
   14019      4216069 :   if (CLASS_TYPE_P (from) || CLASS_TYPE_P (to))
   14020          109 :     arg = build_stub_object (from);
   14021      4216069 :   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      5074942 : can_convert_arg (tree to, tree from, tree arg, int flags,
   14037              :                  tsubst_flags_t complain)
   14038              : {
   14039      5074942 :   conversion *t;
   14040      5074942 :   bool ok_p;
   14041              : 
   14042      5074942 :   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      5074942 :   push_deferring_access_checks (dk_deferred);
   14048              : 
   14049              :   /* Handle callers like check_local_shadow forgetting to
   14050              :      convert_from_reference.  */
   14051      5074942 :   if (TYPE_REF_P (from) && arg)
   14052              :     {
   14053           52 :       arg = convert_from_reference (arg);
   14054           52 :       from = TREE_TYPE (arg);
   14055              :     }
   14056              : 
   14057      5074942 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   14058              :                             flags, complain);
   14059      5074942 :   ok_p = (t && !t->bad_p);
   14060              : 
   14061              :   /* Discard the access checks now.  */
   14062      5074942 :   pop_deferring_access_checks ();
   14063              : 
   14064     10149884 :   return ok_p;
   14065      5074942 : }
   14066              : 
   14067              : /* Like can_convert_arg, but allows dubious conversions as well.  */
   14068              : 
   14069              : bool
   14070    173086883 : can_convert_arg_bad (tree to, tree from, tree arg, int flags,
   14071              :                      tsubst_flags_t complain)
   14072              : {
   14073    173086883 :   conversion *t;
   14074              : 
   14075    173086883 :   conversion_obstack_sentinel cos;
   14076              :   /* Try to perform the conversion.  */
   14077    173086883 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   14078              :                             flags, complain);
   14079              : 
   14080    346173766 :   return t != NULL;
   14081    173086883 : }
   14082              : 
   14083              : /* Return an IMPLICIT_CONV_EXPR from EXPR to TYPE with bits set from overload
   14084              :    resolution FLAGS.  */
   14085              : 
   14086              : tree
   14087     13786205 : 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     13786205 :   expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14095     13786205 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   14096      6270894 :     IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14097     13786205 :   if (flags & LOOKUP_NO_NARROWING)
   14098        22136 :     IMPLICIT_CONV_EXPR_BRACED_INIT (expr) = true;
   14099     13786205 :   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    280504868 : perform_implicit_conversion_flags (tree type, tree expr,
   14110              :                                    tsubst_flags_t complain, int flags)
   14111              : {
   14112    280504868 :   conversion *conv;
   14113    280504868 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14114              : 
   14115    280504868 :   if (error_operand_p (expr))
   14116          444 :     return error_mark_node;
   14117              : 
   14118    280504424 :   conversion_obstack_sentinel cos;
   14119              : 
   14120    280504424 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14121              :                               /*c_cast_p=*/false,
   14122              :                               flags, complain);
   14123              : 
   14124    280504424 :   if (!conv)
   14125              :     {
   14126       233142 :       if (complain & tf_error)
   14127          479 :         implicit_conversion_error (loc, type, expr, flags);
   14128       233142 :       expr = error_mark_node;
   14129              :     }
   14130    280271282 :   else if (processing_template_decl && conv->kind != ck_identity)
   14131     13768009 :     expr = build_implicit_conv_flags (type, expr, flags);
   14132              :   else
   14133              :     {
   14134              :       /* Give a conversion call the same location as expr.  */
   14135    266503273 :       iloc_sentinel il (loc);
   14136    266503273 :       expr = convert_like (conv, expr, complain);
   14137    266503273 :     }
   14138              : 
   14139    280504424 :   return expr;
   14140    280504424 : }
   14141              : 
   14142              : tree
   14143     12454601 : perform_implicit_conversion (tree type, tree expr, tsubst_flags_t complain)
   14144              : {
   14145     12454601 :   return perform_implicit_conversion_flags (type, expr, complain,
   14146     12454601 :                                             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     46630553 : perform_direct_initialization_if_possible (tree type,
   14159              :                                            tree expr,
   14160              :                                            bool c_cast_p,
   14161              :                                            tsubst_flags_t complain)
   14162              : {
   14163     46630553 :   conversion *conv;
   14164              : 
   14165     46630553 :   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     46630553 :   if (CLASS_TYPE_P (type))
   14183              :     {
   14184      3111291 :       releasing_vec args (make_tree_vector_single (expr));
   14185      3111291 :       expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
   14186              :                                         &args, type, LOOKUP_NORMAL, complain);
   14187      3111291 :       return build_cplus_new (type, expr, complain);
   14188      3111291 :     }
   14189              : 
   14190     43519262 :   conversion_obstack_sentinel cos;
   14191              : 
   14192     43519262 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14193              :                               c_cast_p,
   14194              :                               LOOKUP_NORMAL, complain);
   14195     43519262 :   if (!conv || conv->bad_p)
   14196              :     expr = NULL_TREE;
   14197     38963899 :   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       662871 :       expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14205       662871 :       IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14206              :     }
   14207              :   else
   14208     38301028 :     expr = convert_like (conv, expr, NULL_TREE, 0,
   14209              :                          /*issue_conversion_warnings=*/false,
   14210              :                          c_cast_p, /*nested_p=*/false, complain);
   14211              : 
   14212     43519262 :   return expr;
   14213     43519262 : }
   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         7555 : make_temporary_var_for_ref_to_temp (tree decl, tree type)
   14260              : {
   14261         7555 :   tree var = create_temporary_var (type);
   14262              : 
   14263              :   /* Register the variable.  */
   14264         7555 :   if (VAR_P (decl)
   14265         7555 :       && (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          728 :       copy_linkage (var, decl);
   14278              : 
   14279          728 :       tree name = mangle_ref_init_variable (decl);
   14280          728 :       DECL_NAME (var) = name;
   14281          728 :       SET_DECL_ASSEMBLER_NAME (var, name);
   14282              : 
   14283              :       /* Set the context to make the variable mergeable in modules.  */
   14284          728 :       DECL_CONTEXT (var) = current_scope ();
   14285              :     }
   14286              :   else
   14287              :     /* Create a new cleanup level if necessary.  */
   14288         6827 :     maybe_push_cleanup_level (type);
   14289              : 
   14290         7555 :   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         7555 : 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         7555 :   tree init;
   14307         7555 :   tree type;
   14308         7555 :   tree var;
   14309              : 
   14310              :   /* Create the temporary variable.  */
   14311         7555 :   type = TREE_TYPE (expr);
   14312         7555 :   var = make_temporary_var_for_ref_to_temp (decl, type);
   14313         7555 :   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         7555 :   if (TREE_CODE (expr) != TARGET_EXPR)
   14323            0 :     expr = get_target_expr (expr);
   14324              :   else
   14325              :     {
   14326         7555 :       if (TREE_ADDRESSABLE (expr))
   14327         7472 :         TREE_ADDRESSABLE (var) = 1;
   14328         7555 :       if (DECL_MERGEABLE (TARGET_EXPR_SLOT (expr)))
   14329          535 :         DECL_MERGEABLE (var) = true;
   14330              :     }
   14331              : 
   14332         7555 :   if (TREE_CODE (decl) == FIELD_DECL
   14333         7555 :       && 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         7555 :   if (walk_data)
   14344         1481 :     cp_walk_tree (&TARGET_EXPR_INITIAL (expr), extend_temps_r,
   14345              :                   walk_data, nullptr);
   14346              :   else
   14347         6074 :     TARGET_EXPR_INITIAL (expr)
   14348        12148 :       = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups,
   14349              :                                cond_guard);
   14350              : 
   14351              :   /* Any reference temp has a non-trivial initializer.  */
   14352         7555 :   DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
   14353              : 
   14354              :   /* If the initializer is constant, put it in DECL_INITIAL so we get
   14355              :      static initialization and use in constant expressions.  */
   14356         7555 :   init = maybe_constant_init (expr, var, /*manifestly_const_eval=*/true);
   14357              :   /* As in store_init_value.  */
   14358         7555 :   init = cp_fully_fold (init);
   14359         7555 :   if (TREE_CONSTANT (init))
   14360              :     {
   14361         1076 :       if (literal_type_p (type)
   14362         1050 :           && CP_TYPE_CONST_NON_VOLATILE_P (type)
   14363         1708 :           && !TYPE_HAS_MUTABLE_P (type))
   14364              :         {
   14365              :           /* 5.19 says that a constant expression can include an
   14366              :              lvalue-rvalue conversion applied to "a glvalue of literal type
   14367              :              that refers to a non-volatile temporary object initialized
   14368              :              with a constant expression".  Rather than try to communicate
   14369              :              that this VAR_DECL is a temporary, just mark it constexpr.  */
   14370          629 :           DECL_DECLARED_CONSTEXPR_P (var) = true;
   14371          629 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = true;
   14372          629 :           TREE_CONSTANT (var) = true;
   14373          629 :           TREE_READONLY (var) = true;
   14374              :         }
   14375         1076 :       DECL_INITIAL (var) = init;
   14376         1076 :       init = NULL_TREE;
   14377              :     }
   14378              :   else
   14379              :     /* Create the INIT_EXPR that will initialize the temporary
   14380              :        variable.  */
   14381         6479 :     init = split_nonconstant_init (var, expr);
   14382         7555 :   if (at_function_scope_p ())
   14383              :     {
   14384         6914 :       add_decl_expr (var);
   14385              : 
   14386         6914 :       if (TREE_STATIC (var))
   14387           87 :         init = add_stmt_to_compound (init, register_dtor_fn (var));
   14388              :       else
   14389              :         {
   14390              :           /* ??? Instead of rebuilding the cleanup, we could replace the slot
   14391              :              with var in TARGET_EXPR_CLEANUP (expr).  */
   14392         6827 :           tree cleanup = cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14393         6827 :           if (cleanup)
   14394              :             {
   14395         2779 :               if (cond_guard && cleanup != error_mark_node)
   14396              :                 {
   14397           23 :                   if (*cond_guard == NULL_TREE)
   14398              :                     {
   14399           23 :                       *cond_guard = build_local_temp (boolean_type_node);
   14400           23 :                       add_decl_expr (*cond_guard);
   14401           23 :                       tree set = cp_build_modify_expr (UNKNOWN_LOCATION,
   14402              :                                                        *cond_guard, NOP_EXPR,
   14403              :                                                        boolean_false_node,
   14404              :                                                        tf_warning_or_error);
   14405           23 :                       finish_expr_stmt (set);
   14406              :                     }
   14407           23 :                   cleanup = build3 (COND_EXPR, void_type_node,
   14408              :                                     *cond_guard, cleanup, NULL_TREE);
   14409              :                 }
   14410         2779 :               if (flag_exceptions && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE)
   14411              :                 {
   14412              :                   /* The normal cleanup for this extended variable isn't pushed
   14413              :                      until cp_finish_decl, so we need to retain a TARGET_EXPR
   14414              :                      to clean it up in case a later initializer throws
   14415              :                      (g++.dg/eh/ref-temp3.C).
   14416              : 
   14417              :                      We don't do this for array temporaries because they have
   14418              :                      the array cleanup region from build_vec_init.
   14419              : 
   14420              :                      Unlike maybe_push_temp_cleanup, we don't actually need a
   14421              :                      flag, but a TARGET_EXPR needs a TARGET_EXPR_SLOT.
   14422              :                      Perhaps this could use WITH_CLEANUP_EXPR instead, but
   14423              :                      gimplify.cc doesn't handle that, and front-end handling
   14424              :                      was removed in r8-1725 and r8-1818.
   14425              : 
   14426              :                      Alternately it might be preferable to flatten an
   14427              :                      initialization with extended temps into a sequence of
   14428              :                      (non-full-expression) statements, so we could immediately
   14429              :                      push_cleanup here for only a single cleanup region, but we
   14430              :                      don't have a mechanism for that in the front-end, only the
   14431              :                      gimplifier.  */
   14432         2671 :                   tree targ = get_internal_target_expr (boolean_true_node);
   14433         2671 :                   TARGET_EXPR_CLEANUP (targ) = cleanup;
   14434         2671 :                   CLEANUP_EH_ONLY (targ) = true;
   14435              :                   /* Don't actually initialize the bool.  */
   14436         2671 :                   init = (!init ? void_node
   14437         2645 :                           : convert_to_void (init, ICV_STATEMENT, tf_none));
   14438         2671 :                   TARGET_EXPR_INITIAL (targ) = init;
   14439         2671 :                   init = targ;
   14440              :                 }
   14441         2779 :               vec_safe_push (*cleanups, cleanup);
   14442              :             }
   14443              :         }
   14444              : 
   14445              :       /* We must be careful to destroy the temporary only
   14446              :          after its initialization has taken place.  If the
   14447              :          initialization throws an exception, then the
   14448              :          destructor should not be run.  We cannot simply
   14449              :          transform INIT into something like:
   14450              : 
   14451              :          (INIT, ({ CLEANUP_STMT; }))
   14452              : 
   14453              :          because emit_local_var always treats the
   14454              :          initializer as a full-expression.  Thus, the
   14455              :          destructor would run too early; it would run at the
   14456              :          end of initializing the reference variable, rather
   14457              :          than at the end of the block enclosing the
   14458              :          reference variable.
   14459              : 
   14460              :          The solution is to pass back a cleanup expression
   14461              :          which the caller is responsible for attaching to
   14462              :          the statement tree.  */
   14463              :     }
   14464              :   else
   14465              :     {
   14466              :       /* Don't output reflection variables.  */
   14467          641 :       if (consteval_only_p (var))
   14468            1 :         DECL_EXTERNAL (var) = true;
   14469              : 
   14470          641 :       rest_of_decl_compilation (var, /*toplev=*/1, at_eof);
   14471          641 :       if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
   14472              :         {
   14473           40 :           if (CP_DECL_THREAD_LOCAL_P (var))
   14474           12 :             tls_aggregates = tree_cons (NULL_TREE, var,
   14475              :                                         tls_aggregates);
   14476              :           else
   14477           28 :             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         7555 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   14486         7555 :       && VAR_P (decl))
   14487         2750 :     TREE_USED (decl) = DECL_READ_P (decl) = true;
   14488              : 
   14489         7555 :   *initp = init;
   14490         7555 :   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      6194625 : initialize_reference (tree type, tree expr,
   14498              :                       int flags, tsubst_flags_t complain)
   14499              : {
   14500      6194625 :   conversion *conv;
   14501      6194625 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14502              : 
   14503      6194625 :   if (type == error_mark_node || error_operand_p (expr))
   14504              :     return error_mark_node;
   14505              : 
   14506      6194557 :   conversion_obstack_sentinel cos;
   14507              : 
   14508      6194557 :   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      6194557 :   if ((!conv || conv->bad_p)
   14513          675 :       && (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      6195150 :   if (!conv || conv->bad_p)
   14525              :     {
   14526          672 :       if (complain & tf_error)
   14527              :         {
   14528          352 :           if (conv)
   14529          303 :             convert_like (conv, expr, complain);
   14530           49 :           else if (!CP_TYPE_CONST_P (TREE_TYPE (type))
   14531           17 :                    && !TYPE_REF_IS_RVALUE (type)
   14532           66 :                    && !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           43 :             error_at (loc, "invalid initialization of reference of type "
   14538              :                       "%qH from expression of type %qI", type,
   14539           43 :                       TREE_TYPE (expr));
   14540              :         }
   14541          672 :       return error_mark_node;
   14542              :     }
   14543              : 
   14544      6193885 :   if (conv->kind == ck_ref_bind)
   14545              :     /* Perform the conversion.  */
   14546      6193882 :     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      6194557 : }
   14555              : 
   14556              : /* Return true if T is std::pair<const T&, const T&>.  */
   14557              : 
   14558              : static bool
   14559       613318 : std_pair_ref_ref_p (tree t)
   14560              : {
   14561              :   /* First, check if we have std::pair.  */
   14562        56347 :   if (!NON_UNION_CLASS_TYPE_P (t)
   14563       669205 :       || !CLASSTYPE_TEMPLATE_INSTANTIATION (t))
   14564              :     return false;
   14565        19737 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (t));
   14566        19737 :   if (!decl_in_std_namespace_p (tdecl))
   14567              :     return false;
   14568        14518 :   tree name = DECL_NAME (tdecl);
   14569        14518 :   if (!name || !id_equal (name, "pair"))
   14570              :     return false;
   14571              : 
   14572              :   /* Now see if the template arguments are both const T&.  */
   14573          363 :   tree args = CLASSTYPE_TI_ARGS (t);
   14574          363 :   if (TREE_VEC_LENGTH (args) != 2)
   14575              :     return false;
   14576          423 :   for (int i = 0; i < 2; i++)
   14577          453 :     if (!TYPE_REF_OBJ_P (TREE_VEC_ELT (args, i))
   14578          453 :         || !CP_TYPE_CONST_P (TREE_TYPE (TREE_VEC_ELT (args, i))))
   14579          333 :       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         1554 : no_dangling_p (tree t)
   14614              : {
   14615         1554 :   t = lookup_attribute ("no_dangling", TYPE_ATTRIBUTES (t));
   14616         1554 :   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         3868 : do_warn_dangling_reference (tree expr, bool arg_p)
   14710              : {
   14711         3868 :   STRIP_NOPS (expr);
   14712              : 
   14713         3868 :   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         3636 :   switch (TREE_CODE (expr))
   14731              :     {
   14732         1817 :     case CALL_EXPR:
   14733         1817 :       {
   14734         1817 :         tree fndecl = cp_get_callee_fndecl_nofold (expr);
   14735         1817 :         if (!fndecl
   14736         1817 :             || warning_suppressed_p (fndecl, OPT_Wdangling_reference)
   14737         1806 :             || !warning_enabled_at (DECL_SOURCE_LOCATION (fndecl),
   14738         1806 :                                     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         1447 :             || (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   14747          849 :                 && DECL_OVERLOADED_OPERATOR_P (fndecl)
   14748          316 :                 && DECL_OVERLOADED_OPERATOR_IS (fndecl, INDIRECT_REF))
   14749         3057 :             || no_dangling_p (TREE_TYPE (fndecl)))
   14750          601 :           return NULL_TREE;
   14751              : 
   14752         1216 :         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         1216 :         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         1644 :         for (int i = 0; i < call_expr_nargs (expr); ++i)
   14769              :           {
   14770         1238 :             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         1238 :             if (!DECL_IOBJ_MEMBER_FUNCTION_P (fndecl)
   14774         1238 :                 && !TYPE_REF_P (TREE_TYPE (arg)))
   14775          130 :               continue;
   14776         1108 :             STRIP_NOPS (arg);
   14777         1108 :             if (TREE_CODE (arg) == ADDR_EXPR)
   14778          723 :               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         1108 :             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          831 :             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    102543745 : maybe_warn_dangling_reference (const_tree decl, tree init)
   14843              : {
   14844    102543745 :   if (!warn_dangling_reference)
   14845              :     return;
   14846       615576 :   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      1228604 :   if (!((TYPE_REF_OBJ_P (type)
   14851         5420 :          && (TYPE_REF_IS_RVALUE (type)
   14852         4988 :              || CP_TYPE_CONST_P (TREE_TYPE (type))))
   14853       613028 :         || 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         2563 :   auto wsh
   14859         2563 :     = make_temp_override (global_dc->m_warn_system_headers,
   14860         2563 :                           (!in_system_header_at (DECL_SOURCE_LOCATION (decl))
   14861         2563 :                            || global_dc->m_warn_system_headers));
   14862         2563 :   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         2563 : }
   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       662019 : 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       662019 :   tree sub = init;
   14926       662019 :   tree *p;
   14927       662019 :   STRIP_NOPS (sub);
   14928       662019 :   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       661777 :   if (TREE_CODE (sub) == POINTER_PLUS_EXPR
   14936       661777 :       && 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       661771 :   if (TREE_CODE (sub) == COND_EXPR)
   14946              :     {
   14947        22482 :       tree cur_cond_guard = NULL_TREE;
   14948        22482 :       if (TREE_OPERAND (sub, 1))
   14949        22482 :         TREE_OPERAND (sub, 1)
   14950        44964 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   14951              :                                      &cur_cond_guard);
   14952        22482 :       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        22482 :       cur_cond_guard = NULL_TREE;
   14962        22482 :       if (TREE_OPERAND (sub, 2))
   14963        22482 :         TREE_OPERAND (sub, 2)
   14964        44964 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 2), cleanups,
   14965              :                                      &cur_cond_guard);
   14966        22482 :       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        22482 :       return init;
   14976              :     }
   14977       639289 :   if (TREE_CODE (sub) != ADDR_EXPR)
   14978              :     return init;
   14979              :   /* Deal with binding to a subobject.  */
   14980       194248 :   for (p = &TREE_OPERAND (sub, 0);
   14981       207969 :        TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   14982        13721 :     p = &TREE_OPERAND (*p, 0);
   14983       194248 :   if (TREE_CODE (*p) == TARGET_EXPR)
   14984              :     {
   14985         6074 :       tree subinit = NULL_TREE;
   14986         6074 :       *p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit,
   14987              :                                      cond_guard, nullptr);
   14988         6074 :       recompute_tree_invariant_for_addr_expr (sub);
   14989         6074 :       if (init != sub)
   14990         6056 :         init = fold_convert (TREE_TYPE (init), sub);
   14991         6074 :       if (subinit)
   14992         5131 :         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        69850 : extend_temps_r (tree *tp, int *walk_subtrees, void *data)
   15015              : {
   15016        69850 :   extend_temps_data *d = (extend_temps_data *)data;
   15017              : 
   15018        69850 :   if (TREE_CODE (*tp) == VAR_DECL)
   15019              :     {
   15020         8932 :       if (tree *r = d->var_map->get (*tp))
   15021            0 :         *tp = *r;
   15022         8932 :       return NULL_TREE;
   15023              :     }
   15024              : 
   15025        60903 :   if (TYPE_P (*tp) || TREE_CODE (*tp) == CLEANUP_POINT_EXPR
   15026       121820 :       || d->pset->add (*tp))
   15027              :     {
   15028         3605 :       *walk_subtrees = 0;
   15029         3605 :       return NULL_TREE;
   15030              :     }
   15031              : 
   15032        57313 :   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        57305 :   tree *p = tp;
   15056              : 
   15057        57305 :   if (TREE_CODE (*tp) == ADDR_EXPR)
   15058        13062 :     for (p = &TREE_OPERAND (*tp, 0);
   15059        14136 :          TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   15060         1074 :       p = &TREE_OPERAND (*p, 0);
   15061              : 
   15062        57305 :   if (TREE_CODE (*p) == TARGET_EXPR
   15063              :       /* An eliding TARGET_EXPR isn't a temporary at all.  */
   15064         2374 :       && !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        59098 :       && !TARGET_EXPR_INTERNAL_P (*p))
   15068              :     {
   15069              :       /* A CLEANUP_EH_ONLY expr should also have TARGET_EXPR_INTERNAL_P.  */
   15070         1481 :       gcc_checking_assert (!CLEANUP_EH_ONLY (*p));
   15071              : 
   15072         1481 :       tree subinit = NULL_TREE;
   15073         1481 :       tree slot = TARGET_EXPR_SLOT (*p);
   15074         1481 :       *p = set_up_extended_ref_temp (d->decl, *p, d->cleanups, &subinit,
   15075              :                                      d->cond_guard, d);
   15076         1481 :       if (TREE_CODE (*tp) == ADDR_EXPR)
   15077         1467 :         recompute_tree_invariant_for_addr_expr (*tp);
   15078         1481 :       if (subinit)
   15079         1374 :         *tp = cp_build_compound_expr (subinit, *tp, tf_none);
   15080         1481 :       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        13995 : extend_all_temps (tree decl, tree init, vec<tree, va_gc> **cleanups)
   15090              : {
   15091        13995 :   hash_set<tree> pset;
   15092        13995 :   hash_map<tree, tree> map;
   15093        13995 :   gcc_assert (!TREE_STATIC (decl));
   15094        13995 :   extend_temps_data d = { decl, init, cleanups, nullptr, &pset, &map };
   15095        13995 :   cp_walk_tree (&init, extend_temps_r, &d, nullptr);
   15096        13995 :   return init;
   15097        13995 : }
   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    104848492 : extend_ref_init_temps (tree decl, tree init, vec<tree, va_gc> **cleanups,
   15105              :                        tree *cond_guard)
   15106              : {
   15107    104848492 :   tree type = TREE_TYPE (init);
   15108    104848492 :   if (processing_template_decl)
   15109              :     return init;
   15110              : 
   15111              :   /* P2718R0 - in C++23 for-range-initializer, extend all temps.  */
   15112    102557740 :   if (DECL_NAME (decl) == for_range__identifier
   15113        88238 :       && 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    102571758 :       && !TREE_STATIC (decl))
   15117              :     {
   15118        13995 :       gcc_checking_assert (!cond_guard);
   15119        13995 :       return extend_all_temps (decl, init, cleanups);
   15120              :     }
   15121              : 
   15122    102543745 :   maybe_warn_dangling_reference (decl, init);
   15123              : 
   15124    102543745 :   if (TYPE_REF_P (type))
   15125       616228 :     init = extend_ref_init_temps_1 (decl, init, cleanups, cond_guard);
   15126              :   else
   15127              :     {
   15128    101927517 :       tree ctor = init;
   15129    101927517 :       if (TREE_CODE (ctor) == TARGET_EXPR)
   15130      1287278 :         ctor = TARGET_EXPR_INITIAL (ctor);
   15131    101927517 :       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      5009089 :           if (CONSTRUCTOR_IS_PAREN_INIT (ctor))
   15137              :             return init;
   15138              : 
   15139      5008719 :           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      5008140 :               unsigned i;
   15151      5008140 :               constructor_elt *p;
   15152      5008140 :               vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (ctor);
   15153     58879017 :               FOR_EACH_VEC_SAFE_ELT (elts, i, p)
   15154     53870877 :                 p->value = extend_ref_init_temps (decl, p->value, cleanups,
   15155              :                                                   cond_guard);
   15156              :             }
   15157      5008719 :           recompute_constructor_flags (ctor);
   15158      5008719 :           if (decl_maybe_constant_var_p (decl) && TREE_CONSTANT (ctor))
   15159      2708060 :             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         5265 : type_has_extended_temps (tree type)
   15172              : {
   15173         5265 :   type = strip_array_types (type);
   15174         5265 :   if (TYPE_REF_P (type))
   15175              :     return true;
   15176         5208 :   if (CLASS_TYPE_P (type))
   15177              :     {
   15178         2832 :       if (is_std_init_list (type))
   15179              :         return true;
   15180         2829 :       for (tree f = next_aggregate_field (TYPE_FIELDS (type));
   15181         6674 :            f; f = next_aggregate_field (DECL_CHAIN (f)))
   15182         3974 :         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    171745038 : is_std_init_list (tree type)
   15192              : {
   15193    171745038 :   if (!TYPE_P (type))
   15194              :     return false;
   15195    171745015 :   if (cxx_dialect == cxx98)
   15196              :     return false;
   15197              :   /* Look through typedefs.  */
   15198    171335361 :   type = TYPE_MAIN_VARIANT (type);
   15199    137036416 :   return (CLASS_TYPE_P (type)
   15200    136898046 :           && CP_TYPE_CONTEXT (type) == std_node
   15201    248108896 :           && 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    149742066 : is_list_ctor (tree decl)
   15209              : {
   15210    149742066 :   tree args = FUNCTION_FIRST_USER_PARMTYPE (decl);
   15211    149742066 :   tree arg;
   15212              : 
   15213    149742066 :   if (!args || args == void_list_node)
   15214              :     return false;
   15215              : 
   15216    120726988 :   arg = non_reference (TREE_VALUE (args));
   15217    120726988 :   if (!is_std_init_list (arg))
   15218              :     return false;
   15219              : 
   15220      2178355 :   args = TREE_CHAIN (args);
   15221              : 
   15222      3709950 :   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         2056 : maybe_show_nonconverting_candidate (tree to, tree from, tree arg, int flags)
   15236              : {
   15237         2056 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   15238          289 :     return;
   15239              : 
   15240         1767 :   conversion_obstack_sentinel cos;
   15241         1767 :   conversion *c = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   15242              :                                        flags & ~LOOKUP_ONLYCONVERTING, tf_none);
   15243         1767 :   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         1767 : }
   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.