LCOV - code coverage report
Current view: top level - gcc/cp - call.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.1 % 6408 6159
Test Date: 2026-06-20 15:32:29 Functions: 99.6 % 226 225
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Functions related to invoking -*- C++ -*- methods and overloaded functions.
       2              :    Copyright (C) 1987-2026 Free Software Foundation, Inc.
       3              :    Contributed by Michael Tiemann (tiemann@cygnus.com) and
       4              :    modified by Brendan Kehoe (brendan@cygnus.com).
       5              : 
       6              : This file is part of GCC.
       7              : 
       8              : GCC is free software; you can redistribute it and/or modify
       9              : it under the terms of the GNU General Public License as published by
      10              : the Free Software Foundation; either version 3, or (at your option)
      11              : any later version.
      12              : 
      13              : GCC is distributed in the hope that it will be useful,
      14              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16              : GNU General Public License for more details.
      17              : 
      18              : You should have received a copy of the GNU General Public License
      19              : along with GCC; see the file COPYING3.  If not see
      20              : <http://www.gnu.org/licenses/>.  */
      21              : 
      22              : 
      23              : /* High-level class interface.  */
      24              : 
      25              : #include "config.h"
      26              : #include "system.h"
      27              : #include "coretypes.h"
      28              : #include "target.h"
      29              : #include "cp-tree.h"
      30              : #include "timevar.h"
      31              : #include "stringpool.h"
      32              : #include "cgraph.h"
      33              : #include "stor-layout.h"
      34              : #include "trans-mem.h"
      35              : #include "flags.h"
      36              : #include "toplev.h"
      37              : #include "intl.h"
      38              : #include "convert.h"
      39              : #include "langhooks.h"
      40              : #include "c-family/c-objc.h"
      41              : #include "internal-fn.h"
      42              : #include "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      3049201 : check_dtor_name (tree basetype, tree name)
     236              : {
     237              :   /* Just accept something we've already complained about.  */
     238      3049201 :   if (name == error_mark_node)
     239              :     return true;
     240              : 
     241      3049201 :   if (TREE_CODE (name) == TYPE_DECL)
     242           84 :     name = TREE_TYPE (name);
     243      3049117 :   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      3049175 :   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    331124799 : build_addr_func (tree function, tsubst_flags_t complain)
     282              : {
     283    331124799 :   tree type = TREE_TYPE (function);
     284              : 
     285              :   /* We have to do these by hand to avoid real pointer to member
     286              :      functions.  */
     287    331124799 :   if (TREE_CODE (type) == METHOD_TYPE)
     288              :     {
     289     51430752 :       if (TREE_CODE (function) == OFFSET_REF)
     290              :         {
     291           72 :           tree object = build_address (TREE_OPERAND (function, 0));
     292           72 :           return get_member_function_from_ptrfunc (&object,
     293           72 :                                                    TREE_OPERAND (function, 1),
     294              :                                                    complain);
     295              :         }
     296     51430680 :       function = build_address (function);
     297              :     }
     298    279694047 :   else if (TREE_CODE (function) == FUNCTION_DECL
     299    399182319 :            && DECL_IMMEDIATE_FUNCTION_P (function))
     300      1754135 :     function = build_address (function);
     301              :   else
     302    277939912 :     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       160311 : build_call_n (tree function, int n, ...)
     315              : {
     316       160311 :   if (n == 0)
     317            0 :     return build_call_a (function, 0, NULL);
     318              :   else
     319              :     {
     320       160311 :       tree *argarray = XALLOCAVEC (tree, n);
     321       160311 :       va_list ap;
     322       160311 :       int i;
     323              : 
     324       160311 :       va_start (ap, n);
     325       321779 :       for (i = 0; i < n; i++)
     326       161468 :         argarray[i] = va_arg (ap, tree);
     327       160311 :       va_end (ap);
     328       160311 :       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    159751924 : set_flags_from_callee (tree call)
     337              : {
     338              :   /* Handle both CALL_EXPRs and AGGR_INIT_EXPRs.  */
     339    159751924 :   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    159751924 :   bool nothrow = decl && TREE_NOTHROW (decl);
     344    159751924 :   tree callee = cp_get_callee (call);
     345    159751924 :   if (callee)
     346    159751916 :     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    159751924 :   if (cfun && cp_function_chain && !cp_unevaluated_operand)
     352              :     {
     353     94432584 :       if (!nothrow && at_function_scope_p ())
     354     23246626 :         cp_function_chain->can_throw = 1;
     355              : 
     356     94432584 :       if (decl && TREE_THIS_VOLATILE (decl))
     357      2892901 :         current_function_returns_abnormally = 1;
     358              :     }
     359              : 
     360    159751924 :   TREE_NOTHROW (call) = nothrow;
     361    159751924 : }
     362              : 
     363              : tree
     364    155653607 : build_call_a (tree function, int n, tree *argarray)
     365              : {
     366    155653607 :   tree decl;
     367    155653607 :   tree result_type;
     368    155653607 :   tree fntype;
     369    155653607 :   int i;
     370              : 
     371    155653607 :   function = build_addr_func (function, tf_warning_or_error);
     372              : 
     373    155653607 :   gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
     374    155653607 :   fntype = TREE_TYPE (TREE_TYPE (function));
     375    155653607 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     376    155653607 :   result_type = TREE_TYPE (fntype);
     377              :   /* An rvalue has no cv-qualifiers.  */
     378    155653607 :   if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
     379     91609182 :     result_type = cv_unqualified (result_type);
     380              : 
     381    155653607 :   function = build_call_array_loc (input_location,
     382              :                                    result_type, function, n, argarray);
     383    155653607 :   set_flags_from_callee (function);
     384              : 
     385    155653607 :   decl = get_callee_fndecl (function);
     386              : 
     387    155653607 :   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       196214 :       gcc_assert (DECL_ARTIFICIAL (decl)
     394              :                   || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
     395              :                                "__", 2));
     396       196214 :       mark_used (decl);
     397              :     }
     398              : 
     399    155653607 :   require_complete_eh_spec_types (fntype, decl);
     400              : 
     401    448526114 :   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    155653607 :   if (!decl || !fndecl_built_in_p (decl))
     407    314068512 :     for (i = 0; i < n; i++)
     408              :       {
     409    165735107 :         tree arg = CALL_EXPR_ARG (function, i);
     410    165735107 :         if (is_empty_class (TREE_TYPE (arg))
     411    165735107 :             && simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
     412              :           {
     413      5223323 :             while (TREE_CODE (arg) == TARGET_EXPR)
     414              :               /* We're disconnecting the initializer from its target,
     415              :                  don't create a temporary.  */
     416      2610558 :               arg = TARGET_EXPR_INITIAL (arg);
     417      2612765 :             suppress_warning (arg, OPT_Wunused_result);
     418      2612765 :             tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
     419      2612765 :             arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
     420      2612765 :             CALL_EXPR_ARG (function, i) = arg;
     421              :           }
     422              :       }
     423              : 
     424    155653607 :   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     62142359 :   bool rewritten () const { return (flags & LOOKUP_REWRITTEN); }
     543    984476499 :   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    121592464 : null_ptr_cst_p (tree t)
     551              : {
     552    121592464 :   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    121592464 :   if (NULLPTR_TYPE_P (type))
     559              :     return true;
     560              : 
     561    112916428 :   if (cxx_dialect >= cxx11)
     562              :     {
     563    112568465 :       STRIP_ANY_LOCATION_WRAPPER (t);
     564              : 
     565              :       /* Core issue 903 says only literal 0 is a null pointer constant.  */
     566    112568465 :       if (TREE_CODE (t) == INTEGER_CST
     567     12895126 :           && !TREE_OVERFLOW (t)
     568     12895126 :           && TREE_CODE (type) == INTEGER_TYPE
     569     12321113 :           && integer_zerop (t)
     570    120790132 :           && !char_type_p (type))
     571              :         return true;
     572              :     }
     573       347963 :   else if (CP_INTEGRAL_TYPE_P (type))
     574              :     {
     575        65217 :       t = fold_non_dependent_expr (t, tf_none);
     576        65217 :       STRIP_NOPS (t);
     577        65217 :       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     94676651 : null_member_pointer_value_p (tree t)
     588              : {
     589     94676651 :   tree type = TREE_TYPE (t);
     590     94676651 :   if (!type)
     591              :     return false;
     592     94497192 :   else if (TYPE_PTRMEMFUNC_P (type))
     593          810 :     return (TREE_CODE (t) == CONSTRUCTOR
     594          417 :             && CONSTRUCTOR_NELTS (t)
     595         1224 :             && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
     596     94496382 :   else if (TYPE_PTRDATAMEM_P (type))
     597         5737 :     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    687412942 : sufficient_parms_p (const_tree parmlist)
     607              : {
     608    696572253 :   for (; parmlist && parmlist != void_list_node;
     609      9159311 :        parmlist = TREE_CHAIN (parmlist))
     610    211008244 :     if (!TREE_PURPOSE (parmlist)
     611    211008244 :         && !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   7455816131 : conversion_obstack_alloc (size_t n)
     621              : {
     622   7455816131 :   void *p;
     623   7455816131 :   if (!conversion_obstack_initialized)
     624              :     {
     625        85518 :       gcc_obstack_init (&conversion_obstack);
     626        85518 :       conversion_obstack_initialized = true;
     627              :     }
     628   7455816131 :   p = obstack_alloc (&conversion_obstack, n);
     629   7455816131 :   memset (p, 0, n);
     630   7455816131 :   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   2438442120 :   conversion_obstack_sentinel (): p (conversion_obstack_alloc (0)) {}
     639   1219207506 :   ~conversion_obstack_sentinel () { obstack_free (&conversion_obstack, p); }
     640              : };
     641              : 
     642              : /* Allocate rejection reasons.  */
     643              : 
     644              : static struct rejection_reason *
     645    713874248 : alloc_rejection (enum rejection_reason_code code)
     646              : {
     647    713874248 :   struct rejection_reason *p;
     648            0 :   p = (struct rejection_reason *) conversion_obstack_alloc (sizeof *p);
     649    713874248 :   p->code = code;
     650    713874248 :   return p;
     651              : }
     652              : 
     653              : static struct rejection_reason *
     654    182435755 : arity_rejection (tree first_arg, int expected, int actual, bool least_p = false)
     655              : {
     656    145208797 :   struct rejection_reason *r = alloc_rejection (rr_arity);
     657    182435755 :   int adjust = first_arg != NULL_TREE;
     658    182435755 :   r->u.arity.expected = expected - adjust;
     659    182435755 :   r->u.arity.actual = actual - adjust;
     660    182435755 :   r->u.arity.least_p = least_p;
     661    182435755 :   return r;
     662              : }
     663              : 
     664              : static struct rejection_reason *
     665    152886579 : arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     666              :                           location_t loc)
     667              : {
     668      6617608 :   struct rejection_reason *r = alloc_rejection (rr_arg_conversion);
     669    152886579 :   int adjust = first_arg != NULL_TREE;
     670    152886579 :   r->u.conversion.n_arg = n_arg - adjust;
     671    152886579 :   r->u.conversion.from = from;
     672    152886579 :   r->u.conversion.to_type = to;
     673    152886579 :   r->u.conversion.loc = loc;
     674    152886579 :   return r;
     675              : }
     676              : 
     677              : static struct rejection_reason *
     678     20962292 : bad_arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     679              :                               location_t loc)
     680              : {
     681         2023 :   struct rejection_reason *r = alloc_rejection (rr_bad_arg_conversion);
     682     20962292 :   int adjust = first_arg != NULL_TREE;
     683     20962292 :   r->u.bad_conversion.n_arg = n_arg - adjust;
     684     20962292 :   r->u.bad_conversion.from = from;
     685     20962292 :   r->u.bad_conversion.to_type = to;
     686     20962292 :   r->u.bad_conversion.loc = loc;
     687     20962292 :   return r;
     688              : }
     689              : 
     690              : static struct rejection_reason *
     691         2637 : explicit_conversion_rejection (tree from, tree to)
     692              : {
     693         2637 :   struct rejection_reason *r = alloc_rejection (rr_explicit_conversion);
     694         2637 :   r->u.conversion.n_arg = 0;
     695         2637 :   r->u.conversion.from = from;
     696         2637 :   r->u.conversion.to_type = to;
     697         2637 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     698         2637 :   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    356150853 : 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    356150853 :   size_t args_n_bytes = sizeof (*args) * nargs;
     719    356150853 :   tree *args1 = (tree *) conversion_obstack_alloc (args_n_bytes);
     720    356150853 :   struct rejection_reason *r = alloc_rejection (rr_template_unification);
     721    356150853 :   r->u.template_unification.tmpl = tmpl;
     722    356150853 :   r->u.template_unification.explicit_targs = explicit_targs;
     723    356150853 :   r->u.template_unification.num_targs = TREE_VEC_LENGTH (targs);
     724              :   /* Copy args to our own storage.  */
     725    356150853 :   memcpy (args1, args, args_n_bytes);
     726    356150853 :   r->u.template_unification.args = args1;
     727    356150853 :   r->u.template_unification.nargs = nargs;
     728    356150853 :   r->u.template_unification.return_type = return_type;
     729    356150853 :   r->u.template_unification.strict = strict;
     730    356150853 :   r->u.template_unification.flags = flags;
     731    356150853 :   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       674797 : invalid_copy_with_fn_template_rejection (void)
     742              : {
     743            0 :   struct rejection_reason *r = alloc_rejection (rr_invalid_copy);
     744       674797 :   return r;
     745              : }
     746              : 
     747              : static struct rejection_reason *
     748       599968 : inherited_ctor_rejection (void)
     749              : {
     750            0 :   struct rejection_reason *r = alloc_rejection (rr_inherited_ctor);
     751       599968 :   return r;
     752              : }
     753              : 
     754              : /* Build a constraint failure record.  */
     755              : 
     756              : static struct rejection_reason *
     757       161236 : constraint_failure (void)
     758              : {
     759            0 :   struct rejection_reason *r = alloc_rejection (rr_constraint_failure);
     760       161236 :   return r;
     761              : }
     762              : 
     763              : /* Dynamically allocate a conversion.  */
     764              : 
     765              : static conversion *
     766   2586105957 : alloc_conversion (conversion_kind kind)
     767              : {
     768   2586105957 :   conversion *c;
     769            0 :   c = (conversion *) conversion_obstack_alloc (sizeof (conversion));
     770   2586105957 :   c->kind = kind;
     771   2586105957 :   return c;
     772              : }
     773              : 
     774              : /* Make sure that all memory on the conversion obstack has been
     775              :    freed.  */
     776              : 
     777              : void
     778        97817 : validate_conversion_obstack (void)
     779              : {
     780        97817 :   if (conversion_obstack_initialized)
     781        85185 :     gcc_assert ((obstack_next_free (&conversion_obstack)
     782              :                  == obstack_base (&conversion_obstack)));
     783        97817 : }
     784              : 
     785              : /* Dynamically allocate an array of N conversions.  */
     786              : 
     787              : static conversion **
     788    957454035 : 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   1412377733 : has_next (conversion_kind code)
     797              : {
     798   1329060082 :   return !(code == ck_identity
     799   1412377733 :            || code == ck_ambig
     800              :            || code == ck_list
     801   1329125616 :            || code == ck_aggr
     802   1412377733 :            || code == ck_deferred_bad);
     803              : }
     804              : 
     805              : static conversion *
     806    762012534 : build_conv (conversion_kind code, tree type, conversion *from)
     807              : {
     808    762012534 :   conversion *t;
     809    762012534 :   conversion_rank rank = CONVERSION_RANK (from);
     810              : 
     811              :   /* Only call this function for conversions that use u.next.  */
     812    762012534 :   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    762012534 :   t = alloc_conversion (code);
     817    762012534 :   t->type = type;
     818    762012534 :   t->u.next = from;
     819              : 
     820    762012534 :   switch (code)
     821              :     {
     822    225212970 :     case ck_ptr:
     823    225212970 :     case ck_pmem:
     824    225212970 :     case ck_base:
     825    225212970 :     case ck_std:
     826    225212970 :       if (rank < cr_std)
     827    762012534 :         rank = cr_std;
     828              :       break;
     829              : 
     830     51554506 :     case ck_qual:
     831     51554506 :     case ck_fnptr:
     832     51554506 :       if (rank < cr_exact)
     833    762012534 :         rank = cr_exact;
     834              :       break;
     835              : 
     836              :     default:
     837              :       break;
     838              :     }
     839    762012534 :   t->rank = rank;
     840    762012534 :   t->user_conv_p = (code == ck_user || from->user_conv_p);
     841    762012534 :   t->bad_p = from->bad_p;
     842    762012534 :   t->base_p = false;
     843    762012534 :   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        90783 : build_list_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     852              : {
     853        90783 :   tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (type), 0);
     854        90783 :   unsigned len = CONSTRUCTOR_NELTS (ctor);
     855        90783 :   conversion **subconvs = alloc_conversions (len);
     856        90783 :   conversion *t;
     857        90783 :   unsigned i;
     858        90783 :   tree val;
     859              : 
     860              :   /* Within a list-initialization we can have more user-defined
     861              :      conversions.  */
     862        90783 :   flags &= ~LOOKUP_NO_CONVERSION;
     863              :   /* But no narrowing conversions.  */
     864        90783 :   flags |= LOOKUP_NO_NARROWING;
     865              : 
     866              :   /* Can't make an array of these types.  */
     867        90783 :   if (TYPE_REF_P (elttype)
     868        90774 :       || TREE_CODE (elttype) == FUNCTION_TYPE
     869        90774 :       || VOID_TYPE_P (elttype))
     870              :     return NULL;
     871              : 
     872       342010 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
     873              :     {
     874       264275 :       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       264224 :       conversion *sub
     936       264224 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
     937              :                                false, flags, complain);
     938       264224 :       if (sub == NULL)
     939              :         return NULL;
     940              : 
     941       251185 :       subconvs[i] = sub;
     942              :     }
     943              : 
     944        77735 :   t = alloc_conversion (ck_list);
     945        77735 :   t->type = type;
     946        77735 :   t->u.list = subconvs;
     947        77735 :   t->rank = cr_exact;
     948              : 
     949       310909 :   for (i = 0; i < len; ++i)
     950              :     {
     951       233174 :       conversion *sub = subconvs[i];
     952       233174 :       if (sub->rank > t->rank)
     953        59559 :         t->rank = sub->rank;
     954       233174 :       if (sub->user_conv_p)
     955        10142 :         t->user_conv_p = true;
     956       233174 :       if (sub->bad_p)
     957        59574 :         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    567288482 : next_conversion (conversion *conv)
     969              : {
     970    567288482 :   if (conv == NULL
     971    567288482 :       || !has_next (conv->kind))
     972              :     return NULL;
     973    555749446 :   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      1391372 : strip_standard_conversion (conversion *conv)
     981              : {
     982      1391372 :   while (conv
     983      1397168 :          && conv->kind != ck_user
     984      1431458 :          && has_next (conv->kind))
     985         5796 :     conv = next_conversion (conv);
     986      1391372 :   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        25320 : can_convert_array (tree atype, tree from, int flags, tsubst_flags_t complain)
     994              : {
     995        25320 :   tree elttype = TREE_TYPE (atype);
     996        25320 :   unsigned i;
     997              : 
     998        25320 :   if (TREE_CODE (from) == CONSTRUCTOR)
     999              :     {
    1000        28382 :       for (i = 0; i < CONSTRUCTOR_NELTS (from); ++i)
    1001              :         {
    1002         3107 :           tree val = CONSTRUCTOR_ELT (from, i)->value;
    1003         3107 :           bool ok;
    1004         3107 :           if (TREE_CODE (elttype) == ARRAY_TYPE)
    1005           18 :             ok = can_convert_array (elttype, val, flags, complain);
    1006              :           else
    1007         3089 :             ok = can_convert_arg (elttype, TREE_TYPE (val), val, flags,
    1008              :                                   complain);
    1009         3107 :           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       814612 : field_in_pset (hash_set<tree, true> &pset, tree field)
    1029              : {
    1030       814612 :   if (pset.contains (field))
    1031              :     return true;
    1032         2593 :   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      1251389 : build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1050              : {
    1051      1251389 :   unsigned HOST_WIDE_INT i = 0;
    1052      1251389 :   conversion *c;
    1053      1251389 :   tree field = next_aggregate_field (TYPE_FIELDS (type));
    1054      1251389 :   tree empty_ctor = NULL_TREE;
    1055      1251389 :   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      1251389 :   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      1251389 :   tree idx, val;
    1069      2063408 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
    1070              :     {
    1071       812111 :       if (!idx)
    1072              :         break;
    1073              : 
    1074       812051 :       gcc_checking_assert (TREE_CODE (idx) == FIELD_DECL);
    1075              : 
    1076       812051 :       tree ftype = TREE_TYPE (idx);
    1077       812051 :       bool ok;
    1078              : 
    1079       812051 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1080         1111 :         ok = can_convert_array (ftype, val, flags, complain);
    1081              :       else
    1082       810940 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1083              :                               complain);
    1084              : 
    1085       812051 :       if (!ok)
    1086              :         return NULL;
    1087              : 
    1088              :       /* For unions, there should be just one initializer.  */
    1089       812042 :       if (TREE_CODE (type) == UNION_TYPE)
    1090              :         {
    1091              :           field = NULL_TREE;
    1092              :           i = 1;
    1093              :           break;
    1094              :         }
    1095       812019 :       pset.add (idx);
    1096              :     }
    1097              : 
    1098      2130738 :   for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
    1099              :     {
    1100       879618 :       tree ftype = TREE_TYPE (field);
    1101       879618 :       bool ok;
    1102              : 
    1103       879618 :       if (!pset.is_empty () && field_in_pset (pset, field))
    1104       812019 :         continue;
    1105        67599 :       if (i < CONSTRUCTOR_NELTS (ctor))
    1106              :         {
    1107           39 :           constructor_elt *ce = CONSTRUCTOR_ELT (ctor, i);
    1108           39 :           gcc_checking_assert (!ce->index);
    1109           39 :           val = ce->value;
    1110           39 :           ++i;
    1111              :         }
    1112        67560 :       else if (DECL_INITIAL (field))
    1113        16606 :         val = get_nsdmi (field, /*ctor*/false, complain);
    1114        50954 :       else if (TYPE_REF_P (ftype))
    1115              :         /* Value-initialization of reference is ill-formed.  */
    1116              :         return NULL;
    1117              :       else
    1118              :         {
    1119        50948 :           if (empty_ctor == NULL_TREE)
    1120        38120 :             empty_ctor = build_constructor (init_list_type_node, NULL);
    1121              :           val = empty_ctor;
    1122              :         }
    1123              : 
    1124        67593 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1125        24191 :         ok = can_convert_array (ftype, val, flags, complain);
    1126              :       else
    1127        43402 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1128              :                               complain);
    1129              : 
    1130        67593 :       if (!ok)
    1131              :         return NULL;
    1132              : 
    1133        67580 :       if (TREE_CODE (type) == UNION_TYPE)
    1134              :         break;
    1135              :     }
    1136              : 
    1137      1251361 :   if (i < CONSTRUCTOR_NELTS (ctor))
    1138              :     return NULL;
    1139              : 
    1140      1251334 :   c = alloc_conversion (ck_aggr);
    1141      1251334 :   c->type = type;
    1142      1251334 :   c->rank = cr_exact;
    1143      1251334 :   c->user_conv_p = true;
    1144      1251334 :   c->check_narrowing = true;
    1145      1251334 :   c->u.expr = ctor;
    1146      1251334 :   return c;
    1147      1251389 : }
    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         1866 : build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1154              : {
    1155         1866 :   conversion *c;
    1156         1866 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1157         1866 :   tree elttype = TREE_TYPE (type);
    1158         1866 :   bool bad = false;
    1159         1866 :   bool user = false;
    1160         1866 :   enum conversion_rank rank = cr_exact;
    1161              : 
    1162              :   /* We might need to propagate the size from the element to the array.  */
    1163         1866 :   complete_type (type);
    1164              : 
    1165         1866 :   if (TYPE_DOMAIN (type)
    1166         1866 :       && !variably_modified_type_p (TYPE_DOMAIN (type), NULL_TREE))
    1167              :     {
    1168         1792 :       unsigned HOST_WIDE_INT alen = tree_to_uhwi (array_type_nelts_top (type));
    1169         1792 :       if (alen < len)
    1170              :         return NULL;
    1171              :     }
    1172              : 
    1173         1819 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1174              : 
    1175         7596 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1176              :     {
    1177         2973 :       conversion *sub
    1178         2973 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1179              :                                false, flags, complain);
    1180         2973 :       if (sub == NULL)
    1181              :         return NULL;
    1182              : 
    1183         2225 :       if (sub->rank > rank)
    1184          282 :         rank = sub->rank;
    1185         2225 :       if (sub->user_conv_p)
    1186           27 :         user = true;
    1187         2225 :       if (sub->bad_p)
    1188          213 :         bad = true;
    1189              :     }
    1190              : 
    1191         1071 :   c = alloc_conversion (ck_aggr);
    1192         1071 :   c->type = type;
    1193         1071 :   c->rank = rank;
    1194         1071 :   c->user_conv_p = user;
    1195         1071 :   c->bad_p = bad;
    1196         1071 :   c->u.expr = ctor;
    1197         1071 :   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        54822 : build_complex_conv (tree type, tree ctor, int flags,
    1205              :                     tsubst_flags_t complain)
    1206              : {
    1207        54822 :   conversion *c;
    1208        54822 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1209        54822 :   tree elttype = TREE_TYPE (type);
    1210        54822 :   bool bad = false;
    1211        54822 :   bool user = false;
    1212        54822 :   enum conversion_rank rank = cr_exact;
    1213              : 
    1214        54822 :   if (len != 2)
    1215              :     return NULL;
    1216              : 
    1217        54782 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1218              : 
    1219       273910 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1220              :     {
    1221       109564 :       conversion *sub
    1222       109564 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1223              :                                false, flags, complain);
    1224       109564 :       if (sub == NULL)
    1225              :         return NULL;
    1226              : 
    1227       109564 :       if (sub->rank > rank)
    1228           44 :         rank = sub->rank;
    1229       109564 :       if (sub->user_conv_p)
    1230            0 :         user = true;
    1231       109564 :       if (sub->bad_p)
    1232            0 :         bad = true;
    1233              :     }
    1234              : 
    1235        54782 :   c = alloc_conversion (ck_aggr);
    1236        54782 :   c->type = type;
    1237        54782 :   c->rank = rank;
    1238        54782 :   c->user_conv_p = user;
    1239        54782 :   c->bad_p = bad;
    1240        54782 :   c->u.expr = ctor;
    1241        54782 :   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   1815383203 : build_identity_conv (tree type, tree expr)
    1249              : {
    1250   1815383203 :   conversion *c;
    1251              : 
    1252            0 :   c = alloc_conversion (ck_identity);
    1253   1815383203 :   c->type = type;
    1254   1815383203 :   c->u.expr = expr;
    1255              : 
    1256   1815383203 :   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         1345 : build_ambiguous_conv (tree type, tree expr)
    1265              : {
    1266         1345 :   conversion *c;
    1267              : 
    1268            0 :   c = alloc_conversion (ck_ambig);
    1269         1345 :   c->type = type;
    1270         1345 :   c->u.expr = expr;
    1271              : 
    1272         1345 :   return c;
    1273              : }
    1274              : 
    1275              : tree
    1276   3262617046 : strip_top_quals (tree t)
    1277              : {
    1278   3262617046 :   if (TREE_CODE (t) == ARRAY_TYPE)
    1279              :     return t;
    1280   3256626245 :   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   1455886121 : standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
    1290              :                      int flags, tsubst_flags_t complain)
    1291              : {
    1292   1455886121 :   enum tree_code fcode, tcode;
    1293   1455886121 :   conversion *conv;
    1294   1455886121 :   bool fromref = false;
    1295   1455886121 :   tree qualified_to;
    1296              : 
    1297   1455886121 :   to = non_reference (to);
    1298   1455886121 :   if (TYPE_REF_P (from))
    1299              :     {
    1300        73372 :       fromref = true;
    1301        73372 :       from = TREE_TYPE (from);
    1302              :     }
    1303   1455886121 :   qualified_to = to;
    1304   1455886121 :   to = strip_top_quals (to);
    1305   1455886121 :   from = strip_top_quals (from);
    1306              : 
    1307   1455886121 :   if (expr && type_unknown_p (expr))
    1308              :     {
    1309       262104 :       if (TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
    1310              :         {
    1311        30539 :           tsubst_flags_t tflags = tf_conv;
    1312        30539 :           expr = instantiate_type (to, expr, tflags);
    1313        30539 :           if (expr == error_mark_node)
    1314              :             return NULL;
    1315        19844 :           from = TREE_TYPE (expr);
    1316              :         }
    1317       231565 :       else if (TREE_CODE (to) == BOOLEAN_TYPE)
    1318              :         {
    1319              :           /* Necessary for eg, TEMPLATE_ID_EXPRs (c++/50961).  */
    1320         5122 :           expr = resolve_nondeduced_context (expr, complain);
    1321         5122 :           from = TREE_TYPE (expr);
    1322              :         }
    1323              :     }
    1324              : 
    1325   1455875426 :   fcode = TREE_CODE (from);
    1326   1455875426 :   tcode = TREE_CODE (to);
    1327              : 
    1328   1455875426 :   conv = build_identity_conv (from, expr);
    1329   1455875426 :   if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
    1330              :     {
    1331      6010684 :       from = type_decays_to (from);
    1332      6010684 :       fcode = TREE_CODE (from);
    1333              :       /* Tell convert_like that we're using the address.  */
    1334      6010684 :       conv->rvaluedness_matches_p = true;
    1335      6010684 :       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   1449864742 :   else if (fromref || (expr && obvalue_p (expr)))
    1341              :     {
    1342    338267984 :       if (expr)
    1343              :         {
    1344    338194624 :           tree bitfield_type;
    1345    338194624 :           bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1346    338194624 :           if (bitfield_type)
    1347              :             {
    1348      2304093 :               from = strip_top_quals (bitfield_type);
    1349      2304093 :               fcode = TREE_CODE (from);
    1350              :             }
    1351              :         }
    1352    338267984 :       conv = build_conv (ck_rvalue, from, conv);
    1353              :       /* If we're performing copy-initialization, remember to skip
    1354              :          explicit constructors.  */
    1355    338267984 :       if (flags & LOOKUP_ONLYCONVERTING)
    1356    289332238 :         conv->copy_init_p = true;
    1357              :     }
    1358              : 
    1359              :    /* Allow conversion between `__complex__' data types.  */
    1360   1455875426 :   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      2224135 :       conversion *part_conv = standard_conversion
    1366      2224135 :         (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, c_cast_p, flags,
    1367              :          complain);
    1368              : 
    1369      2224135 :       if (!part_conv)
    1370              :         conv = NULL;
    1371      2224135 :       else if (part_conv->kind == ck_identity)
    1372              :         /* Leave conv alone.  */;
    1373              :       else
    1374              :         {
    1375       230482 :           conv = build_conv (part_conv->kind, to, conv);
    1376       230482 :           conv->rank = part_conv->rank;
    1377              :         }
    1378              : 
    1379      2224135 :       return conv;
    1380              :     }
    1381              : 
    1382   1453651291 :   if (same_type_p (from, to))
    1383              :     {
    1384    887591387 :       if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
    1385     16485622 :         conv->type = qualified_to;
    1386    871105765 :       else if (from != to)
    1387              :         /* Use TO in order to not lose TO in diagnostics.  */
    1388     76300733 :         conv->type = to;
    1389    887591387 :       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    364935095 :   if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
    1397    364848529 :        || NULLPTR_TYPE_P (to))
    1398    571299745 :       && ((expr && null_ptr_cst_p (expr))
    1399    200990430 :           || NULLPTR_TYPE_P (from)))
    1400      5374224 :     conv = build_conv (ck_std, to, conv);
    1401    560685680 :   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
    1402    560146970 :            || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
    1403              :     {
    1404              :       /* For backwards brain damage compatibility, allow interconversion of
    1405              :          pointers and integers with a pedwarn.  */
    1406      2020240 :       conv = build_conv (ck_std, to, conv);
    1407      2020240 :       conv->bad_p = true;
    1408              :     }
    1409    558665440 :   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       345070 :       conv = build_conv (ck_std, to, conv);
    1414       345070 :       conv->bad_p = true;
    1415              :     }
    1416    558320370 :   else if ((tcode == POINTER_TYPE && fcode == POINTER_TYPE)
    1417    368374488 :            || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from)))
    1418              :     {
    1419         1735 :       tree to_pointee;
    1420         1735 :       tree from_pointee;
    1421              : 
    1422         1735 :       if (tcode == POINTER_TYPE)
    1423              :         {
    1424    189945882 :           to_pointee = TREE_TYPE (to);
    1425    189945882 :           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    189945882 :           if (TREE_CODE (to_pointee) == FUNCTION_TYPE
    1431    189945882 :               && TYPE_QUALS (to_pointee))
    1432            9 :             to_pointee = build_qualified_type (to_pointee, TYPE_UNQUALIFIED);
    1433    189945882 :           if (TREE_CODE (from_pointee) == FUNCTION_TYPE
    1434    189945882 :               && TYPE_QUALS (from_pointee))
    1435           54 :             from_pointee = build_qualified_type (from_pointee, TYPE_UNQUALIFIED);
    1436              :         }
    1437              :       else
    1438              :         {
    1439         1735 :           to_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (to);
    1440         1735 :           from_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (from);
    1441              :         }
    1442              : 
    1443    189947617 :       if (tcode == POINTER_TYPE
    1444    189947617 :           && same_type_ignoring_top_level_qualifiers_p (from_pointee,
    1445              :                                                         to_pointee))
    1446              :         ;
    1447    134052822 :       else if (VOID_TYPE_P (to_pointee)
    1448      4347316 :                && !TYPE_PTRDATAMEM_P (from)
    1449      4347316 :                && TREE_CODE (from_pointee) != FUNCTION_TYPE)
    1450              :         {
    1451      4346991 :           tree nfrom = TREE_TYPE (from);
    1452              :           /* Don't try to apply restrict to void.  */
    1453      4346991 :           int quals = cp_type_quals (nfrom) & ~TYPE_QUAL_RESTRICT;
    1454      4346991 :           from_pointee = cp_build_qualified_type (void_type_node, quals);
    1455      4346991 :           from = build_pointer_type (from_pointee);
    1456      4346991 :           conv = build_conv (ck_ptr, from, conv);
    1457      4346991 :         }
    1458    129705831 :       else if (TYPE_PTRDATAMEM_P (from))
    1459              :         {
    1460         1735 :           tree fbase = TYPE_PTRMEM_CLASS_TYPE (from);
    1461         1735 :           tree tbase = TYPE_PTRMEM_CLASS_TYPE (to);
    1462              : 
    1463         1735 :           if (same_type_p (fbase, tbase))
    1464              :             /* No base conversion needed.  */;
    1465          619 :           else if (DERIVED_FROM_P (fbase, tbase)
    1466         1026 :                    && (same_type_ignoring_top_level_qualifiers_p
    1467          407 :                        (from_pointee, to_pointee)))
    1468              :             {
    1469          383 :               from = build_ptrmem_type (tbase, from_pointee);
    1470          383 :               conv = build_conv (ck_pmem, from, conv);
    1471              :             }
    1472              :           else
    1473          236 :             return NULL;
    1474              :         }
    1475     63133567 :       else if (CLASS_TYPE_P (from_pointee)
    1476     63131206 :                && 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    192042556 :                && DERIVED_FROM_P (to_pointee, from_pointee))
    1489              :         {
    1490      5839556 :           from_pointee
    1491      5839556 :             = cp_build_qualified_type (to_pointee,
    1492              :                                        cp_type_quals (from_pointee));
    1493      5839556 :           from = build_pointer_type (from_pointee);
    1494      5839556 :           conv = build_conv (ck_ptr, from, conv);
    1495      5839556 :           conv->base_p = true;
    1496              :         }
    1497              : 
    1498    189947381 :       if (same_type_p (from, to))
    1499              :         /* OK */;
    1500    182284946 :       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          624 :         conv = build_conv (ck_qual, to, conv);
    1505    182284322 :       else if (!c_cast_p && comp_ptr_ttypes (to_pointee, from_pointee))
    1506     51308674 :         conv = build_conv (ck_qual, to, conv);
    1507    130975648 :       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    130975444 :       else if (fnptr_conv_p (to, from))
    1511       229232 :         conv = build_conv (ck_fnptr, to, conv);
    1512              :       /* Allow conversions among compatible ObjC pointer types (base
    1513              :          conversions have been already handled above).  */
    1514    130746212 :       else if (c_dialect_objc ()
    1515    130746212 :                && objc_compare_types (to, from, -4, NULL_TREE))
    1516            0 :         conv = build_conv (ck_ptr, to, conv);
    1517    130746212 :       else if (ptr_reasonably_similar (to_pointee, from_pointee))
    1518              :         {
    1519      8040454 :           conv = build_conv (ck_ptr, to, conv);
    1520      8040454 :           conv->bad_p = true;
    1521              :         }
    1522              :       else
    1523              :         return NULL;
    1524              : 
    1525    261654091 :       from = to;
    1526              :     }
    1527    368372753 :   else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
    1528              :     {
    1529        82890 :       tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
    1530        82890 :       tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
    1531        82890 :       tree fbase = class_of_this_parm (fromfn);
    1532        82890 :       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        82890 :       if (!same_type_p (fbase, tbase) && !DERIVED_FROM_P (fbase, tbase))
    1537              :         return NULL;
    1538              : 
    1539        82729 :       tree fstat = static_fn_type (fromfn);
    1540        82729 :       tree tstat = static_fn_type (tofn);
    1541        82729 :       if (same_type_p (tstat, fstat)
    1542        82729 :           || fnptr_conv_p (tstat, fstat))
    1543              :         /* OK */;
    1544              :       else
    1545              :         return NULL;
    1546              : 
    1547        82461 :       if (!same_type_p (fbase, tbase))
    1548              :         {
    1549        82390 :           from = build_memfn_type (fstat,
    1550              :                                    tbase,
    1551              :                                    cp_type_quals (tbase),
    1552              :                                    type_memfn_rqual (tofn));
    1553        82390 :           from = build_ptrmemfunc_type (build_pointer_type (from));
    1554        82390 :           conv = build_conv (ck_pmem, from, conv);
    1555        82390 :           conv->base_p = true;
    1556              :         }
    1557        82461 :       if (fnptr_conv_p (tstat, fstat))
    1558           71 :         conv = build_conv (ck_fnptr, to, conv);
    1559              :     }
    1560    368289863 :   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      6109898 :       if (ARITHMETIC_TYPE_P (from)
    1569      6050054 :           || UNSCOPED_ENUM_P (from)
    1570      3981453 :           || fcode == POINTER_TYPE
    1571      2793994 :           || TYPE_PTRMEM_P (from)
    1572     14371129 :           || NULLPTR_TYPE_P (from))
    1573              :         {
    1574      8783669 :           conv = build_conv (ck_std, to, conv);
    1575      8783669 :           if (fcode == POINTER_TYPE
    1576      7596210 :               || TYPE_PTRDATAMEM_P (from)
    1577      7596064 :               || (TYPE_PTRMEMFUNC_P (from)
    1578           77 :                   && conv->rank < cr_pbool)
    1579     16379656 :               || NULLPTR_TYPE_P (from))
    1580      1187764 :             conv->rank = cr_pbool;
    1581      8783669 :           if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
    1582           40 :             conv->bad_p = true;
    1583      8783669 :           if (flags & LOOKUP_NO_NARROWING)
    1584        30781 :             conv->check_narrowing = true;
    1585      8783669 :           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    356712505 :   else if (ARITHMETIC_TYPE_P (to))
    1594              :     {
    1595     29224698 :       if (! (INTEGRAL_CODE_P (fcode)
    1596     22965726 :              || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
    1597    216700345 :           || 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    186150655 :       if (!COMPLETE_TYPE_P (from))
    1604              :         return NULL;
    1605              : 
    1606    186150649 :       conv = build_conv (ck_std, to, conv);
    1607              : 
    1608    186150649 :       tree underlying_type = NULL_TREE;
    1609    186150649 :       if (TREE_CODE (from) == ENUMERAL_TYPE
    1610    186150649 :           && ENUM_FIXED_UNDERLYING_TYPE_P (from))
    1611      1623641 :         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    186150649 :       if ((same_type_p (to, type_promotes_to (from))
    1619    174791344 :            || (underlying_type && same_type_p (to, underlying_type)))
    1620    186150668 :           && next_conversion (conv)->rank <= cr_promotion)
    1621     11359324 :         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    186150649 :       if (fcode == REAL_TYPE
    1633    186150649 :           && tcode == REAL_TYPE
    1634     15496855 :           && (extended_float_type_p (from)
    1635     14921310 :               || extended_float_type_p (to))
    1636    189037791 :           && cp_compare_floating_point_conversion_ranks (from, to) >= 2)
    1637      1331371 :         conv->bad_p = true;
    1638              :     }
    1639    162977886 :   else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
    1640    162977886 :            && vector_types_convertible_p (from, to, false))
    1641         4884 :     return build_conv (ck_std, to, conv);
    1642    162973002 :   else if (MAYBE_CLASS_TYPE_P (to) && MAYBE_CLASS_TYPE_P (from)
    1643     65411963 :            && is_properly_derived_from (from, to))
    1644              :     {
    1645       439824 :       if (conv->kind == ck_rvalue)
    1646       439773 :         conv = next_conversion (conv);
    1647       439824 :       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       439824 :       conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
    1653              :       /* If we're performing copy-initialization, remember to skip
    1654              :          explicit constructors.  */
    1655       439824 :       if (flags & LOOKUP_ONLYCONVERTING)
    1656       439757 :         conv->copy_init_p = true;
    1657              :     }
    1658              :   else
    1659    162533178 :     return NULL;
    1660              : 
    1661    261654091 :   if (flags & LOOKUP_NO_NARROWING)
    1662     91537693 :     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    259933216 : reference_related_p (tree t1, tree t2)
    1673              : {
    1674    259933216 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1675              :     return false;
    1676              : 
    1677    259933212 :   t1 = TYPE_MAIN_VARIANT (t1);
    1678    259933212 :   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    259933212 :   return (similar_type_p (t1, t2)
    1685    259933212 :           || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    1686     63983780 :               && DERIVED_FROM_P (t1, t2)));
    1687              : }
    1688              : 
    1689              : /* Returns nonzero if T1 is reference-compatible with T2.  */
    1690              : 
    1691              : bool
    1692    230680267 : 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    230680267 :   tree ptype1 = build_pointer_type (t1);
    1700    230680267 :   tree ptype2 = build_pointer_type (t2);
    1701    230680267 :   conversion *conv = standard_conversion (ptype1, ptype2, NULL_TREE,
    1702              :                                           /*c_cast_p=*/false, 0, tf_none);
    1703    230680267 :   if (!conv || conv->bad_p)
    1704    128734030 :     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    112250814 : involves_qualification_conversion_p (tree to, tree from)
    1713              : {
    1714              :   /* If we're not converting a pointer to another one, we won't get
    1715              :      a qualification conversion.  */
    1716    112250814 :   if (!((TYPE_PTR_P (to) && TYPE_PTR_P (from))
    1717         2385 :         || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from))))
    1718              :     return false;
    1719              : 
    1720      4492853 :   conversion *conv = standard_conversion (to, from, NULL_TREE,
    1721              :                                           /*c_cast_p=*/false, 0, tf_none);
    1722      8970021 :   for (conversion *t = conv; t; t = next_conversion (t))
    1723      4492869 :     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         3646 : handler_match_for_exception_type (tree handler, tree except_type)
    1734              : {
    1735         3646 :   tree handler_type = HANDLER_TYPE (handler);
    1736         3646 :   if (handler_type == NULL_TREE)
    1737              :     return true; /* ... */
    1738         3588 :   if (same_type_ignoring_top_level_qualifiers_p (handler_type, except_type))
    1739              :     return true;
    1740          562 :   if (CLASS_TYPE_P (except_type) && CLASS_TYPE_P (handler_type))
    1741              :     {
    1742          138 :       base_kind b_kind;
    1743          138 :       tree binfo = lookup_base (except_type, handler_type, ba_check, &b_kind,
    1744              :                                 tf_none);
    1745          138 :       if (binfo && binfo != error_mark_node)
    1746           54 :         return true;
    1747              :     }
    1748          508 :   if (TYPE_PTR_P (handler_type) || TYPE_PTRDATAMEM_P (handler_type))
    1749              :     {
    1750          120 :       if (TREE_CODE (except_type) == NULLPTR_TYPE)
    1751              :         return true;
    1752          108 :       if ((TYPE_PTR_P (handler_type) && TYPE_PTR_P (except_type))
    1753           18 :           || (TYPE_PTRDATAMEM_P (handler_type)
    1754            0 :               && TYPE_PTRDATAMEM_P (except_type)))
    1755              :         {
    1756           90 :           conversion *conv
    1757           90 :             = standard_conversion (handler_type, except_type, NULL_TREE,
    1758              :                                    /*c_cast_p=*/false, 0, tf_none);
    1759           90 :           if (conv && !conv->bad_p)
    1760              :             {
    1761           66 :               for (conversion *t = conv; t; t = next_conversion (t))
    1762           44 :                 switch (t->kind)
    1763              :                   {
    1764           44 :                   case ck_ptr:
    1765           44 :                   case ck_fnptr:
    1766           44 :                   case ck_qual:
    1767           44 :                   case ck_identity:
    1768           44 :                     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    115804962 : direct_reference_binding (tree type, conversion *conv)
    1785              : {
    1786    115804962 :   tree t;
    1787              : 
    1788    115804962 :   gcc_assert (TYPE_REF_P (type));
    1789    115804962 :   gcc_assert (!TYPE_REF_P (conv->type));
    1790              : 
    1791    115804962 :   t = TREE_TYPE (type);
    1792              : 
    1793    115804962 :   if (conv->kind == ck_identity)
    1794              :     /* Mark the identity conv as to not decay to rvalue.  */
    1795    115804962 :     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    115804962 :   if (is_properly_derived_from (conv->type, t))
    1814              :     {
    1815              :       /* Represent the derived-to-base conversion.  */
    1816      3554148 :       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      3554148 :       conv->need_temporary_p = false;
    1821              :     }
    1822    112250814 :   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        15701 :     conv = build_conv (ck_qual, strip_top_quals (t), conv);
    1846              : 
    1847    115804962 :   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    229875478 : reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
    1859              :                    tsubst_flags_t complain)
    1860              : {
    1861    229875478 :   conversion *conv = NULL;
    1862    229875478 :   conversion *bad_direct_conv = nullptr;
    1863    229875478 :   tree to = TREE_TYPE (rto);
    1864    229875478 :   tree from = rfrom;
    1865    229875478 :   tree tfrom;
    1866    229875478 :   bool related_p;
    1867    229875478 :   bool compatible_p;
    1868    229875478 :   cp_lvalue_kind gl_kind;
    1869    229875478 :   bool is_lvalue;
    1870              : 
    1871    229875478 :   if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
    1872              :     {
    1873           50 :       expr = instantiate_type (to, expr, tf_none);
    1874           50 :       if (expr == error_mark_node)
    1875              :         return NULL;
    1876           50 :       from = TREE_TYPE (expr);
    1877              :     }
    1878              : 
    1879    229875478 :   bool copy_list_init = false;
    1880    229875478 :   bool single_list_conv = false;
    1881    229875478 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    1882              :     {
    1883        90114 :       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        90114 :       if (CONSTRUCTOR_NELTS (expr) == 1
    1895        49483 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    1896              :         {
    1897         3845 :           tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    1898         3845 :           if (error_operand_p (elt))
    1899              :             return NULL;
    1900         3840 :           tree etype = TREE_TYPE (elt);
    1901         3840 :           if (reference_related_p (to, etype))
    1902              :             {
    1903          672 :               expr = elt;
    1904          672 :               from = etype;
    1905          672 :               goto skip;
    1906              :             }
    1907         3168 :           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    229875473 :     skip:;
    1918              :     }
    1919              : 
    1920    229875473 :   if (TYPE_REF_P (from))
    1921              :     {
    1922        55653 :       from = TREE_TYPE (from);
    1923        55653 :       if (!TYPE_REF_IS_RVALUE (rfrom)
    1924        55653 :           || TREE_CODE (from) == FUNCTION_TYPE)
    1925              :         gl_kind = clk_ordinary;
    1926              :       else
    1927              :         gl_kind = clk_rvalueref;
    1928              :     }
    1929    229819820 :   else if (expr)
    1930    226564658 :     gl_kind = lvalue_kind (expr);
    1931      2991021 :   else if (CLASS_TYPE_P (from)
    1932      3255162 :            || 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    229875473 :   if ((flags & LOOKUP_NO_TEMP_BIND)
    1939      3388181 :       && (gl_kind & clk_class))
    1940              :     gl_kind = clk_none;
    1941              : 
    1942              :   /* Same mask as real_lvalue_p.  */
    1943    227271725 :   is_lvalue = gl_kind && !(gl_kind & (clk_rvalueref|clk_class));
    1944              : 
    1945    196193795 :   tfrom = from;
    1946    196193795 :   if ((gl_kind & clk_bitfield) != 0)
    1947      1640345 :     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    229875473 :   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    229875473 :   if (related_p && c_cast_p
    1956    229875473 :       && !at_least_as_qualified_p (to, tfrom))
    1957          196 :     to = cp_build_qualified_type (to, cp_type_quals (tfrom));
    1958    229875473 :   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    229875473 :   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    103049120 :       conv = build_identity_conv (tfrom, expr);
    1984    103049120 :       conv = direct_reference_binding (rto, conv);
    1985              : 
    1986    103049120 :       if (TYPE_REF_P (rfrom))
    1987              :         /* Handle rvalue reference to function properly.  */
    1988        14248 :         conv->rvaluedness_matches_p
    1989        14248 :           = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
    1990              :       else
    1991    103034872 :         conv->rvaluedness_matches_p
    1992    103034872 :           = (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
    1993              : 
    1994    103049120 :       if ((gl_kind & clk_bitfield) != 0
    1995    103049120 :           || ((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     75112091 :       if (is_lvalue && TYPE_REF_IS_RVALUE (rto)
    2012    112595362 :           && TREE_CODE (to) != FUNCTION_TYPE)
    2013      9544517 :         conv->bad_p = true;
    2014              : 
    2015              :       /* Nor the reverse.  */
    2016     27937029 :       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     17340463 :           && !(cxx_dialect <= cxx20
    2021     14486458 :                && (gl_kind & clk_implicit_rval))
    2022     16271713 :           && (!CP_TYPE_CONST_NON_VOLATILE_P (to)
    2023     16162060 :               || (flags & LOOKUP_NO_RVAL_BIND))
    2024    103158773 :           && TREE_CODE (to) != FUNCTION_TYPE)
    2025       109653 :         conv->bad_p = true;
    2026              : 
    2027    103049120 :       if (!compatible_p)
    2028      6195154 :         conv->bad_p = true;
    2029              : 
    2030    103049120 :       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      4289821 :   else if (!related_p
    2037    122536532 :            && !(flags & LOOKUP_NO_CONVERSION)
    2038     45698699 :            && (CLASS_TYPE_P (from) || single_list_conv))
    2039              :     {
    2040     16779362 :       tree rexpr = expr;
    2041     16779362 :       if (single_list_conv)
    2042           96 :         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     16779362 :       z_candidate *cand = build_user_type_conversion_1 (rto, rexpr, flags,
    2058              :                                                         complain);
    2059     16779362 :       if (cand)
    2060              :         {
    2061        11569 :           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    126815183 :   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    123645711 :   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    163727144 :   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    123645711 :   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    123645711 :   if (!maybe_valid_p && (flags & LOOKUP_SHORTCUT_BAD_CONVS))
    2116              :     {
    2117      7324249 :       if (bad_direct_conv)
    2118              :         return bad_direct_conv;
    2119              : 
    2120      7323920 :       conv = alloc_conversion (ck_deferred_bad);
    2121      7323920 :       conv->bad_p = true;
    2122      7323920 :       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    116321462 :   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    116321462 :   if (!(flags & LOOKUP_COPY_PARM))
    2137     98227017 :     flags |= LOOKUP_ONLYCONVERTING;
    2138              : 
    2139    116321462 :   if (!conv)
    2140    116321462 :     conv = implicit_conversion (to, from, expr, c_cast_p,
    2141              :                                 flags, complain);
    2142    116321462 :   if (!conv)
    2143              :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2144              : 
    2145     11186496 :   if (conv->user_conv_p)
    2146              :     {
    2147      7469056 :       if (copy_list_init)
    2148              :         /* Remember this was copy-list-initialization.  */
    2149        61630 :         conv->need_temporary_p = true;
    2150              : 
    2151              :       /* If initializing the temporary used a conversion function,
    2152              :          recalculate the second conversion sequence.  */
    2153     21546088 :       for (conversion *t = conv; t; t = next_conversion (t))
    2154     14494865 :         if (t->kind == ck_user
    2155      7441838 :             && 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     14494853 :         else if (t->kind == ck_user
    2165     14494853 :                  && DECL_CONV_FN_P (t->cand->fn))
    2166              :           {
    2167       417821 :             tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn));
    2168              :             /* A prvalue of non-class type is cv-unqualified.  */
    2169       417821 :             if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype))
    2170         1890 :               ftype = cv_unqualified (ftype);
    2171       417821 :             int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND;
    2172       417821 :             conversion *new_second
    2173       417821 :               = reference_binding (rto, ftype, NULL_TREE, c_cast_p,
    2174              :                                    sflags, complain);
    2175       417821 :             if (!new_second)
    2176              :               return bad_direct_conv ? bad_direct_conv : nullptr;
    2177       417821 :             conv = merge_conversion_sequences (t, new_second);
    2178       417821 :             gcc_assert (maybe_valid_p || conv->bad_p);
    2179              :             return conv;
    2180              :           }
    2181              :     }
    2182              : 
    2183     10768675 :   conv = build_conv (ck_ref_bind, rto, conv);
    2184              :   /* This reference binding, unlike those above, requires the
    2185              :      creation of a temporary.  */
    2186     10768675 :   conv->need_temporary_p = true;
    2187     10768675 :   conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
    2188     10768675 :   conv->bad_p |= !maybe_valid_p;
    2189              : 
    2190     10768675 :   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   1441876436 : implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
    2200              :                      int flags, tsubst_flags_t complain)
    2201              : {
    2202   1441876436 :   conversion *conv;
    2203              : 
    2204   1441876436 :   if (from == error_mark_node || to == error_mark_node
    2205   1441875119 :       || 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   1441875119 :   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   1441875119 :   complain &= ~tf_error;
    2220              : 
    2221              :   /* Call reshape_init early to remove redundant braces.  */
    2222   1441875119 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) && CLASS_TYPE_P (to))
    2223              :     {
    2224      2237832 :       to = complete_type (to);
    2225      2237832 :       if (!COMPLETE_TYPE_P (to))
    2226              :         return nullptr;
    2227      2237808 :       if (!CLASSTYPE_NON_AGGREGATE (to))
    2228              :         {
    2229      1251688 :           expr = reshape_init (to, expr, complain);
    2230      1251688 :           if (expr == error_mark_node)
    2231              :             return nullptr;
    2232      1251448 :           from = TREE_TYPE (expr);
    2233              :         }
    2234              :     }
    2235              : 
    2236              :   /* An argument should have gone through convert_from_reference.  */
    2237   1441874855 :   gcc_checking_assert (!expr || !TYPE_REF_P (from));
    2238              : 
    2239   1441874855 :   if (TYPE_REF_P (to))
    2240    223386079 :     conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
    2241              :   else
    2242   1218488776 :     conv = standard_conversion (to, from, expr, c_cast_p, flags, complain);
    2243              : 
    2244   1441874855 :   if (conv)
    2245              :     return conv;
    2246              : 
    2247    281454666 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    2248              :     {
    2249      4596716 :       if (is_std_init_list (to) && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2250        90783 :         return build_list_conv (to, expr, flags, complain);
    2251              : 
    2252              :       /* As an extension, allow list-initialization of _Complex.  */
    2253      4415141 :       if (TREE_CODE (to) == COMPLEX_TYPE
    2254      4469972 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2255              :         {
    2256        54822 :           conv = build_complex_conv (to, expr, flags, complain);
    2257        54822 :           if (conv)
    2258              :             return conv;
    2259              :         }
    2260              : 
    2261              :       /* Allow conversion from an initializer-list with one element to a
    2262              :          scalar type.  */
    2263      4360359 :       if (SCALAR_TYPE_P (to))
    2264              :         {
    2265      2189200 :           int nelts = CONSTRUCTOR_NELTS (expr);
    2266       340310 :           tree elt;
    2267              : 
    2268       340310 :           if (nelts == 0)
    2269      1848890 :             elt = build_value_init (to, tf_none);
    2270       340310 :           else if (nelts == 1 && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2271       339446 :             elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2272              :           else
    2273          864 :             elt = error_mark_node;
    2274              : 
    2275      2189200 :           conv = implicit_conversion (to, TREE_TYPE (elt), elt,
    2276              :                                       c_cast_p, flags, complain);
    2277      2189200 :           if (conv)
    2278              :             {
    2279      2187313 :               conv->check_narrowing = true;
    2280      2187313 :               if (BRACE_ENCLOSED_INITIALIZER_P (elt))
    2281              :                 /* Too many levels of braces, i.e. '{{1}}'.  */
    2282           16 :                 conv->bad_p = true;
    2283      2187313 :               return conv;
    2284              :             }
    2285              :         }
    2286      2171159 :       else if (TREE_CODE (to) == ARRAY_TYPE)
    2287         1866 :         return build_array_conv (to, expr, flags, complain);
    2288              :     }
    2289              : 
    2290    279119922 :   if (expr != NULL_TREE
    2291    272501804 :       && (MAYBE_CLASS_TYPE_P (from)
    2292    144836789 :           || MAYBE_CLASS_TYPE_P (to))
    2293    477102090 :       && (flags & LOOKUP_NO_CONVERSION) == 0)
    2294              :     {
    2295     74404947 :       struct z_candidate *cand;
    2296              : 
    2297     50871323 :       if (CLASS_TYPE_P (to)
    2298     50871275 :           && BRACE_ENCLOSED_INITIALIZER_P (expr)
    2299     76551358 :           && !CLASSTYPE_NON_AGGREGATE (complete_type (to)))
    2300      1251389 :         return build_aggr_conv (to, expr, flags, complain);
    2301              : 
    2302     73153558 :       cand = build_user_type_conversion_1 (to, expr, flags, complain);
    2303     73153558 :       if (cand)
    2304              :         {
    2305       881880 :           if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    2306       872549 :               && CONSTRUCTOR_NELTS (expr) == 1
    2307        56631 :               && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    2308     13935910 :               && !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        56243 :               tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2316        56243 :               tree elttype = TREE_TYPE (elt);
    2317        56243 :               if (reference_related_p (to, elttype))
    2318           85 :                 return implicit_conversion (to, elttype, elt,
    2319           85 :                                             c_cast_p, flags, complain);
    2320              :             }
    2321     13879194 :           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     73153473 :       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      6329460 : good_conversion (tree to, tree from, tree expr,
    2341              :                  int flags, tsubst_flags_t complain)
    2342              : {
    2343      6329460 :   conversion *c = implicit_conversion (to, from, expr, /*cast*/false,
    2344              :                                        flags, complain);
    2345      6329460 :   if (c && c->bad_p)
    2346      2549300 :     c = NULL;
    2347      6329460 :   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    995246109 : 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    995246109 :   struct z_candidate *cand = (struct z_candidate *)
    2363    995246109 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2364              : 
    2365    995246109 :   cand->fn = fn;
    2366    995246109 :   cand->first_arg = first_arg;
    2367    995246109 :   cand->args = args;
    2368    995246109 :   cand->convs = convs;
    2369    995246109 :   cand->num_convs = num_convs;
    2370    995246109 :   cand->access_path = access_path;
    2371    995246109 :   cand->conversion_path = conversion_path;
    2372    995246109 :   cand->viable = viable;
    2373    995246109 :   cand->reason = reason;
    2374    995246109 :   cand->next = *candidates;
    2375    995246109 :   cand->flags = flags;
    2376    995246109 :   *candidates = cand;
    2377              : 
    2378    995246109 :   if (convs && cand->reversed ())
    2379              :     /* Swap the conversions for comparison in joust; we'll swap them back
    2380              :        before build_over_call.  */
    2381     79871146 :     std::swap (convs[0], convs[1]);
    2382              : 
    2383    995246109 :   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    627763423 : add_ignored_candidate (z_candidate **candidates, tree fn)
    2392              : {
    2393              :   /* No need to dynamically allocate these.  */
    2394    627763423 :   static const rejection_reason reason_ignored = { rr_ignored, {} };
    2395              : 
    2396    627763423 :   struct z_candidate *cand = (struct z_candidate *)
    2397    627758886 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2398              : 
    2399    627763423 :   cand->fn = fn;
    2400    627763423 :   cand->reason = const_cast<rejection_reason *> (&reason_ignored);
    2401    627763423 :   cand->next = *candidates;
    2402    627763423 :   *candidates = cand;
    2403              : 
    2404    627763423 :   return cand;
    2405              : }
    2406              : 
    2407              : /* True iff CAND is a candidate added by add_ignored_candidate.  */
    2408              : 
    2409              : static bool
    2410    558639775 : ignored_candidate_p (const z_candidate *cand)
    2411              : {
    2412    558633672 :   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    145212241 : remaining_arguments (tree arg)
    2420              : {
    2421    145212241 :   int n;
    2422              : 
    2423    252928480 :   for (n = 0; arg != NULL_TREE && arg != void_list_node;
    2424    107716239 :        arg = TREE_CHAIN (arg))
    2425    107716239 :     n++;
    2426              : 
    2427    145212241 :   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    417062616 : conv_flags (int i, int nargs, tree fn, tree arg, int flags)
    2441              : {
    2442    417062616 :   int lflags = flags;
    2443    417062616 :   tree t;
    2444    433449862 :   if (i == 0 && nargs == 1 && DECL_CONSTRUCTOR_P (fn)
    2445    139055129 :       && (t = FUNCTION_FIRST_USER_PARMTYPE (fn))
    2446    556117745 :       && (same_type_ignoring_top_level_qualifiers_p
    2447    139055129 :           (non_reference (TREE_VALUE (t)), DECL_CONTEXT (fn))))
    2448              :     {
    2449    108179915 :       if (!(flags & LOOKUP_ONLYCONVERTING))
    2450     33120289 :         lflags |= LOOKUP_COPY_PARM;
    2451    108179915 :       if ((flags & LOOKUP_LIST_INIT_CTOR)
    2452    108179915 :           && BRACE_ENCLOSED_INITIALIZER_P (arg))
    2453         1477 :         lflags |= LOOKUP_NO_CONVERSION;
    2454              :     }
    2455              :   else
    2456    308882701 :     lflags |= LOOKUP_ONLYCONVERTING;
    2457              : 
    2458    417062616 :   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     89891007 : build_this_conversion (tree fn, tree ctype,
    2467              :                        tree& parmtype, tree& argtype, tree& arg,
    2468              :                        int flags, tsubst_flags_t complain)
    2469              : {
    2470    179782014 :   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     89891007 :   parmtype = cp_build_qualified_type (ctype,
    2483     89891007 :                                       cp_type_quals (TREE_TYPE (parmtype)));
    2484     89891007 :   bool this_p = true;
    2485     89891007 :   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       157796 :       bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
    2490       157796 :       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       157796 :       this_p = false;
    2494              :     }
    2495              :   else
    2496              :     {
    2497     89733211 :       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     89733211 :       arg = build_address (arg);
    2502     89733211 :       argtype = lvalue_type (arg);
    2503              :     }
    2504     89891007 :   flags |= LOOKUP_ONLYCONVERTING;
    2505     89891007 :   conversion *t = implicit_conversion (parmtype, argtype, arg,
    2506              :                                        /*c_cast_p=*/false, flags, complain);
    2507     89891007 :   t->this_p = this_p;
    2508     89891007 :   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    592093959 : 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    592093959 :   tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2537    592093959 :   int i, len;
    2538    592093959 :   tree parmnode;
    2539    592093959 :   tree orig_first_arg = first_arg;
    2540    592093959 :   int skip;
    2541    592093959 :   int viable = 1;
    2542    592093959 :   struct rejection_reason *reason = NULL;
    2543              : 
    2544              :   /* The `this', `in_chrg' and VTT arguments to constructors are not
    2545              :      considered in overload resolution.  */
    2546   1184187918 :   if (DECL_CONSTRUCTOR_P (fn))
    2547              :     {
    2548    270165106 :       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    270165031 :         parmlist = skip_artificial_parms_for (fn, parmlist);
    2553    270165106 :       skip = num_artificial_parms_for (fn);
    2554    270165106 :       if (skip > 0 && first_arg != NULL_TREE)
    2555              :         {
    2556    270165106 :           --skip;
    2557    270165106 :           first_arg = NULL_TREE;
    2558              :         }
    2559              :     }
    2560              :   else
    2561              :     skip = 0;
    2562              : 
    2563   1145767697 :   len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0);
    2564    592093959 :   if (!convs)
    2565    512152681 :     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    592093959 :   parmnode = parmlist;
    2575   1209616571 :   for (i = 0; i < len; ++i)
    2576              :     {
    2577    689100708 :       if (parmnode == NULL_TREE || parmnode == void_list_node)
    2578              :         break;
    2579    617522612 :       parmnode = TREE_CHAIN (parmnode);
    2580              :     }
    2581              : 
    2582    592093959 :   if ((i < len && parmnode)
    2583    592093959 :       || !sufficient_parms_p (parmnode))
    2584              :     {
    2585    145208797 :       int remaining = remaining_arguments (parmnode);
    2586    145208797 :       viable = 0;
    2587    145208797 :       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    542567465 :   if (viable && len == 1 && parmlist && DECL_CONSTRUCTOR_P (fn)
    2596    141246161 :       && flag_new_inheriting_ctors
    2597    733331435 :       && DECL_INHERITED_CTOR (fn))
    2598              :     {
    2599       844549 :       tree ptype = non_reference (TREE_VALUE (parmlist));
    2600       844549 :       tree dtype = DECL_CONTEXT (fn);
    2601      1689098 :       tree btype = DECL_INHERITED_CTOR_BASE (fn);
    2602       844549 :       if (reference_related_p (ptype, dtype)
    2603       844549 :           && reference_related_p (btype, ptype))
    2604              :         {
    2605       599968 :           viable = false;
    2606       599968 :           reason = inherited_ctor_rejection ();
    2607              :         }
    2608              :     }
    2609              : 
    2610              :   /* Second, for a function to be viable, its constraints must be
    2611              :      satisfied. */
    2612    592093959 :   if (flag_concepts && viable && !constraints_satisfied_p (fn))
    2613              :     {
    2614       161227 :       reason = constraint_failure ();
    2615       161227 :       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    592093959 :   if (viable && parmlist && (flags & LOOKUP_DEFAULTED))
    2622              :     {
    2623     75383156 :       if (DECL_CONSTRUCTOR_P (fn))
    2624              :         i = 1;
    2625     19628823 :       else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    2626     19628823 :                && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    2627              :         i = 2;
    2628              :       else
    2629              :         i = 0;
    2630     37691578 :       if (i && len == i)
    2631              :         {
    2632     20789441 :           parmnode = chain_index (i-1, parmlist);
    2633     20789441 :           if (!reference_related_p (non_reference (TREE_VALUE (parmnode)),
    2634              :                                     ctype))
    2635      4221292 :             viable = 0;
    2636              :         }
    2637              : 
    2638              :       /* This only applies at the top level.  */
    2639     33470286 :       flags &= ~LOOKUP_DEFAULTED;
    2640              :     }
    2641              : 
    2642    592093959 :   if (! viable)
    2643    150191284 :     goto out;
    2644              : 
    2645    441902675 :   if (shortcut_bad_convs)
    2646    441774725 :     flags |= LOOKUP_SHORTCUT_BAD_CONVS;
    2647              :   else
    2648       127950 :     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    441902675 :   parmnode = parmlist;
    2655              : 
    2656    761117961 :   for (i = 0; i < len; ++i)
    2657              :     {
    2658    484560916 :       tree argtype, to_type;
    2659    484560916 :       tree arg;
    2660              : 
    2661    484560916 :       if (parmnode == void_list_node)
    2662              :         break;
    2663              : 
    2664    484560916 :       if (convs[i])
    2665              :         {
    2666              :           /* Already set during deduction.  */
    2667      5724164 :           parmnode = TREE_CHAIN (parmnode);
    2668      5724164 :           continue;
    2669              :         }
    2670              : 
    2671    478836752 :       if (i == 0 && first_arg != NULL_TREE)
    2672     86340295 :         arg = first_arg;
    2673              :       else
    2674    392496457 :         arg = const_cast<tree> (
    2675    751397954 :                 (*args)[i + skip - (first_arg != NULL_TREE ? 1 : 0)]);
    2676    478836752 :       argtype = lvalue_type (arg);
    2677              : 
    2678    478836752 :       conversion *t;
    2679    478836752 :       if (parmnode)
    2680              :         {
    2681    473672826 :           tree parmtype = TREE_VALUE (parmnode);
    2682    473672826 :           if (i == 0
    2683    382973940 :               && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2684    926372616 :               && !DECL_CONSTRUCTOR_P (fn))
    2685     86327673 :             t = build_this_conversion (fn, ctype, parmtype, argtype, arg,
    2686              :                                        flags, complain);
    2687              :           else
    2688              :             {
    2689    387345153 :               int lflags = conv_flags (i, len-skip, fn, arg, flags);
    2690    387345153 :               t = implicit_conversion (parmtype, argtype, arg,
    2691              :                                        /*c_cast_p=*/false, lflags, complain);
    2692              :             }
    2693    473672826 :           to_type = parmtype;
    2694    473672826 :           parmnode = TREE_CHAIN (parmnode);
    2695              :         }
    2696              :       else
    2697              :         {
    2698      5163926 :           t = build_identity_conv (argtype, arg);
    2699      5163926 :           t->ellipsis_p = true;
    2700      5163926 :           to_type = argtype;
    2701              :         }
    2702              : 
    2703    478836752 :       convs[i] = t;
    2704    478836752 :       if (! t)
    2705              :         {
    2706    144449285 :           viable = 0;
    2707    144449285 :           reason = arg_conversion_rejection (first_arg, i, argtype, to_type,
    2708    144449285 :                                              EXPR_LOCATION (arg));
    2709    144449285 :           break;
    2710              :         }
    2711              : 
    2712    334387467 :       if (t->bad_p)
    2713              :         {
    2714     20927431 :           viable = -1;
    2715     20927431 :           reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type,
    2716     20927431 :                                                  EXPR_LOCATION (arg));
    2717     20927431 :           if (shortcut_bad_convs)
    2718              :             break;
    2719              :         }
    2720              :     }
    2721              : 
    2722    276557045 :  out:
    2723    592093959 :   return add_candidate (candidates, fn, orig_first_arg, args, len, convs,
    2724    592093959 :                         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        96173 : 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        96173 :   tree totype = TREE_TYPE (TREE_TYPE (fn));
    2746        96173 :   int i, len, viable, flags;
    2747        96173 :   tree parmlist, parmnode;
    2748        96173 :   conversion **convs;
    2749        96173 :   struct rejection_reason *reason;
    2750              : 
    2751       192567 :   for (parmlist = totype; TREE_CODE (parmlist) != FUNCTION_TYPE; )
    2752        96394 :     parmlist = TREE_TYPE (parmlist);
    2753        96173 :   parmlist = TYPE_ARG_TYPES (parmlist);
    2754              : 
    2755        96173 :   len = vec_safe_length (arglist) + 1;
    2756        96173 :   convs = alloc_conversions (len);
    2757        96173 :   parmnode = parmlist;
    2758        96173 :   viable = 1;
    2759        96173 :   flags = LOOKUP_IMPLICIT;
    2760        96173 :   reason = NULL;
    2761              : 
    2762              :   /* Don't bother looking up the same type twice.  */
    2763        96173 :   if (*candidates && (*candidates)->fn == totype)
    2764              :     return NULL;
    2765              : 
    2766        96158 :   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       313950 :   for (i = 0; i < len; ++i)
    2775              :     {
    2776       217968 :       tree arg, argtype, convert_type = NULL_TREE;
    2777       217968 :       conversion *t;
    2778              : 
    2779       217968 :       if (i == 0)
    2780              :         arg = obj;
    2781              :       else
    2782       121819 :         arg = (*arglist)[i - 1];
    2783       217968 :       argtype = lvalue_type (arg);
    2784              : 
    2785       217968 :       if (i == 0)
    2786              :         {
    2787        96149 :           t = build_identity_conv (argtype, NULL_TREE);
    2788        96149 :           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        96149 :           convert_type = totype;
    2792              :         }
    2793       121819 :       else if (parmnode == void_list_node)
    2794              :         break;
    2795       121723 :       else if (parmnode)
    2796              :         {
    2797       121714 :           t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg,
    2798              :                                    /*c_cast_p=*/false, flags, complain);
    2799       121714 :           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       217872 :       convs[i] = t;
    2809       217872 :       if (! t)
    2810              :         break;
    2811              : 
    2812       217801 :       if (t->bad_p)
    2813              :         {
    2814           27 :           viable = -1;
    2815           72 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, arg, convert_type,
    2816           27 :                                                  EXPR_LOCATION (arg));
    2817              :         }
    2818              : 
    2819       217801 :       if (i == 0)
    2820        96149 :         continue;
    2821              : 
    2822       121652 :       if (parmnode)
    2823       121643 :         parmnode = TREE_CHAIN (parmnode);
    2824              :     }
    2825              : 
    2826        96149 :   if (i < len
    2827        96149 :       || ! sufficient_parms_p (parmnode))
    2828              :     {
    2829          191 :       int remaining = remaining_arguments (parmnode);
    2830          191 :       viable = 0;
    2831          191 :       reason = arity_rejection (NULL_TREE, i + remaining, len);
    2832              :     }
    2833              : 
    2834        96149 :   return add_candidate (candidates, totype, obj, arglist, len, convs,
    2835        96149 :                         access_path, conversion_path, viable, reason, flags);
    2836              : }
    2837              : 
    2838              : static void
    2839      8970814 : 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      8970814 :   conversion *t;
    2844      8970814 :   conversion **convs;
    2845      8970814 :   size_t num_convs;
    2846      8970814 :   int viable = 1;
    2847      8970814 :   tree types[2];
    2848      8970814 :   struct rejection_reason *reason = NULL;
    2849              : 
    2850      8970814 :   types[0] = type1;
    2851      8970814 :   types[1] = type2;
    2852              : 
    2853      8970814 :   num_convs = args.length ();
    2854      8970814 :   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      8970814 :   if (type1 != boolean_type_node)
    2862      8433219 :     flags |= LOOKUP_ONLYCONVERTING;
    2863              : 
    2864     26212751 :   for (unsigned i = 0; i < 2 && i < num_convs; ++i)
    2865              :     {
    2866     17241937 :       t = implicit_conversion (types[i], argtypes[i], args[i],
    2867              :                                /*c_cast_p=*/false, flags, complain);
    2868     17241937 :       if (! t)
    2869              :         {
    2870      1819686 :           viable = 0;
    2871              :           /* We need something for printing the candidate.  */
    2872      1819686 :           t = build_identity_conv (types[i], NULL_TREE);
    2873      1819686 :           reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i],
    2874      1819686 :                                              types[i], EXPR_LOCATION (args[i]));
    2875              :         }
    2876     15422251 :       else if (t->bad_p)
    2877              :         {
    2878          187 :           viable = 0;
    2879          187 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, args[i],
    2880              :                                                  types[i],
    2881          187 :                                                  EXPR_LOCATION (args[i]));
    2882              :         }
    2883     17241937 :       convs[i] = t;
    2884              :     }
    2885              : 
    2886              :   /* For COND_EXPR we rearranged the arguments; undo that now.  */
    2887      8970814 :   if (num_convs == 3)
    2888              :     {
    2889          159 :       convs[2] = convs[1];
    2890          159 :       convs[1] = convs[0];
    2891          159 :       t = implicit_conversion (boolean_type_node, argtypes[2], args[2],
    2892              :                                /*c_cast_p=*/false, flags,
    2893              :                                complain);
    2894          159 :       if (t)
    2895          159 :         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      8970814 :   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      8970814 : }
    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         3038 : 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         3038 :   return ((CP_INTEGRAL_TYPE_P (type)
    2931          225 :            && same_type_p (type_promotes_to (type), type))
    2932         3038 :           || 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     13239952 : 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     13239952 :   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     13239952 :   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       108448 :     case INDIRECT_REF:
    3012       108448 :       if (TYPE_PTR_P (type1)
    3013       108448 :           && (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       197735 :     case NEGATE_EXPR:
    3031       197735 :       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       151103 :     case BIT_NOT_EXPR:
    3040       151103 :       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       193512 :     case MINUS_EXPR:
    3120       193512 :       if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
    3121              :         break;
    3122           13 :       if (TYPE_PTROB_P (type1)
    3123       193498 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3124              :         {
    3125            4 :           type2 = ptrdiff_type_node;
    3126            4 :           break;
    3127              :         }
    3128              :       /* FALLTHRU */
    3129       846459 :     case MULT_EXPR:
    3130       846459 :     case TRUNC_DIV_EXPR:
    3131       846459 :       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      6341201 :     case SPACESHIP_EXPR:
    3140      6341201 :     case EQ_EXPR:
    3141      6341201 :     case NE_EXPR:
    3142       207453 :       if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3143      6548654 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)))
    3144              :         break;
    3145      6341167 :       if (NULLPTR_TYPE_P (type1) && NULLPTR_TYPE_P (type2))
    3146              :         break;
    3147      6341161 :       if (TYPE_PTRMEM_P (type1) && null_ptr_cst_p (args[1]))
    3148              :         {
    3149              :           type2 = type1;
    3150              :           break;
    3151              :         }
    3152      6341158 :       if (TYPE_PTRMEM_P (type2) && null_ptr_cst_p (args[0]))
    3153              :         {
    3154              :           type1 = type2;
    3155              :           break;
    3156              :         }
    3157              :       /* Fall through.  */
    3158      7028975 :     case LT_EXPR:
    3159      7028975 :     case GT_EXPR:
    3160      7028975 :     case LE_EXPR:
    3161      7028975 :     case GE_EXPR:
    3162      7028975 :     case MAX_EXPR:
    3163      7028975 :     case MIN_EXPR:
    3164      7028975 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3165              :         break;
    3166      5413858 :       if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3167              :         break;
    3168      5410177 :       if (TREE_CODE (type1) == ENUMERAL_TYPE
    3169      3864767 :           && TREE_CODE (type2) == ENUMERAL_TYPE)
    3170              :         break;
    3171      2636167 :       if (TYPE_PTR_P (type1)
    3172      2636167 :           && null_ptr_cst_p (args[1]))
    3173              :         {
    3174              :           type2 = type1;
    3175              :           break;
    3176              :         }
    3177      2636148 :       if (null_ptr_cst_p (args[0])
    3178      2636148 :           && TYPE_PTR_P (type2))
    3179              :         {
    3180              :           type1 = type2;
    3181              :           break;
    3182              :         }
    3183              :       return;
    3184              : 
    3185       219632 :     case PLUS_EXPR:
    3186       219632 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3187              :         break;
    3188              :       /* FALLTHRU */
    3189       164160 :     case ARRAY_REF:
    3190       164160 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && TYPE_PTROB_P (type2))
    3191              :         {
    3192            6 :           type1 = ptrdiff_type_node;
    3193            6 :           break;
    3194              :         }
    3195       164154 :       if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3196              :         {
    3197        35367 :           type2 = ptrdiff_type_node;
    3198        35367 :           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      2925211 :     case TRUNC_MOD_EXPR:
    3214      2925211 :     case BIT_AND_EXPR:
    3215      2925211 :     case BIT_IOR_EXPR:
    3216      2925211 :     case BIT_XOR_EXPR:
    3217      2925211 :     case LSHIFT_EXPR:
    3218      2925211 :     case RSHIFT_EXPR:
    3219      2925211 :       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      1714791 :     case MODIFY_EXPR:
    3260      1714791 :       switch (code2)
    3261              :         {
    3262        99352 :         case PLUS_EXPR:
    3263        99352 :         case MINUS_EXPR:
    3264        99352 :           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        99357 :         case MULT_EXPR:
    3271        99357 :         case TRUNC_DIV_EXPR:
    3272        99357 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3273              :             break;
    3274              :           return;
    3275              : 
    3276      1615434 :         case TRUNC_MOD_EXPR:
    3277      1615434 :         case BIT_AND_EXPR:
    3278      1615434 :         case BIT_IOR_EXPR:
    3279      1615434 :         case BIT_XOR_EXPR:
    3280      1615434 :         case LSHIFT_EXPR:
    3281      1615434 :         case RSHIFT_EXPR:
    3282      1615434 :           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      1381057 :       type1 = build_reference_type (type1);
    3305      1381057 :       break;
    3306              : 
    3307         2838 :     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         2838 :       if (promoted_arithmetic_type_p (type1)
    3323         2838 :           && promoted_arithmetic_type_p (type2))
    3324              :         /* That's OK.  */
    3325              :         break;
    3326              : 
    3327              :       /* Otherwise, the types should be pointers.  */
    3328         2813 :       if (!((TYPE_PTR_OR_PTRMEM_P (type1) || null_ptr_cst_p (args[0]))
    3329          369 :             && (TYPE_PTR_OR_PTRMEM_P (type2) || null_ptr_cst_p (args[1]))))
    3330         2679 :         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      8433094 :   bool u1 = uses_template_parms (type1);
    3350      8433094 :   bool u2 = type2 ? uses_template_parms (type2) : false;
    3351      8433081 :   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      8433084 :         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      8207876 :   if (type2 && !same_type_p (type1, type2)
    3373      1842786 :       && TREE_CODE (type1) == TREE_CODE (type2)
    3374      8859153 :       && (TYPE_REF_P (type1)
    3375       426069 :           || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3376       425953 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3377       425935 :           || TYPE_PTRMEMFUNC_P (type1)
    3378       425935 :           || MAYBE_CLASS_TYPE_P (type1)
    3379       425935 :           || TREE_CODE (type1) == ENUMERAL_TYPE))
    3380              :     {
    3381          229 :       if (TYPE_PTR_OR_PTRMEM_P (type1))
    3382              :         {
    3383          134 :           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          134 :           if (cptype != error_mark_node)
    3390              :             {
    3391           94 :               build_builtin_candidate
    3392           94 :                 (candidates, fnname, cptype, cptype, args, argtypes,
    3393              :                  flags, complain);
    3394           94 :               return;
    3395              :             }
    3396              :         }
    3397              : 
    3398          135 :       build_builtin_candidate
    3399          135 :         (candidates, fnname, type1, type1, args, argtypes, flags, complain);
    3400          135 :       build_builtin_candidate
    3401          135 :         (candidates, fnname, type2, type2, args, argtypes, flags, complain);
    3402          135 :       return;
    3403              :     }
    3404              : 
    3405      8432855 :   build_builtin_candidate
    3406      8432855 :     (candidates, fnname, type1, type2, args, argtypes, flags, complain);
    3407              : }
    3408              : 
    3409              : tree
    3410    804678173 : type_decays_to (tree type)
    3411              : {
    3412    804678173 :   if (TREE_CODE (type) == ARRAY_TYPE)
    3413      6043867 :     return build_pointer_type (TREE_TYPE (type));
    3414    798634306 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    3415        32068 :     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     23218801 : 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     23218801 :   int ref1;
    3439     23218801 :   int enum_p = 0;
    3440     23218801 :   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     23218801 :   vec<tree, va_gc> *types[2];
    3444     23218801 :   unsigned ix;
    3445     23218801 :   vec<tree, va_gc> &args = *argv;
    3446     23218801 :   unsigned len = args.length ();
    3447              : 
    3448     64831153 :   for (unsigned i = 0; i < len; ++i)
    3449              :     {
    3450     41612352 :       if (args[i])
    3451     41612352 :         argtypes[i] = unlowered_expr_type (args[i]);
    3452              :       else
    3453            0 :         argtypes[i] = NULL_TREE;
    3454              :     }
    3455              : 
    3456     23218801 :   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       474483 :     case TRUTH_NOT_EXPR:
    3477       474483 :       build_builtin_candidate
    3478       474483 :         (candidates, fnname, boolean_type_node,
    3479              :          NULL_TREE, args, argtypes, flags, complain);
    3480     13146455 :       return;
    3481              : 
    3482        63112 :     case TRUTH_ORIF_EXPR:
    3483        63112 :     case TRUTH_ANDIF_EXPR:
    3484        63112 :       build_builtin_candidate
    3485        63112 :         (candidates, fnname, boolean_type_node,
    3486              :          boolean_type_node, args, argtypes, flags, complain);
    3487        63112 :       return;
    3488              : 
    3489              :     case ADDR_EXPR:
    3490              :     case COMPOUND_EXPR:
    3491              :     case COMPONENT_REF:
    3492              :     case CO_AWAIT_EXPR:
    3493              :       return;
    3494              : 
    3495      5908566 :     case COND_EXPR:
    3496      5908566 :     case EQ_EXPR:
    3497      5908566 :     case NE_EXPR:
    3498      5908566 :     case LT_EXPR:
    3499      5908566 :     case LE_EXPR:
    3500      5908566 :     case GT_EXPR:
    3501      5908566 :     case GE_EXPR:
    3502      5908566 :     case SPACESHIP_EXPR:
    3503      5908566 :       enum_p = 1;
    3504              :       /* Fall through.  */
    3505              : 
    3506              :     default:
    3507              :       ref1 = 0;
    3508              :     }
    3509              : 
    3510     20600575 :   types[0] = make_tree_vector ();
    3511     20600575 :   types[1] = make_tree_vector ();
    3512              : 
    3513     20600575 :   if (len == 3)
    3514          714 :     len = 2;
    3515     42020760 :   for (unsigned i = 0; i < len; ++i)
    3516              :     {
    3517     31473931 :       if (MAYBE_CLASS_TYPE_P (argtypes[i]))
    3518              :         {
    3519     14358032 :           tree convs;
    3520              : 
    3521     14358032 :           if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
    3522              :             return;
    3523              : 
    3524     10998192 :           convs = lookup_conversions (argtypes[i]);
    3525              : 
    3526     10998192 :           if (code == COND_EXPR)
    3527              :             {
    3528         1251 :               if (lvalue_p (args[i]))
    3529          908 :                 vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3530              : 
    3531         1251 :               vec_safe_push (types[i], TYPE_MAIN_VARIANT (argtypes[i]));
    3532              :             }
    3533              : 
    3534     10996941 :           else if (! convs)
    3535              :             return;
    3536              : 
    3537     10606254 :           for (; convs; convs = TREE_CHAIN (convs))
    3538              :             {
    3539      6301968 :               type = TREE_TYPE (convs);
    3540              : 
    3541      7804944 :               if (i == 0 && ref1
    3542      6301968 :                   && (!TYPE_REF_P (type)
    3543         1319 :                       || CP_TYPE_CONST_P (TREE_TYPE (type))))
    3544      1502976 :                 continue;
    3545              : 
    3546      4798992 :               if (code == COND_EXPR && TYPE_REF_P (type))
    3547           24 :                 vec_safe_push (types[i], type);
    3548              : 
    3549      4798992 :               type = non_reference (type);
    3550      4798992 :               if (i != 0 || ! ref1)
    3551              :                 {
    3552      4798953 :                   type = cv_unqualified (type_decays_to (type));
    3553      4798953 :                   if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
    3554          328 :                     vec_safe_push (types[i], type);
    3555      4798953 :                   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3556      2712451 :                     type = type_promotes_to (type);
    3557              :                 }
    3558              : 
    3559      4798992 :               if (! vec_member (type, types[i]))
    3560      4794981 :                 vec_safe_push (types[i], type);
    3561              :             }
    3562              :         }
    3563              :       else
    3564              :         {
    3565     17115899 :           if (code == COND_EXPR && lvalue_p (args[i]))
    3566           93 :             vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3567     17115899 :           type = non_reference (argtypes[i]);
    3568     17115899 :           if (i != 0 || ! ref1)
    3569              :             {
    3570     15401211 :               type = cv_unqualified (type_decays_to (type));
    3571     15401211 :               if (enum_p && UNSCOPED_ENUM_P (type))
    3572      1831656 :                 vec_safe_push (types[i], type);
    3573     15401211 :               if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3574      8730534 :                 type = type_promotes_to (type);
    3575              :             }
    3576     17115899 :           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     21613367 :   FOR_EACH_VEC_ELT_REVERSE (*(types[0]), ix, t)
    3583              :     {
    3584     11066538 :       unsigned jx;
    3585     11066538 :       tree u;
    3586              : 
    3587     11066538 :       if (!types[1]->is_empty ())
    3588     23849121 :         FOR_EACH_VEC_ELT_REVERSE (*(types[1]), jx, u)
    3589     12782583 :           add_builtin_candidate
    3590     12782583 :             (candidates, code, code2, fnname, t,
    3591              :              u, args, argtypes, flags, complain);
    3592              :       else
    3593       457369 :         add_builtin_candidate
    3594       457369 :           (candidates, code, code2, fnname, t,
    3595              :            NULL_TREE, args, argtypes, flags, complain);
    3596              :     }
    3597              : 
    3598     10546829 :   release_tree_vector (types[0]);
    3599     10546829 :   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    474044553 : 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    474044553 :   int ntparms = DECL_NTPARMS (tmpl);
    3624    474044553 :   tree targs = make_tree_vec (ntparms);
    3625    474044553 :   unsigned int len = vec_safe_length (arglist);
    3626    474044553 :   unsigned int nargs = (first_arg == NULL_TREE ? 0 : 1) + len;
    3627    474044553 :   unsigned int skip_without_in_chrg = 0;
    3628    474044553 :   tree first_arg_without_in_chrg = first_arg;
    3629    474044553 :   tree *args_without_in_chrg;
    3630    474044553 :   unsigned int nargs_without_in_chrg;
    3631    474044553 :   unsigned int ia, ix;
    3632    474044553 :   tree arg;
    3633    474044553 :   struct z_candidate *cand;
    3634    474044553 :   tree fn;
    3635    474044553 :   struct rejection_reason *reason = NULL;
    3636    474044553 :   int errs;
    3637    474044553 :   conversion **convs = NULL;
    3638              : 
    3639              :   /* We don't do deduction on the in-charge parameter, the VTT
    3640              :      parameter or 'this'.  */
    3641    474044553 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (tmpl))
    3642              :     {
    3643     48616360 :       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    474044553 :         ++skip_without_in_chrg;
    3650              :     }
    3651              : 
    3652    474044553 :   if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
    3653    474044553 :        || DECL_BASE_CONSTRUCTOR_P (tmpl))
    3654    474977886 :       && 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    474044553 :   if (len < skip_without_in_chrg)
    3663            0 :     return add_ignored_candidate (candidates, tmpl);
    3664              : 
    3665    518618141 :   if (DECL_CONSTRUCTOR_P (tmpl) && nargs == 2
    3666    513683955 :       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (first_arg),
    3667     39639402 :                                                     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      2089538 :       if (tree firstparm = FUNCTION_FIRST_USER_PARMTYPE (tmpl))
    3680              :         {
    3681      2089538 :           firstparm = TREE_VALUE (firstparm);
    3682      2089538 :           if (PACK_EXPANSION_P (firstparm))
    3683         1996 :             firstparm = PACK_EXPANSION_PATTERN (firstparm);
    3684      2089538 :           if (TREE_CODE (firstparm) == TEMPLATE_TYPE_PARM)
    3685              :             {
    3686       674223 :               gcc_assert (!explicit_targs);
    3687       674223 :               reason = invalid_copy_with_fn_template_rejection ();
    3688       674223 :               goto fail;
    3689              :             }
    3690              :         }
    3691              :     }
    3692              : 
    3693    473370330 :   nargs_without_in_chrg = ((first_arg_without_in_chrg != NULL_TREE ? 1 : 0)
    3694    473370330 :                            + (len - skip_without_in_chrg));
    3695    473370330 :   args_without_in_chrg = XALLOCAVEC (tree, nargs_without_in_chrg);
    3696    473370330 :   ia = 0;
    3697    473370330 :   if (first_arg_without_in_chrg != NULL_TREE)
    3698              :     {
    3699         7862 :       args_without_in_chrg[ia] = first_arg_without_in_chrg;
    3700         7862 :       ++ia;
    3701              :     }
    3702    795386178 :   for (ix = skip_without_in_chrg;
    3703   1268756508 :        vec_safe_iterate (arglist, ix, &arg);
    3704              :        ++ix)
    3705              :     {
    3706    795386178 :       args_without_in_chrg[ia] = arg;
    3707    795386178 :       ++ia;
    3708              :     }
    3709    473370330 :   gcc_assert (ia == nargs_without_in_chrg);
    3710              : 
    3711    473370330 :   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    473370318 :       int min_arity = 0, max_arity = 0;
    3719    473370318 :       tree parms = TYPE_ARG_TYPES (TREE_TYPE (tmpl));
    3720    473370318 :       parms = skip_artificial_parms_for (tmpl, parms);
    3721   1780862206 :       for (; parms != void_list_node; parms = TREE_CHAIN (parms))
    3722              :         {
    3723   1673961810 :           if (!parms || PACK_EXPANSION_P (TREE_VALUE (parms)))
    3724              :             {
    3725              :               max_arity = -1;
    3726              :               break;
    3727              :             }
    3728    834121570 :           if (TREE_PURPOSE (parms))
    3729              :             /* A parameter with a default argument.  */
    3730      9294693 :             ++max_arity;
    3731              :           else
    3732    824826877 :             ++min_arity, ++max_arity;
    3733              :         }
    3734    473370318 :       if (ia < (unsigned)min_arity)
    3735              :         {
    3736              :           /* Too few arguments.  */
    3737     32471978 :           reason = arity_rejection (NULL_TREE, min_arity, ia,
    3738              :                                     /*least_p=*/(max_arity == -1));
    3739     32471978 :           goto fail;
    3740              :         }
    3741    440898340 :       else if (max_arity != -1 && ia > (unsigned)max_arity)
    3742              :         {
    3743              :           /* Too many arguments.  */
    3744      4754789 :           reason = arity_rejection (NULL_TREE, max_arity, ia);
    3745      4754789 :           goto fail;
    3746              :         }
    3747              : 
    3748    436143551 :       convs = alloc_conversions (nargs);
    3749              : 
    3750    436143551 :       if (shortcut_bad_convs
    3751    436138929 :           && DECL_IOBJ_MEMBER_FUNCTION_P (tmpl)
    3752    503720685 :           && !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      3563334 :           tree parmtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (tmpl)));
    3759      3563334 :           tree argtype = lvalue_type (first_arg);
    3760      3563334 :           tree arg = first_arg;
    3761      3563334 :           conversion *t = build_this_conversion (tmpl, ctype,
    3762              :                                                  parmtype, argtype, arg,
    3763              :                                                  flags, complain);
    3764      3563334 :           convs[0] = t;
    3765      3563334 :           if (t->bad_p)
    3766              :             {
    3767        32651 :               reason = bad_arg_conversion_rejection (first_arg, 0,
    3768              :                                                      arg, parmtype,
    3769        32651 :                                                      EXPR_LOCATION (arg));
    3770        32651 :               goto fail;
    3771              :             }
    3772              :         }
    3773              :     }
    3774              : 
    3775    436110912 :   errs = errorcount+sorrycount;
    3776    872208273 :   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    436110912 :                             false, complain & tf_decltype);
    3781              : 
    3782    436097361 :   if (fn == error_mark_node)
    3783              :     {
    3784              :       /* Don't repeat unification later if it already resulted in errors.  */
    3785    356150963 :       if (errorcount+sorrycount == errs)
    3786    356150853 :         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    356150963 :       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     79946398 :   if (((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    3799              :        == LOOKUP_ONLYCONVERTING)
    3800     79946398 :       && DECL_NONCONVERTING_P (fn))
    3801         4537 :     return add_ignored_candidate (candidates, fn);
    3802              : 
    3803    159883722 :   if (DECL_CONSTRUCTOR_P (fn) && nargs == 2)
    3804              :     {
    3805      4428118 :       tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3806      8856209 :       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          574 :           reason = invalid_copy_with_fn_template_rejection ();
    3813          574 :           goto fail;
    3814              :         }
    3815              :     }
    3816              : 
    3817     79941287 :   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     79941278 :     cand = add_function_candidate (candidates, fn, ctype,
    3823              :                                    first_arg, arglist, access_path,
    3824              :                                    conversion_path, flags, convs,
    3825              :                                    shortcut_bad_convs, complain);
    3826     79941287 :   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      5114780 :     cand->template_decl = build_template_info (tmpl, targs);
    3845              :   else
    3846     74826507 :     cand->template_decl = DECL_TEMPLATE_INFO (fn);
    3847     79941287 :   cand->explicit_targs = explicit_targs;
    3848              : 
    3849     79941287 :   return cand;
    3850    394085178 :  fail:
    3851    394085178 :   int viable = (reason->code == rr_bad_arg_conversion ? -1 : 0);
    3852    394085178 :   return add_candidate (candidates, tmpl, first_arg, arglist, nargs, convs,
    3853    394085178 :                         access_path, conversion_path, viable, reason, flags);
    3854              : }
    3855              : 
    3856              : 
    3857              : static struct z_candidate *
    3858    474044541 : 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    474044541 :   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    474030990 :                                  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    303156139 : splice_viable (struct z_candidate *cands,
    3904              :                bool strict_p,
    3905              :                bool *any_viable_p)
    3906              : {
    3907    303156139 :   z_candidate *strictly_viable = nullptr;
    3908    303156139 :   z_candidate **strictly_viable_tail = &strictly_viable;
    3909              : 
    3910    303156139 :   z_candidate *non_strictly_viable = nullptr;
    3911    303156139 :   z_candidate **non_strictly_viable_tail = &non_strictly_viable;
    3912              : 
    3913    303156139 :   z_candidate *non_viable = nullptr;
    3914    303156139 :   z_candidate **non_viable_tail = &non_viable;
    3915              : 
    3916    303156139 :   z_candidate *non_viable_ignored = nullptr;
    3917    303156139 :   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    303156139 :   if (processing_template_decl)
    3922     55541690 :     strict_p = true;
    3923              : 
    3924   1154221757 :   for (z_candidate *cand = cands; cand; cand = cand->next)
    3925              :     {
    3926    851065618 :       if (!strict_p
    3927    296266331 :           && (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    759150172 :         strict_p = true;
    3932              : 
    3933              :       /* Move this candidate to the appropriate list according to
    3934              :          its viability.  */
    3935    851065618 :       auto& tail = (cand->viable == 1 ? strictly_viable_tail
    3936              :                     : cand->viable == -1 ? non_strictly_viable_tail
    3937   1356314645 :                     : ignored_candidate_p (cand) ? non_viable_ignored_tail
    3938   1356314645 :                     : non_viable_tail);
    3939    851065618 :       *tail = cand;
    3940    851065618 :       tail = &cand->next;
    3941              :     }
    3942              : 
    3943    606312278 :   *any_viable_p = (strictly_viable != nullptr
    3944    303156139 :                    || (!strict_p && non_strictly_viable != nullptr));
    3945              : 
    3946              :   /* Combine the lists.  */
    3947    303156139 :   *non_viable_ignored_tail = nullptr;
    3948    303156139 :   *non_viable_tail = non_viable_ignored;
    3949    303156139 :   *non_strictly_viable_tail = non_viable;
    3950    303156139 :   *strictly_viable_tail = non_strictly_viable;
    3951              : 
    3952    303156139 :   return strictly_viable;
    3953              : }
    3954              : 
    3955              : static bool
    3956    289981478 : any_strictly_viable (struct z_candidate *cands)
    3957              : {
    3958    396091318 :   for (; cands; cands = cands->next)
    3959    114463117 :     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     63514844 : 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     63514844 :   if (processing_template_decl)
    3974        73509 :     return build_address (obj);
    3975              : 
    3976     63441335 :   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      4567674 : equal_functions (tree fn1, tree fn2)
    3985              : {
    3986      4567674 :   if (TREE_CODE (fn1) != TREE_CODE (fn2))
    3987              :     return 0;
    3988      4552329 :   if (TREE_CODE (fn1) == TEMPLATE_DECL)
    3989        36051 :     return fn1 == fn2;
    3990      9032538 :   if (DECL_LOCAL_DECL_P (fn1) || DECL_LOCAL_DECL_P (fn2)
    3991      9032535 :       || DECL_EXTERN_C_FUNCTION_P (fn1))
    3992      2890649 :     return decls_match (fn1, fn2);
    3993      1625629 :   return fn1 == fn2;
    3994              : }
    3995              : 
    3996              : /* Print information about a candidate FN being rejected due to INFO.  */
    3997              : 
    3998              : static void
    3999         5309 : print_conversion_rejection (location_t loc, struct conversion_info *info,
    4000              :                             tree fn)
    4001              : {
    4002         5309 :   tree from = info->from;
    4003         5309 :   if (!TYPE_P (from))
    4004         4369 :     from = lvalue_type (from);
    4005         5309 :   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         5285 :   else if (!TYPE_P (info->from))
    4019              :     {
    4020         4345 :       if (info->n_arg >= 0)
    4021         4345 :         inform (loc, "conversion of argument %d would be ill-formed:",
    4022              :                 info->n_arg + 1);
    4023         4345 :       iloc_sentinel ils = loc;
    4024         4345 :       perform_implicit_conversion (info->to_type, info->from,
    4025              :                                    tf_warning_or_error);
    4026         4345 :     }
    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         5309 : }
    4039              : 
    4040              : /* Print information about a candidate with WANT parameters and we found
    4041              :    HAVE.  */
    4042              : 
    4043              : static void
    4044         1457 : print_arity_information (location_t loc, unsigned int have, unsigned int want,
    4045              :                          bool least_p)
    4046              : {
    4047         1457 :   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         1416 :     inform_n (loc, want,
    4054              :               "candidate expects %d argument, %d provided",
    4055              :               "candidate expects %d arguments, %d provided",
    4056              :               want, have);
    4057         1457 : }
    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        13269 : print_z_candidate (location_t loc, const char *msgstr,
    4068              :                    struct z_candidate *candidate)
    4069              : {
    4070        13269 :   const char *msg = (msgstr == NULL
    4071        13269 :                      ? ""
    4072        13269 :                      : ACONCAT ((_(msgstr), " ", NULL)));
    4073        13269 :   tree fn = candidate->fn;
    4074        13269 :   if (flag_new_inheriting_ctors)
    4075        13242 :     fn = strip_inheriting_ctors (fn);
    4076        13269 :   location_t cloc = location_of (fn);
    4077              : 
    4078        13269 :   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        13055 :   else if (TYPE_P (fn))
    4095           15 :     inform (cloc, "%s%qT (conversion)", msg, fn);
    4096        13040 :   else if (candidate->viable == -1)
    4097         4376 :     inform (cloc, "%s%#qD (near match)", msg, fn);
    4098         8664 :   else if (ignored_candidate_p (candidate))
    4099            6 :     inform (cloc, "%s%#qD (ignored)", msg, fn);
    4100         8658 :   else if (DECL_DELETED_FN (fn))
    4101           60 :     inform (cloc, "%s%#qD (deleted)", msg, fn);
    4102         8598 :   else if (candidate->reversed ())
    4103          300 :     inform (cloc, "%s%#qD (reversed)", msg, fn);
    4104         8298 :   else if (candidate->rewritten ())
    4105          150 :     inform (cloc, "%s%#qD (rewritten)", msg, fn);
    4106              :   else
    4107         8148 :     inform (cloc, "%s%#qD", msg, fn);
    4108              : 
    4109        13269 :   auto_diagnostic_nesting_level sentinel;
    4110              : 
    4111        13269 :   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        13269 :   if (candidate->reason != NULL)
    4119              :     {
    4120        10156 :       struct rejection_reason *r = candidate->reason;
    4121              : 
    4122        10156 :       switch (r->code)
    4123              :         {
    4124         1457 :         case rr_arity:
    4125         1457 :           print_arity_information (cloc, r->u.arity.actual,
    4126         1457 :                                    r->u.arity.expected,
    4127         1457 :                                    r->u.arity.least_p);
    4128         1457 :           break;
    4129          913 :         case rr_arg_conversion:
    4130          913 :           print_conversion_rejection (cloc, &r->u.conversion, fn);
    4131          913 :           break;
    4132         4396 :         case rr_bad_arg_conversion:
    4133         4396 :           print_conversion_rejection (cloc, &r->u.bad_conversion, fn);
    4134         4396 :           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         3240 :         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         3240 :           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         3195 :           inform (cloc, "template argument deduction/substitution failed:");
    4159         3195 :           {
    4160         3195 :             auto_diagnostic_nesting_level sentinel;
    4161         3195 :             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         3195 :           }
    4172         3195 :           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        13269 : }
    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         5524 : print_z_candidates (location_t loc, struct z_candidate *candidates,
    4203              :                     tristate only_viable_p /* = tristate::unknown () */)
    4204              : {
    4205         5524 :   struct z_candidate *cand1;
    4206         5524 :   struct z_candidate **cand2;
    4207              : 
    4208         5524 :   if (!candidates)
    4209         1008 :     return;
    4210              : 
    4211              :   /* Remove non-viable deleted candidates.  */
    4212         4516 :   cand1 = candidates;
    4213        20362 :   for (cand2 = &cand1; *cand2; )
    4214              :     {
    4215        15846 :       if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
    4216        11429 :           && !(*cand2)->viable
    4217        19607 :           && DECL_DELETED_FN ((*cand2)->fn))
    4218          102 :         *cand2 = (*cand2)->next;
    4219              :       else
    4220        15744 :         cand2 = &(*cand2)->next;
    4221              :     }
    4222              :   /* ...if there are any non-deleted ones.  */
    4223         4516 :   if (cand1)
    4224         4510 :     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        19960 :   for (cand1 = candidates; cand1; cand1 = cand1->next)
    4232              :     {
    4233        15444 :       tree fn = cand1->fn;
    4234              :       /* Skip builtin candidates and conversion functions.  */
    4235        15444 :       if (!DECL_P (fn))
    4236          289 :         continue;
    4237        15155 :       cand2 = &cand1->next;
    4238       143288 :       while (*cand2)
    4239              :         {
    4240       128133 :           if (DECL_P ((*cand2)->fn)
    4241       128133 :               && equal_functions (fn, (*cand2)->fn))
    4242          306 :             *cand2 = (*cand2)->next;
    4243              :           else
    4244       127827 :             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         4516 :   if (only_viable_p.is_unknown ())
    4253         4507 :     only_viable_p = candidates->viable == 1;
    4254              : 
    4255         4516 :   auto_diagnostic_nesting_level sentinel;
    4256              : 
    4257         4516 :   int num_candidates = 0;
    4258        17675 :   for (auto iter = candidates; iter; iter = iter->next)
    4259              :     {
    4260        13500 :       if (only_viable_p.is_true () && iter->viable != 1)
    4261              :         break;
    4262        13159 :       ++num_candidates;
    4263              :     }
    4264              : 
    4265         4516 :   inform_num_candidates (loc, num_candidates);
    4266              : 
    4267         4516 :   auto_diagnostic_nesting_level sentinel2;
    4268              : 
    4269         4516 :   int candidate_idx = 0;
    4270        22156 :   for (; candidates; candidates = candidates->next)
    4271              :     {
    4272        13496 :       if (only_viable_p.is_true () && candidates->viable != 1)
    4273              :         break;
    4274        13192 :       if (ignored_candidate_p (candidates) && !flag_diagnostics_all_candidates)
    4275              :         {
    4276           31 :           inform (loc, "some candidates omitted; "
    4277              :                        "use %<-fdiagnostics-all-candidates%> to display them");
    4278           31 :           break;
    4279              :         }
    4280        13124 :       pretty_printer pp;
    4281        13124 :       pp_printf (&pp, N_("candidate %i:"), candidate_idx + 1);
    4282        13124 :       const char *const msgstr = pp_formatted_text (&pp);
    4283        13124 :       print_z_candidate (loc, msgstr, candidates);
    4284        13124 :       ++candidate_idx;
    4285        13124 :     }
    4286         4516 : }
    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     14329268 : merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
    4296              : {
    4297     14329268 :   conversion **t;
    4298     14329268 :   bool bad = user_seq->bad_p;
    4299              : 
    4300     14329268 :   gcc_assert (user_seq->kind == ck_user);
    4301              : 
    4302              :   /* Find the end of the second conversion sequence.  */
    4303     15038638 :   for (t = &std_seq; (*t)->kind != ck_identity; t = &((*t)->u.next))
    4304              :     {
    4305              :       /* The entire sequence is a user-conversion sequence.  */
    4306       709370 :       (*t)->user_conv_p = true;
    4307       709370 :       if (bad)
    4308         2902 :         (*t)->bad_p = true;
    4309              :     }
    4310              : 
    4311     14329268 :   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       427508 :     user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
    4316              : 
    4317              :   /* Replace the identity conversion with the user conversion
    4318              :      sequence.  */
    4319     14329268 :   *t = user_seq;
    4320              : 
    4321     14329268 :   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      2421237 : 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      2421237 :   gcc_assert (*candidates == NULL);
    4343              : 
    4344              :   /* We're looking for a ctor for list-initialization.  */
    4345      2421237 :   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      2421237 :   flags |= LOOKUP_NO_NARROWING;
    4349              : 
    4350      4842474 :   unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1;
    4351      2421237 :   tree init_list = (*args)[nart];
    4352              : 
    4353              :   /* Always use the default constructor if the list is empty (DR 990).  */
    4354      2421237 :   if (CONSTRUCTOR_NELTS (init_list) == 0
    4355      2421237 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
    4356              :     ;
    4357      2192690 :   else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list)
    4358      2192690 :            && !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        11339 :       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      2192642 :   else if (TYPE_HAS_LIST_CTOR (totype))
    4368              :     {
    4369        83504 :       flags |= LOOKUP_LIST_ONLY;
    4370        83504 :       add_candidates (fns, first_arg, args, NULL_TREE,
    4371              :                       explicit_targs, template_only, conversion_path,
    4372              :                       access_path, flags, candidates, complain);
    4373       167008 :       if (any_strictly_viable (*candidates))
    4374              :         return;
    4375              :     }
    4376              : 
    4377              :   /* Expand the CONSTRUCTOR into a new argument vec.  */
    4378      2409898 :   vec<tree, va_gc> *new_args;
    4379      4590522 :   vec_alloc (new_args, nart + CONSTRUCTOR_NELTS (init_list));
    4380      2409901 :   for (unsigned i = 0; i < nart; ++i)
    4381            3 :     new_args->quick_push ((*args)[i]);
    4382      2409898 :   new_args = append_ctor_to_tree_vector (new_args, init_list);
    4383              : 
    4384              :   /* We aren't looking for list-ctors anymore.  */
    4385      2409898 :   flags &= ~LOOKUP_LIST_ONLY;
    4386              :   /* We allow more user-defined conversions within an init-list.  */
    4387      2409898 :   flags &= ~LOOKUP_NO_CONVERSION;
    4388              : 
    4389      2409898 :   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         1440 : list_ctor_element_type (tree fn)
    4398              : {
    4399         1440 :   gcc_checking_assert (is_list_ctor (fn));
    4400              : 
    4401         1440 :   tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    4402         1440 :   parm = non_reference (TREE_VALUE (parm));
    4403         1440 :   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         1447 : braced_init_element_type (tree expr)
    4411              : {
    4412         1447 :   if (TREE_CODE (expr) == CONSTRUCTOR
    4413         1447 :       && TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE)
    4414            0 :     return TREE_TYPE (TREE_TYPE (expr));
    4415         1447 :   if (!BRACE_ENCLOSED_INITIALIZER_P (expr))
    4416              :     return NULL_TREE;
    4417              : 
    4418         1447 :   tree elttype = NULL_TREE;
    4419        14505 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (expr))
    4420              :     {
    4421        10348 :       tree type = TREE_TYPE (e.value);
    4422        10348 :       type = type_decays_to (type);
    4423        10348 :       if (!elttype)
    4424              :         elttype = type;
    4425         8920 :       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          255 : count_ctor_elements (tree ctor)
    4455              : {
    4456          255 :   unsigned HOST_WIDE_INT len = 0;
    4457         2086 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (ctor))
    4458         1321 :     if (TREE_CODE (e.value) == RAW_DATA_CST)
    4459            9 :       len += RAW_DATA_LENGTH (e.value);
    4460              :     else
    4461         1312 :       ++len;
    4462          255 :   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        17170 : 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        17170 :   if (!TYPE_NON_AGGREGATE_CLASS (elttype))
    4474              :     return NULL_TREE;
    4475         1447 :   tree init_elttype = braced_init_element_type (init);
    4476         1447 :   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          319 :   conversion_obstack_sentinel cos;
    4482          319 :   init_elttype = cp_build_qualified_type (init_elttype, TYPE_QUAL_CONST);
    4483          319 :   tree arg = build_stub_object (init_elttype);
    4484          319 :   conversion *c = implicit_conversion (elttype, init_elttype, arg, false,
    4485              :                                        LOOKUP_NORMAL, tf_none);
    4486          319 :   if (c && c->kind == ck_rvalue)
    4487            0 :     c = next_conversion (c);
    4488          313 :   if (!c || c->kind != ck_user)
    4489              :     return NULL_TREE;
    4490              :   /* Check that we actually can perform the conversion.  */
    4491          310 :   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          304 :   if (!DECL_CONSTRUCTOR_P (c->cand->fn)
    4498          304 :       || (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          301 :   tree first = CONSTRUCTOR_ELT (init, 0)->value;
    4505          301 :   conversion *fc = implicit_conversion (elttype, init_elttype, first, false,
    4506              :                                         LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING,
    4507              :                                         tf_none);
    4508          301 :   if (fc && fc->kind == ck_rvalue)
    4509           48 :     fc = next_conversion (fc);
    4510          301 :   if (!fc || fc->kind != ck_user || fc->cand->fn != c->cand->fn)
    4511              :     return NULL_TREE;
    4512          259 :   first = convert_like (fc, first, tf_none);
    4513          259 :   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          256 :   first = maybe_constant_init (first);
    4519          256 :   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          319 : }
    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     13911447 : maybe_init_list_as_range (tree fn, tree expr)
    4553              : {
    4554     13911447 :   if (!processing_template_decl
    4555     13405251 :       && BRACE_ENCLOSED_INITIALIZER_P (expr)
    4556       854011 :       && is_list_ctor (fn)
    4557     13913040 :       && decl_in_std_namespace_p (fn))
    4558              :     {
    4559         1440 :       tree to = list_ctor_element_type (fn);
    4560         1440 :       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     89955097 : build_user_type_conversion_1 (tree totype, tree expr, int flags,
    4583              :                               tsubst_flags_t complain)
    4584              : {
    4585     89955097 :   struct z_candidate *candidates, *cand;
    4586     89955097 :   tree fromtype;
    4587     89955097 :   tree ctors = NULL_TREE;
    4588     89955097 :   tree conv_fns = NULL_TREE;
    4589     89955097 :   conversion *conv = NULL;
    4590     89955097 :   tree first_arg = NULL_TREE;
    4591     89955097 :   vec<tree, va_gc> *args = NULL;
    4592     89955097 :   bool any_viable_p;
    4593     89955097 :   int convflags;
    4594              : 
    4595     89955097 :   if (!expr)
    4596              :     return NULL;
    4597              : 
    4598     89955091 :   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     89955091 :   gcc_assert (!MAYBE_CLASS_TYPE_P (fromtype) || !MAYBE_CLASS_TYPE_P (totype)
    4604              :               || !DERIVED_FROM_P (totype, fromtype));
    4605              : 
    4606     89955091 :   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     49641790 :     ctors = get_class_binding (totype, complete_ctor_identifier);
    4610              : 
    4611     89955091 :   tree to_nonref = non_reference (totype);
    4612     89955091 :   if (MAYBE_CLASS_TYPE_P (fromtype))
    4613              :     {
    4614     62685177 :       if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
    4615     62657804 :           (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
    4616     51232133 :            && 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     62657801 :         conv_fns = lookup_conversions (fromtype);
    4626              :     }
    4627              : 
    4628     89955091 :   candidates = 0;
    4629     89955091 :   flags |= LOOKUP_NO_CONVERSION;
    4630     89955091 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4631       895075 :     flags |= LOOKUP_NO_NARROWING;
    4632              :   /* Prevent add_candidates from treating a non-strictly viable candidate
    4633              :      as unviable.  */
    4634     89955091 :   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     89955091 :   convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION
    4639     89955091 :                | (flags & LOOKUP_NO_NARROWING));
    4640     89955091 :   flags &= ~LOOKUP_NO_TEMP_BIND;
    4641              : 
    4642     89955091 :   if (ctors)
    4643              :     {
    4644     49432368 :       int ctorflags = flags;
    4645              : 
    4646     49432368 :       first_arg = build_dummy_object (totype);
    4647              : 
    4648              :       /* We should never try to call the abstract or base constructor
    4649              :          from here.  */
    4650    346970304 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (OVL_FIRST (ctors))
    4651              :                   && !DECL_HAS_VTT_PARM_P (OVL_FIRST (ctors)));
    4652              : 
    4653     49432368 :       args = make_tree_vector_single (expr);
    4654     49432368 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4655              :         {
    4656              :           /* List-initialization.  */
    4657       895075 :           add_list_candidates (ctors, first_arg, args, totype, NULL_TREE,
    4658       895075 :                                false, TYPE_BINFO (totype), TYPE_BINFO (totype),
    4659              :                                ctorflags, &candidates, complain);
    4660              :         }
    4661              :       else
    4662              :         {
    4663     48537293 :           add_candidates (ctors, first_arg, args, NULL_TREE, NULL_TREE, false,
    4664     48537293 :                           TYPE_BINFO (totype), TYPE_BINFO (totype),
    4665              :                           ctorflags, &candidates, complain);
    4666              :         }
    4667              : 
    4668    272116587 :       for (cand = candidates; cand; cand = cand->next)
    4669              :         {
    4670    222684219 :           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    222684219 :           if (!TYPE_REF_P (totype)
    4681    222684219 :               && cxx_dialect < cxx17
    4682       413972 :               && (flags & LOOKUP_ONLYCONVERTING)
    4683       358519 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4684       113604 :             cand->second_conv
    4685       113604 :               = build_conv (ck_rvalue, totype, cand->second_conv);
    4686              :         }
    4687              :     }
    4688              : 
    4689     89955091 :   if (conv_fns)
    4690              :     {
    4691     28416211 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4692            0 :         first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
    4693              :       else
    4694     89955091 :         first_arg = expr;
    4695              :     }
    4696              : 
    4697    122983421 :   for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
    4698              :     {
    4699     33028330 :       tree conversion_path = TREE_PURPOSE (conv_fns);
    4700     33028330 :       struct z_candidate *old_candidates;
    4701              : 
    4702              :       /* If LOOKUP_NO_CONVERSION, don't consider a conversion function that
    4703              :          would need an additional 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     33028330 :       tree convtype = non_reference (TREE_TYPE (conv_fns));
    4712     48798545 :       if ((flags & LOOKUP_NO_CONVERSION)
    4713     33028330 :           && !WILDCARD_TYPE_P (convtype)
    4714     62698844 :           && (CLASS_TYPE_P (to_nonref)
    4715     31349422 :               != CLASS_TYPE_P (convtype)))
    4716     15770215 :         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     17258115 :       if (TYPE_REF_P (totype))
    4723      4836813 :         convflags |= LOOKUP_NO_TEMP_BIND;
    4724              : 
    4725     17258115 :       old_candidates = candidates;
    4726     17258115 :       add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype,
    4727              :                       NULL_TREE, false,
    4728     17258115 :                       conversion_path, TYPE_BINFO (fromtype),
    4729              :                       flags, &candidates, complain);
    4730              : 
    4731     34516225 :       for (cand = candidates; cand != old_candidates; cand = cand->next)
    4732              :         {
    4733     17258110 :           if (cand->viable == 0)
    4734              :             /* Already rejected, don't change to -1.  */
    4735      6576859 :             continue;
    4736              : 
    4737     10681251 :           tree rettype = TREE_TYPE (TREE_TYPE (cand->fn));
    4738     10681251 :           conversion *ics
    4739     10681251 :             = 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      4063643 :           if (ics && MAYBE_CLASS_TYPE_P (totype) && ics->kind != ck_rvalue
    4756     11340214 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4757       244180 :             ics = build_conv (ck_rvalue, totype, ics);
    4758              : 
    4759     10681251 :           cand->second_conv = ics;
    4760              : 
    4761     10681251 :           if (!ics)
    4762              :             {
    4763      6617608 :               cand->viable = 0;
    4764     13233383 :               cand->reason = arg_conversion_rejection (NULL_TREE, -2,
    4765              :                                                        rettype, totype,
    4766      6617608 :                                                        EXPR_LOCATION (expr));
    4767              :             }
    4768        12985 :           else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p
    4769              :                    /* Limit this to non-templates for now (PR90546).  */
    4770         1365 :                    && !cand->template_decl
    4771      4065003 :                    && 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         1354 :               cand->viable = 0;
    4777              :             }
    4778      4062289 :           else if (DECL_NONCONVERTING_P (cand->fn)
    4779      4062289 :                    && 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         2637 :               cand->viable = -1;
    4789         2637 :               cand->reason = explicit_conversion_rejection (rettype, totype);
    4790              :             }
    4791      4059652 :           else if (cand->viable == 1 && ics->bad_p)
    4792              :             {
    4793         1996 :               cand->viable = -1;
    4794         1996 :               cand->reason
    4795         3992 :                 = bad_arg_conversion_rejection (NULL_TREE, -2,
    4796              :                                                 rettype, totype,
    4797         1996 :                                                 EXPR_LOCATION (expr));
    4798              :             }
    4799      4057656 :           else if (primary_template_specialization_p (cand->fn)
    4800      4057656 :                    && 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     89955091 :   candidates = splice_viable (candidates, false, &any_viable_p);
    4813     89955091 :   if (!any_viable_p)
    4814              :     {
    4815     76042299 :       if (args)
    4816     38910755 :         release_tree_vector (args);
    4817     76042299 :       return NULL;
    4818              :     }
    4819              : 
    4820     13912792 :   cand = tourney (candidates, complain);
    4821     13912792 :   if (cand == NULL)
    4822              :     {
    4823         1345 :       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         1345 :       cand = candidates;        /* any one will do */
    4833         1345 :       cand->second_conv = build_ambiguous_conv (totype, expr);
    4834         1345 :       cand->second_conv->user_conv_p = true;
    4835         2690 :       if (!any_strictly_viable (candidates))
    4836           12 :         cand->second_conv->bad_p = true;
    4837         1345 :       if (flags & LOOKUP_ONLYCONVERTING)
    4838         1272 :         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         1345 :       return cand;
    4844              :     }
    4845              : 
    4846              :   /* Maybe pass { } as iterators instead of an initializer_list.  */
    4847     13911447 :   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     13911447 :   tree convtype;
    4857     27822894 :   if (!DECL_CONSTRUCTOR_P (cand->fn))
    4858      4050108 :     convtype = non_reference (TREE_TYPE (TREE_TYPE (cand->fn)));
    4859      9861339 :   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        11621 :     convtype = cv_unqualified (totype);
    4864              :   else
    4865              :     convtype = totype;
    4866              :   /* Build the user conversion sequence.  */
    4867     13911447 :   conv = build_conv
    4868     13911447 :     (ck_user,
    4869              :      convtype,
    4870     13911447 :      build_identity_conv (TREE_TYPE (expr), expr));
    4871     13911447 :   conv->cand = cand;
    4872     13911447 :   if (cand->viable == -1)
    4873         7313 :     conv->bad_p = true;
    4874              : 
    4875              :   /* Remember that this was a list-initialization.  */
    4876     13911447 :   if (flags & LOOKUP_NO_NARROWING)
    4877      3204499 :     conv->check_narrowing = true;
    4878              : 
    4879              :   /* Combine it with the second conversion sequence.  */
    4880     13911447 :   cand->second_conv = merge_conversion_sequences (conv,
    4881              :                                                   cand->second_conv);
    4882              : 
    4883     13911447 :   return cand;
    4884              : }
    4885              : 
    4886              : /* Wrapper for above. */
    4887              : 
    4888              : tree
    4889        22068 : build_user_type_conversion (tree totype, tree expr, int flags,
    4890              :                             tsubst_flags_t complain)
    4891              : {
    4892        22068 :   struct z_candidate *cand;
    4893        22068 :   tree ret;
    4894              : 
    4895        22068 :   auto_cond_timevar tv (TV_OVERLOAD);
    4896              : 
    4897        22068 :   conversion_obstack_sentinel cos;
    4898              : 
    4899        22068 :   cand = build_user_type_conversion_1 (totype, expr, flags, complain);
    4900              : 
    4901        22068 :   if (cand)
    4902              :     {
    4903        21838 :       if (cand->second_conv->kind == ck_ambig)
    4904           65 :         ret = error_mark_node;
    4905              :       else
    4906              :         {
    4907        21773 :           expr = convert_like (cand->second_conv, expr, complain);
    4908        21773 :           ret = convert_from_reference (expr);
    4909              :         }
    4910              :     }
    4911              :   else
    4912              :     ret = NULL_TREE;
    4913              : 
    4914        44136 :   return ret;
    4915        22068 : }
    4916              : 
    4917              : /* Give a helpful diagnostic when implicit_conversion fails.  */
    4918              : 
    4919              : static void
    4920          680 : implicit_conversion_error (location_t loc, tree type, tree expr,
    4921              :                            int flags)
    4922              : {
    4923          680 :   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          680 :   if (TREE_TYPE (expr) == unknown_type_node)
    4928           60 :     instantiate_type (type, expr, complain);
    4929          620 :   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          633 :            && !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          597 :       auto_diagnostic_group d;
    4939          597 :       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          580 :           range_label_for_type_mismatch label (TREE_TYPE (expr), type);
    4947          580 :           gcc_rich_location rich_loc (loc, &label,
    4948          580 :                                       highlight_colors::percent_h);
    4949          580 :           error_at (&rich_loc, "could not convert %qE from %qH to %qI",
    4950          580 :                     expr, TREE_TYPE (expr), type);
    4951          580 :         }
    4952          597 :       maybe_show_nonconverting_candidate (type, TREE_TYPE (expr), expr, flags);
    4953          597 :     }
    4954          680 : }
    4955              : 
    4956              : /* Worker for build_converted_constant_expr.  */
    4957              : 
    4958              : static tree
    4959    307312829 : build_converted_constant_expr_internal (tree type, tree expr,
    4960              :                                         int flags, tsubst_flags_t complain)
    4961              : {
    4962    307312829 :   conversion *conv;
    4963    307312829 :   tree t;
    4964    307312829 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    4965              : 
    4966    307312829 :   if (error_operand_p (expr))
    4967           65 :     return error_mark_node;
    4968              : 
    4969    307312764 :   conversion_obstack_sentinel cos;
    4970              : 
    4971    307312764 :   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    307312764 :   for (conversion *c = conv;
    4992    355280179 :        c && c->kind != ck_identity;
    4993     47967415 :        c = next_conversion (c))
    4994              :     {
    4995     47967415 :       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          761 :         case ck_ref_bind:
    5013          761 :           if (c->need_temporary_p)
    5014              :             {
    5015            6 :               if (complain & tf_error)
    5016            1 :                 error_at (loc, "initializing %qH with %qI in converted "
    5017              :                           "constant expression does not bind directly",
    5018            1 :                           type, next_conversion (c)->type);
    5019              :               conv = NULL;
    5020              :             }
    5021              :           break;
    5022              : 
    5023      8848947 :         case ck_base:
    5024      8848947 :         case ck_pmem:
    5025      8848947 :         case ck_ptr:
    5026      8848947 :         case ck_std:
    5027      8848947 :           t = next_conversion (c)->type;
    5028      8848947 :           if (INTEGRAL_OR_ENUMERATION_TYPE_P (t)
    5029      8848867 :               && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    5030              :             /* Integral promotion or conversion.  */
    5031              :             break;
    5032          114 :           if (NULLPTR_TYPE_P (t))
    5033              :             /* Conversion from nullptr to pointer or pointer-to-member.  */
    5034              :             break;
    5035              : 
    5036          114 :           if (complain & tf_error)
    5037           82 :             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    307312096 :   if (conv && conv->kind == ck_ref_bind
    5050    307313519 :       && REFERENCE_REF_P (expr))
    5051              :     {
    5052          487 :       tree ref = TREE_OPERAND (expr, 0);
    5053          487 :       if (same_type_p (type, TREE_TYPE (ref)))
    5054              :         return ref;
    5055              :     }
    5056              : 
    5057    307312299 :   if (conv)
    5058              :     {
    5059              :       /* Don't copy a class in a template.  */
    5060        28263 :       if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue
    5061    307329409 :           && processing_template_decl)
    5062          213 :         conv = next_conversion (conv);
    5063              : 
    5064              :       /* Issuing conversion warnings for value-dependent expressions is
    5065              :          likely too noisy.  */
    5066    307311631 :       warning_sentinel w (warn_conversion);
    5067    307311631 :       conv->check_narrowing = true;
    5068    307311631 :       conv->check_narrowing_const_only = true;
    5069    307311631 :       expr = convert_like (conv, expr, complain);
    5070    307311631 :     }
    5071              :   else
    5072              :     {
    5073          668 :       if (complain & tf_error)
    5074          194 :         implicit_conversion_error (loc, type, expr, flags);
    5075          668 :       expr = error_mark_node;
    5076              :     }
    5077              : 
    5078              :   return expr;
    5079    307312764 : }
    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    179076205 : build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
    5097              : {
    5098    179076205 :   return build_converted_constant_expr_internal (type, expr, LOOKUP_IMPLICIT,
    5099    179076205 :                                                  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    128236624 : build_converted_constant_bool_expr (tree expr, tsubst_flags_t complain)
    5108              : {
    5109    128236624 :   return build_converted_constant_expr_internal (boolean_type_node, expr,
    5110    128236624 :                                                  LOOKUP_NORMAL, complain);
    5111              : }
    5112              : 
    5113              : /* Do any initial processing on the arguments to a function call.  */
    5114              : 
    5115              : vec<tree, va_gc> *
    5116    193621144 : resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
    5117              : {
    5118    193621144 :   unsigned int ix;
    5119    193621144 :   tree arg;
    5120              : 
    5121    359812790 :   FOR_EACH_VEC_SAFE_ELT (args, ix, arg)
    5122              :     {
    5123    166192358 :       if (error_operand_p (arg))
    5124              :         return NULL;
    5125    166191816 :       else if (VOID_TYPE_P (TREE_TYPE (arg)))
    5126              :         {
    5127          143 :           if (complain & tf_error)
    5128           12 :             error_at (cp_expr_loc_or_input_loc (arg),
    5129              :                       "invalid use of void expression");
    5130          143 :           return NULL;
    5131              :         }
    5132    166191673 :       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    166191646 :       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     92975248 : 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     92975248 :   struct z_candidate *cand;
    5162     92975248 :   tree explicit_targs;
    5163     92975248 :   int template_only;
    5164              : 
    5165     92975248 :   auto_cond_timevar tv (TV_OVERLOAD);
    5166              : 
    5167     92975248 :   explicit_targs = NULL_TREE;
    5168     92975248 :   template_only = 0;
    5169              : 
    5170     92975248 :   *candidates = NULL;
    5171     92975248 :   *any_viable_p = true;
    5172              : 
    5173              :   /* Check FN.  */
    5174     92975248 :   gcc_assert (OVL_P (fn) || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
    5175              : 
    5176     92975248 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5177              :     {
    5178     31952443 :       explicit_targs = TREE_OPERAND (fn, 1);
    5179     31952443 :       fn = TREE_OPERAND (fn, 0);
    5180     31952443 :       template_only = 1;
    5181              :     }
    5182              : 
    5183              :   /* Add the various candidate functions.  */
    5184     92975248 :   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     92961730 :   *candidates = splice_viable (*candidates, false, any_viable_p);
    5192     92961730 :   if (*any_viable_p)
    5193              :     {
    5194     92796537 :       if (complain & tf_any_viable)
    5195              :         cand = *candidates;
    5196              :       else
    5197     92796351 :         cand = tourney (*candidates, complain);
    5198              :     }
    5199              :   else
    5200              :     cand = NULL;
    5201              : 
    5202    185923460 :   return cand;
    5203     92961730 : }
    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         2968 : print_error_for_call_failure (tree fn, const vec<tree, va_gc> *args,
    5212              :                               struct z_candidate *candidates)
    5213              : {
    5214         2968 :   tree targs = NULL_TREE;
    5215         2968 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5216              :     {
    5217          548 :       targs = TREE_OPERAND (fn, 1);
    5218          548 :       fn = TREE_OPERAND (fn, 0);
    5219              :     }
    5220         5936 :   tree name = OVL_NAME (fn);
    5221         2968 :   location_t loc = location_of (name);
    5222         2968 :   if (targs)
    5223          548 :     name = lookup_template_function (name, targs);
    5224              : 
    5225         2968 :   auto_diagnostic_group d;
    5226         5936 :   if (!any_strictly_viable (candidates))
    5227         2484 :     error_at (loc, "no matching function for call to %<%D(%A)%>",
    5228              :               name, build_tree_list_vec (args));
    5229              :   else
    5230          484 :     error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous",
    5231              :               name, build_tree_list_vec (args));
    5232         2968 :   if (candidates)
    5233         2968 :     print_z_candidates (loc, candidates);
    5234         2968 : }
    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        22859 : perform_dguide_overload_resolution (tree dguides, const vec<tree, va_gc> *args,
    5242              :                                     tsubst_flags_t complain)
    5243              : {
    5244        22859 :   z_candidate *candidates;
    5245        22859 :   bool any_viable_p;
    5246        22859 :   tree result;
    5247              : 
    5248        45718 :   gcc_assert (deduction_guide_p (OVL_FIRST (dguides)));
    5249              : 
    5250        22859 :   conversion_obstack_sentinel cos;
    5251              : 
    5252        22859 :   z_candidate *cand = perform_overload_resolution (dguides, args, &candidates,
    5253              :                                                    &any_viable_p, complain);
    5254        22859 :   if (!cand)
    5255              :     {
    5256          957 :       if (complain & tf_error)
    5257          198 :         print_error_for_call_failure (dguides, args, candidates);
    5258          957 :       result = error_mark_node;
    5259              :     }
    5260              :   else
    5261        21902 :     result = cand->fn;
    5262              : 
    5263        45718 :   return result;
    5264        22859 : }
    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     91939930 : build_new_function_call (tree fn, vec<tree, va_gc> **args,
    5272              :                          tsubst_flags_t complain)
    5273              : {
    5274     91939930 :   struct z_candidate *candidates, *cand;
    5275     91939930 :   bool any_viable_p;
    5276     91939930 :   tree result;
    5277              : 
    5278     91939930 :   if (args != NULL && *args != NULL)
    5279              :     {
    5280     91939930 :       *args = resolve_args (*args, complain & ~tf_any_viable);
    5281     91939930 :       if (*args == NULL)
    5282          401 :         return error_mark_node;
    5283              :     }
    5284              : 
    5285     91939529 :   if (flag_tm)
    5286         3544 :     tm_malloc_replacement (fn);
    5287              : 
    5288     91939529 :   conversion_obstack_sentinel cos;
    5289              : 
    5290     91939529 :   cand = perform_overload_resolution (fn, *args, &candidates, &any_viable_p,
    5291              :                                       complain);
    5292              : 
    5293     91926011 :   if (!cand)
    5294              :     {
    5295       174842 :       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         3184 :           if (!any_viable_p && candidates && ! candidates->next
    5300         1400 :               && 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          435 :               && (TREE_CODE (fn) != TEMPLATE_ID_EXPR
    5305           33 :                   || 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         2761 :           print_error_for_call_failure (fn, *args, candidates);
    5310              :         }
    5311       174419 :       result = error_mark_node;
    5312              :     }
    5313     91751169 :   else if (complain & tf_any_viable)
    5314          186 :     return void_node;
    5315              :   else
    5316     91750983 :     result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5317              : 
    5318     91925402 :   if (flag_coroutines
    5319     89861337 :       && result
    5320     89861337 :       && TREE_CODE (result) == CALL_EXPR
    5321    147307106 :       && DECL_BUILT_IN_CLASS (TREE_OPERAND (CALL_EXPR_FN (result), 0))
    5322     55381704 :           == BUILT_IN_NORMAL)
    5323      7516659 :    result = coro_validate_builtin_call (result);
    5324              : 
    5325              :   return result;
    5326     91926011 : }
    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      1012837 : 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      1012837 :   tree original_size = *size;
    5348      1012837 :   tree fns;
    5349      1012837 :   struct z_candidate *candidates;
    5350      1012837 :   struct z_candidate *cand = NULL;
    5351      1012837 :   bool any_viable_p;
    5352              : 
    5353      1012837 :   if (fn)
    5354      1011396 :     *fn = NULL_TREE;
    5355              :   /* Set to (size_t)-1 if the size check fails.  */
    5356      1012837 :   if (size_check != NULL_TREE)
    5357              :     {
    5358        20058 :       tree errval = TYPE_MAX_VALUE (sizetype);
    5359        20058 :       if (cxx_dialect >= cxx11 && flag_exceptions)
    5360        19699 :         errval = throw_bad_array_new_length ();
    5361        20058 :       *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5362              :                            original_size, errval);
    5363              :     }
    5364      1012837 :   vec_safe_insert (*args, 0, *size);
    5365      1012837 :   *args = resolve_args (*args, complain);
    5366      1012837 :   if (*args == NULL)
    5367            0 :     return error_mark_node;
    5368              : 
    5369      1012837 :   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      1012837 :   fns = lookup_qualified_name (global_namespace, fnname);
    5381              : 
    5382      1012837 :   if (align_arg)
    5383              :     {
    5384         9004 :       vec<tree, va_gc>* align_args
    5385         9004 :         = vec_copy_and_insert (*args, align_arg, 1);
    5386         9004 :       cand = perform_overload_resolution (fns, align_args, &candidates,
    5387              :                                           &any_viable_p, tf_none);
    5388         9004 :       if (cand)
    5389         8981 :         *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         8981 :   if (!cand)
    5396      1003856 :     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      1012837 :   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      1012828 :    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      1012828 :    if (fn)
    5446      1011387 :      *fn = cand->fn;
    5447              : 
    5448              :    /* Build the CALL_EXPR.  */
    5449      1012828 :    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      1012828 :    tree call = extract_call_expr (ret);
    5455      1012828 :    if (TREE_CODE (call) == CALL_EXPR)
    5456      1012828 :      CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    5457              : 
    5458              :    return ret;
    5459      1012837 : }
    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     75557931 : keep_unused_object_arg (tree result, tree obj, tree fn)
    5471              : {
    5472     75557931 :   if (result == NULL_TREE
    5473     75557931 :       || result == error_mark_node
    5474     74607954 :       || DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    5475     78116196 :       || !TREE_SIDE_EFFECTS (obj))
    5476              :     return result;
    5477              : 
    5478              :   /* But avoid the implicit lvalue-rvalue conversion when `obj' is
    5479              :      volatile.  */
    5480        84001 :   tree a = obj;
    5481        84001 :   if (TREE_THIS_VOLATILE (a))
    5482        55530 :     a = build_this (a);
    5483        84001 :   if (TREE_SIDE_EFFECTS (a))
    5484        28480 :     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      2237040 : build_op_call (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
    5492              : {
    5493      2237040 :   struct z_candidate *candidates = 0, *cand;
    5494      2237040 :   tree fns, convs, first_mem_arg = NULL_TREE;
    5495      2237040 :   bool any_viable_p;
    5496      2237040 :   tree result = NULL_TREE;
    5497              : 
    5498      2237040 :   auto_cond_timevar tv (TV_OVERLOAD);
    5499              : 
    5500      2237040 :   obj = mark_lvalue_use (obj);
    5501              : 
    5502      2237040 :   if (error_operand_p (obj))
    5503            0 :     return error_mark_node;
    5504              : 
    5505      2237040 :   tree type = TREE_TYPE (obj);
    5506              : 
    5507      2237040 :   obj = prep_operand (obj);
    5508              : 
    5509      2237040 :   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      2237040 :   if (TYPE_BINFO (type))
    5520              :     {
    5521      2237022 :       fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1, complain);
    5522      2237022 :       if (fns == error_mark_node)
    5523              :         return error_mark_node;
    5524              :     }
    5525              :   else
    5526              :     fns = NULL_TREE;
    5527              : 
    5528      2237030 :   if (args != NULL && *args != NULL)
    5529              :     {
    5530      2237030 :       *args = resolve_args (*args, complain);
    5531      2237030 :       if (*args == NULL)
    5532          109 :         return error_mark_node;
    5533              :     }
    5534              : 
    5535      2236921 :   conversion_obstack_sentinel cos;
    5536              : 
    5537      2236921 :   if (fns)
    5538              :     {
    5539      2234043 :       first_mem_arg = obj;
    5540              : 
    5541      2234043 :       add_candidates (BASELINK_FUNCTIONS (fns),
    5542              :                       first_mem_arg, *args, NULL_TREE,
    5543              :                       NULL_TREE, false,
    5544      2234043 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    5545              :                       LOOKUP_NORMAL, &candidates, complain);
    5546              :     }
    5547              : 
    5548      2236921 :   bool any_call_ops = candidates != nullptr;
    5549              : 
    5550      2236921 :   convs = lookup_conversions (type);
    5551              : 
    5552      2387309 :   for (; convs; convs = TREE_CHAIN (convs))
    5553              :     {
    5554       150388 :       tree totype = TREE_TYPE (convs);
    5555              : 
    5556       130774 :       if (TYPE_PTRFN_P (totype)
    5557        19617 :           || TYPE_REFFN_P (totype)
    5558       169961 :           || (TYPE_REF_P (totype)
    5559         1069 :               && TYPE_PTRFN_P (TREE_TYPE (totype))))
    5560       262072 :         for (tree fn : ovl_range (TREE_VALUE (convs)))
    5561              :           {
    5562       131036 :             if (DECL_NONCONVERTING_P (fn))
    5563            3 :               continue;
    5564              : 
    5565       131033 :             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        34869 :                 if (any_call_ops)
    5571        34857 :                   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        96164 :               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      2236921 :   candidates = splice_viable (candidates, true, &any_viable_p);
    5588      2236921 :   if (!any_viable_p)
    5589              :     {
    5590        28462 :       if (complain & tf_error)
    5591              :         {
    5592          282 :           auto_diagnostic_group d;
    5593          282 :           error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj),
    5594              :                  build_tree_list_vec (*args));
    5595          282 :           print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5596          282 :         }
    5597        28462 :       result = error_mark_node;
    5598              :     }
    5599              :   else
    5600              :     {
    5601      2208459 :       cand = tourney (candidates, complain);
    5602      2208459 :       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      2208442 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    5614      2208383 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    5615      4416825 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, CALL_EXPR))
    5616              :         {
    5617      2208383 :           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      2208383 :           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      2236921 :   return result;
    5639      2237040 : }
    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         1466 : concat_op_error_string (bool match, const char *errmsg, const char *suffix)
    5647              : {
    5648         1466 :   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         1445 : op_error_string (const char *errmsg, int ntypes, bool match)
    5660              : {
    5661         1445 :   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         1466 : 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         1466 :   bool assop = code == MODIFY_EXPR;
    5687         1466 :   const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
    5688              : 
    5689         1466 :   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         1447 :     default:
    5745         1447 :       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           99 :         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          198 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%s%E%>"),
    5768              :                                           1, match),
    5769           99 :                     opname, opname, arg1, TREE_TYPE (arg1));
    5770              :       break;
    5771              :     }
    5772         1466 : }
    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       522864 : conditional_conversion (tree e1, tree e2, tsubst_flags_t complain)
    5779              : {
    5780       522864 :   tree t1 = non_reference (TREE_TYPE (e1));
    5781       522864 :   tree t2 = non_reference (TREE_TYPE (e2));
    5782       522864 :   conversion *conv;
    5783       522864 :   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       522864 :   if (glvalue_p (e2))
    5796              :     {
    5797       495211 :       tree rtype = cp_build_reference_type (t2, !lvalue_p (e2));
    5798       495211 :       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       495211 :       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       419923 :   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       188429 :   if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    5826       376935 :       && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
    5827              :     {
    5828        54923 :       if (good_base && at_least_as_qualified_p (t2, t1))
    5829              :         {
    5830        27379 :           conv = build_identity_conv (t1, e1);
    5831        27379 :           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        27373 :             conv = build_conv (ck_rvalue, t2, conv);
    5836        27379 :           return conv;
    5837              :         }
    5838              :       else
    5839        27544 :         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       262324 :     return implicit_conversion (t2, t1, e1, /*c_cast_p=*/false,
    5848       262324 :                                 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      7474487 : build_conditional_expr (const op_location_t &loc,
    5856              :                         tree arg1, tree arg2, tree arg3,
    5857              :                         tsubst_flags_t complain)
    5858              : {
    5859      7474487 :   tree arg2_type;
    5860      7474487 :   tree arg3_type;
    5861      7474487 :   tree result = NULL_TREE;
    5862      7474487 :   tree result_type = NULL_TREE;
    5863      7474487 :   tree semantic_result_type = NULL_TREE;
    5864      7474487 :   bool is_glvalue = true;
    5865      7474487 :   struct z_candidate *candidates = 0;
    5866      7474487 :   struct z_candidate *cand;
    5867      7474487 :   tree orig_arg2, orig_arg3;
    5868              : 
    5869      7474487 :   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      7474487 :   if (!arg2)
    5876              :     {
    5877          386 :       if (complain & tf_error)
    5878          380 :         pedwarn (loc, OPT_Wpedantic,
    5879              :                  "ISO C++ forbids omitting the middle term of "
    5880              :                  "a %<?:%> expression");
    5881              : 
    5882          386 :       if ((complain & tf_warning) && !truth_value_p (TREE_CODE (arg1)))
    5883          338 :         warn_for_omitted_condop (loc, arg1);
    5884              : 
    5885              :       /* Make sure that lvalues remain lvalues.  See g++.oliva/ext1.C.  */
    5886          386 :       if (glvalue_p (arg1))
    5887              :         {
    5888           95 :           arg1 = cp_stabilize_reference (arg1);
    5889           95 :           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      7474487 :   if (error_operand_p (arg1)
    5906      7474398 :       || error_operand_p (arg2)
    5907     14948835 :       || error_operand_p (arg3))
    5908          181 :     return error_mark_node;
    5909              : 
    5910      7474306 :   conversion_obstack_sentinel cos;
    5911              : 
    5912      7474306 :   orig_arg2 = arg2;
    5913      7474306 :   orig_arg3 = arg3;
    5914              : 
    5915      7474306 :   if (gnu_vector_type_p (TREE_TYPE (arg1))
    5916      7474306 :       && (VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg1))
    5917            3 :           || VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (arg1))))
    5918              :     {
    5919         1435 :       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         1435 :       if (TREE_CODE (arg1) == VEC_COND_EXPR
    5926         1253 :           && integer_minus_onep (TREE_OPERAND (arg1, 1))
    5927         2688 :           && integer_zerop (TREE_OPERAND (arg1, 2)))
    5928         1253 :         arg1 = TREE_OPERAND (arg1, 0);
    5929              : 
    5930         1435 :       arg1 = force_rvalue (arg1, complain);
    5931         1435 :       arg2 = force_rvalue (arg2, complain);
    5932         1435 :       arg3 = force_rvalue (arg3, complain);
    5933              : 
    5934              :       /* force_rvalue can return error_mark on valid arguments.  */
    5935         1435 :       if (error_operand_p (arg1)
    5936         1435 :           || error_operand_p (arg2)
    5937         2870 :           || error_operand_p (arg3))
    5938            0 :         return error_mark_node;
    5939              : 
    5940         1435 :       arg2_type = TREE_TYPE (arg2);
    5941         1435 :       arg3_type = TREE_TYPE (arg3);
    5942              : 
    5943         1435 :       if (!VECTOR_TYPE_P (arg2_type)
    5944          312 :           && !VECTOR_TYPE_P (arg3_type))
    5945              :         {
    5946              :           /* Rely on the error messages of the scalar version.  */
    5947          294 :           tree scal = build_conditional_expr (loc, integer_one_node,
    5948              :                                               orig_arg2, orig_arg3, complain);
    5949          294 :           if (scal == error_mark_node)
    5950              :             return error_mark_node;
    5951          294 :           tree stype = TREE_TYPE (scal);
    5952          294 :           tree ctype = TREE_TYPE (arg1_type);
    5953          294 :           if (TYPE_SIZE (stype) != TYPE_SIZE (ctype)
    5954          294 :               || (!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          285 :           tree vtype = build_opaque_vector_type (stype,
    5966          285 :                          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          285 :           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          285 :           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          282 :           arg2 = cp_convert (stype, arg2, complain);
    5987          282 :           arg2 = save_expr (arg2);
    5988          282 :           arg2 = build_vector_from_val (vtype, arg2);
    5989          282 :           arg2_type = vtype;
    5990          282 :           arg3 = cp_convert (stype, arg3, complain);
    5991          282 :           arg3 = save_expr (arg3);
    5992          282 :           arg3 = build_vector_from_val (vtype, arg3);
    5993          282 :           arg3_type = vtype;
    5994              :         }
    5995              : 
    5996         2828 :       if ((gnu_vector_type_p (arg2_type) && !VECTOR_TYPE_P (arg3_type))
    5997         2750 :           || (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         1423 :       if (!gnu_vector_type_p (arg2_type)
    6029         1420 :           || !gnu_vector_type_p (arg3_type)
    6030         1414 :           || !same_type_p (arg2_type, arg3_type)
    6031         1414 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type),
    6032         1414 :                        TYPE_VECTOR_SUBPARTS (arg2_type))
    6033         2837 :           || 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         1414 :       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         1414 :       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      7472871 :   arg1 = perform_implicit_conversion_flags (boolean_type_node, arg1, complain,
    6056              :                                             LOOKUP_NORMAL);
    6057      7472871 :   if (error_operand_p (arg1))
    6058           25 :     return error_mark_node;
    6059              : 
    6060      7472846 :   arg2_type = unlowered_expr_type (arg2);
    6061      7472846 :   arg3_type = unlowered_expr_type (arg3);
    6062              : 
    6063      7472846 :   if ((TREE_CODE (arg2) == EXCESS_PRECISION_EXPR
    6064      7472828 :        || 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      7472846 :   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       115801 :       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       115801 :       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       115801 :       if (TREE_CODE (arg2) == THROW_EXPR
    6139           84 :           && TREE_CODE (arg3) != THROW_EXPR)
    6140              :         {
    6141           72 :           result_type = arg3_type;
    6142           72 :           is_glvalue = glvalue_p (arg3);
    6143              :         }
    6144       115729 :       else if (TREE_CODE (arg2) != THROW_EXPR
    6145       115717 :                && TREE_CODE (arg3) == THROW_EXPR)
    6146              :         {
    6147          171 :           result_type = arg2_type;
    6148          171 :           is_glvalue = glvalue_p (arg2);
    6149              :         }
    6150       115558 :       else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
    6151              :         {
    6152       115529 :           result_type = void_type_node;
    6153       115529 :           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       115772 :       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      7357045 :   else if (!same_type_p (arg2_type, arg3_type)
    6183      7357045 :             && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)
    6184      1475366 :                 || (same_type_ignoring_top_level_qualifiers_p (arg2_type,
    6185              :                                                                arg3_type)
    6186       424849 :                     && glvalue_p (arg2) && glvalue_p (arg3)
    6187       102746 :                     && lvalue_p (arg2) == lvalue_p (arg3))))
    6188              :     {
    6189       261432 :       conversion *conv2;
    6190       261432 :       conversion *conv3;
    6191       261432 :       bool converted = false;
    6192              : 
    6193       261432 :       conv2 = conditional_conversion (arg2, arg3, complain);
    6194       261432 :       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       261432 :       if ((conv2 && !conv2->bad_p
    6206        62418 :            && conv3 && !conv3->bad_p)
    6207        62398 :           || (conv2 && conv2->kind == ck_ambig)
    6208       261313 :           || (conv3 && conv3->kind == ck_ambig))
    6209              :         {
    6210          119 :           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          119 :           result = error_mark_node;
    6223              :         }
    6224       261313 :       else if (conv2 && !conv2->bad_p)
    6225              :         {
    6226        62299 :           arg2 = convert_like (conv2, arg2, complain);
    6227        62299 :           arg2 = convert_from_reference (arg2);
    6228        62299 :           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        62299 :           if (error_operand_p (arg2))
    6235            4 :             result = error_mark_node;
    6236            4 :           converted = true;
    6237              :         }
    6238       199014 :       else if (conv3 && !conv3->bad_p)
    6239              :         {
    6240       198300 :           arg3 = convert_like (conv3, arg3, complain);
    6241       198300 :           arg3 = convert_from_reference (arg3);
    6242       198300 :           arg3_type = TREE_TYPE (arg3);
    6243       198300 :           if (error_operand_p (arg3))
    6244            0 :             result = error_mark_node;
    6245            0 :           converted = true;
    6246              :         }
    6247              : 
    6248          123 :       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       261309 :       if (converted
    6267       260595 :           && CLASS_TYPE_P (arg2_type)
    6268       290823 :           && 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     10891864 :   if (((lvalue_p (arg2) && lvalue_p (arg3))
    6281      4424806 :        || (xvalue_p (arg2) && xvalue_p (arg3)))
    6282     10335902 :       && same_type_p (arg2_type, arg3_type))
    6283              :     {
    6284      2888130 :       result_type = arg2_type;
    6285      2888130 :       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      4468792 :   is_glvalue = false;
    6296      4468792 :   if (!same_type_p (arg2_type, arg3_type)
    6297      4468792 :       && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
    6298              :     {
    6299          714 :       releasing_vec args;
    6300          714 :       conversion *conv;
    6301          714 :       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          714 :       args->quick_push (arg2);
    6307          714 :       args->quick_push (arg3);
    6308          714 :       args->quick_push (arg1);
    6309          714 :       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          714 :       candidates = splice_viable (candidates, false, &any_viable_p);
    6321          714 :       if (!any_viable_p)
    6322              :         {
    6323          591 :           if (complain & tf_error)
    6324           22 :             error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6325              :                       arg2_type, arg3_type);
    6326          591 :           return error_mark_node;
    6327              :         }
    6328          123 :       cand = tourney (candidates, complain);
    6329          123 :       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          123 :       conv = cand->convs[0];
    6346          123 :       arg1 = convert_like (conv, arg1, complain);
    6347          123 :       conv = cand->convs[1];
    6348          123 :       arg2 = convert_like (conv, arg2, complain);
    6349          123 :       arg2_type = TREE_TYPE (arg2);
    6350          123 :       conv = cand->convs[2];
    6351          123 :       arg3 = convert_like (conv, arg3, complain);
    6352          123 :       arg3_type = TREE_TYPE (arg3);
    6353          714 :     }
    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      4468201 :   arg2 = force_rvalue (arg2, complain);
    6367      4468201 :   if (!CLASS_TYPE_P (arg2_type))
    6368      4362638 :     arg2_type = TREE_TYPE (arg2);
    6369              : 
    6370      4468201 :   arg3 = force_rvalue (arg3, complain);
    6371      4468201 :   if (!CLASS_TYPE_P (arg3_type))
    6372      4362638 :     arg3_type = TREE_TYPE (arg3);
    6373              : 
    6374      4468201 :   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      4468153 :   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        22621 :   else if ((ARITHMETIC_TYPE_P (arg2_type)
    6391        21904 :             || UNSCOPED_ENUM_P (arg2_type))
    6392       963033 :            && (ARITHMETIC_TYPE_P (arg3_type)
    6393          185 :                || 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       940298 :       tree eptype2 = arg2_type;
    6400       940298 :       tree eptype3 = arg3_type;
    6401       940298 :       tree eptype;
    6402          717 :       if (ANY_INTEGRAL_TYPE_P (arg2_type)
    6403       940301 :           && (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          409 :       else if (ANY_INTEGRAL_TYPE_P (arg3_type)
    6411       940293 :                && (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       940298 :       result_type = type_after_usual_arithmetic_conversions (eptype2,
    6419              :                                                              eptype3);
    6420       940298 :       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       940298 :       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       940298 :       if (complain & tf_warning)
    6462       889936 :         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       940298 :       if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6468          102 :           && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
    6469              :         {
    6470           35 :           tree stripped_orig_arg2 = tree_strip_any_location_wrapper (orig_arg2);
    6471           35 :           tree stripped_orig_arg3 = tree_strip_any_location_wrapper (orig_arg3);
    6472           35 :           if (TREE_CODE (stripped_orig_arg2) == CONST_DECL
    6473           23 :               && TREE_CODE (stripped_orig_arg3) == CONST_DECL
    6474           58 :               && (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           29 :           else if (complain & (cxx_dialect >= cxx26
    6479           29 :                                ? tf_warning_or_error : tf_warning))
    6480           44 :             emit_diagnostic ((cxx_dialect >= cxx26
    6481              :                               ? diagnostics::kind::pedwarn
    6482              :                               : diagnostics::kind::warning),
    6483           26 :                              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            2 :             return error_mark_node;
    6488              :         }
    6489       940263 :       else if ((((complain & (cxx_dialect >= cxx26
    6490       940263 :                               ? tf_warning_or_error : tf_warning))
    6491       892895 :                  && warn_deprecated_enum_float_conv)
    6492        62516 :                 || (cxx_dialect >= cxx26
    6493         1368 :                     && (complain & tf_warning_or_error) == 0))
    6494       879016 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6495           40 :                     && SCALAR_FLOAT_TYPE_P (arg3_type))
    6496       879003 :                    || (SCALAR_FLOAT_TYPE_P (arg2_type)
    6497          240 :                        && TREE_CODE (arg3_type) == ENUMERAL_TYPE)))
    6498              :         {
    6499           23 :           if (cxx_dialect >= cxx26 && (complain & tf_warning_or_error) == 0)
    6500            4 :             return error_mark_node;
    6501           19 :           if (cxx_dialect >= cxx26 && TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6502            5 :             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           14 :           else if (cxx_dialect >= cxx26)
    6506            4 :             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       930514 :       else if ((extra_warnings || warn_enum_conversion)
    6521       940245 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6522           15 :                     && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
    6523         9719 :                    || (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       940292 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6538       940292 :       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        21916 :   else if ((null_ptr_cst_p (arg2)
    6557          175 :             && TYPE_PTR_OR_PTRMEM_P (arg3_type))
    6558        21741 :            || (null_ptr_cst_p (arg3)
    6559        20780 :                && TYPE_PTR_OR_PTRMEM_P (arg2_type))
    6560          961 :            || (TYPE_PTR_P (arg2_type) && TYPE_PTR_P (arg3_type))
    6561           99 :            || (TYPE_PTRDATAMEM_P (arg2_type) && TYPE_PTRDATAMEM_P (arg3_type))
    6562        21992 :            || (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
    6563              :     {
    6564        21862 :       result_type = composite_pointer_type (loc,
    6565              :                                             arg2_type, arg3_type, arg2,
    6566              :                                             arg3, CPO_CONDITIONAL_EXPR,
    6567              :                                             complain);
    6568        21862 :       if (result_type == error_mark_node)
    6569              :         return error_mark_node;
    6570        21836 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6571        21836 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6572              :     }
    6573              : 
    6574      4468067 :   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      4468067 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6583              :     return error_mark_node;
    6584              : 
    6585      4468064 :  valid_operands:
    6586      7471966 :   if (processing_template_decl && is_glvalue)
    6587              :     {
    6588              :       /* Let lvalue_kind know this was a glvalue.  */
    6589       108713 :       tree arg = (result_type == arg2_type ? arg2 : arg3);
    6590       108713 :       result_type = cp_build_reference_type (result_type, xvalue_p (arg));
    6591              :     }
    6592              : 
    6593      7471966 :   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      7471966 :   if (warn_duplicated_branches
    6598          153 :       && (complain & tf_warning)
    6599      7472119 :       && (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      7471966 :   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      4583776 :       if (CLASS_TYPE_P (TREE_TYPE (result)))
    6614              :         {
    6615       105600 :           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       105600 :           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      4583776 :       result = rvalue (result);
    6624      4583776 :       if (semantic_result_type)
    6625           73 :         result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6626              :                          result);
    6627              :     }
    6628              :   else
    6629              :     {
    6630      2888190 :       result = force_paren_expr (result);
    6631      2888190 :       gcc_assert (semantic_result_type == NULL_TREE);
    6632              :     }
    6633              : 
    6634              :   return result;
    6635      7474487 : }
    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    619653778 : prep_operand (tree operand)
    6643              : {
    6644    619653778 :   if (operand)
    6645              :     {
    6646    716104694 :       if (CLASS_TYPE_P (TREE_TYPE (operand))
    6647    383134402 :           && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
    6648              :         /* Make sure the template type is instantiated now.  */
    6649     10008077 :         instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (operand)));
    6650              :     }
    6651              : 
    6652    619653778 :   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    217960043 : perfect_conversion_p (conversion *conv)
    6663              : {
    6664    217960043 :   if (CONVERSION_RANK (conv) != cr_identity)
    6665              :     return false;
    6666    156433734 :   if (conv->kind == ck_ref_bind)
    6667              :     {
    6668     40746994 :       if (!conv->rvaluedness_matches_p)
    6669              :         return false;
    6670     28166185 :       if (!same_type_p (TREE_TYPE (conv->type),
    6671              :                         next_conversion (conv)->type))
    6672              :         return false;
    6673              :     }
    6674    140230988 :   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    512152681 : perfect_candidate_p (z_candidate *cand)
    6688              : {
    6689    512152681 :   if (cand->viable < 1)
    6690              :     return false;
    6691              :   /* CWG1402 makes an implicitly deleted move op worse than other
    6692              :      candidates.  */
    6693    201454033 :   if (DECL_DELETED_FN (cand->fn) && DECL_DEFAULTED_FN (cand->fn)
    6694    200507231 :       && move_fn_p (cand->fn))
    6695              :     return false;
    6696    198917291 :   int len = cand->num_convs;
    6697    339148232 :   for (int i = 0; i < len; ++i)
    6698    217960043 :     if (!perfect_conversion_p (cand->convs[i]))
    6699              :       return false;
    6700    121188189 :   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     20928996 : missing_conversion_p (const z_candidate *cand)
    6710              : {
    6711     37898888 :   for (unsigned i = 0; i < cand->num_convs; ++i)
    6712              :     {
    6713     25191728 :       conversion *conv = cand->convs[i];
    6714     25191728 :       if (!conv)
    6715              :         return true;
    6716     24293258 :       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      7323366 :           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    293227429 : 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    293227429 :   tree ctype;
    6747    293227429 :   const vec<tree, va_gc> *non_static_args;
    6748    293227429 :   bool check_list_ctor = false;
    6749    293227429 :   bool check_converting = false;
    6750    293227429 :   unification_kind_t strict;
    6751    293227429 :   tree ne_context = NULL_TREE;
    6752    293227429 :   tree ne_fns = NULL_TREE;
    6753              : 
    6754    293227429 :   if (!fns)
    6755      3333861 :     return;
    6756              : 
    6757              :   /* Precalculate special handling of constructors and conversion ops.  */
    6758    289893568 :   tree fn = OVL_FIRST (fns);
    6759    289893568 :   if (DECL_CONV_FN_P (fn))
    6760              :     {
    6761     17259540 :       check_list_ctor = false;
    6762     17259540 :       check_converting = (flags & LOOKUP_ONLYCONVERTING) != 0;
    6763     17259540 :       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         1425 :         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     17259540 :       ctype = TYPE_MAIN_VARIANT (TREE_TYPE (first_arg));
    6774              :     }
    6775              :   else
    6776              :     {
    6777    545268056 :       if (DECL_CONSTRUCTOR_P (fn))
    6778              :         {
    6779     74240736 :           check_list_ctor = (flags & LOOKUP_LIST_ONLY) != 0;
    6780              :           /* For list-initialization we consider explicit constructors
    6781              :              and complain if one is chosen.  */
    6782     74240736 :           check_converting
    6783     74240736 :             = ((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    6784              :                == LOOKUP_ONLYCONVERTING);
    6785              :         }
    6786    272634028 :       strict = DEDUCE_CALL;
    6787    426875220 :       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    289893568 :   if ((flags & (LOOKUP_REWRITTEN | LOOKUP_REVERSED))
    6793    289893568 :       && DECL_OVERLOADED_OPERATOR_IS (fn, EQ_EXPR))
    6794              :     {
    6795      6533947 :       tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6796      6533947 :       if (DECL_CLASS_SCOPE_P (fn))
    6797              :         {
    6798       177776 :           ne_context = DECL_CONTEXT (fn);
    6799       177776 :           ne_fns = lookup_fnfields (TREE_TYPE ((*args)[0]), ne_name,
    6800              :                                     1, tf_none);
    6801       177776 :           if (ne_fns == error_mark_node || ne_fns == NULL_TREE)
    6802              :             ne_fns = NULL_TREE;
    6803              :           else
    6804        18149 :             ne_fns = BASELINK_FUNCTIONS (ne_fns);
    6805              :         }
    6806              :       else
    6807              :         {
    6808      6356171 :           ne_context = decl_namespace_context (fn);
    6809      6356171 :           ne_fns = lookup_qualified_name (ne_context, ne_name,
    6810              :                                           LOOK_want::NORMAL,
    6811              :                                           /*complain*/false);
    6812      6356171 :           if (ne_fns == error_mark_node
    6813      2089521 :               || !is_overloaded_fn (ne_fns))
    6814      4266650 :             ne_fns = NULL_TREE;
    6815              :         }
    6816              :     }
    6817              : 
    6818    289893568 :   if (first_arg)
    6819              :     non_static_args = args;
    6820              :   else
    6821              :     /* Delay creating the implicit this parameter until it is needed.  */
    6822    126521955 :     non_static_args = NULL;
    6823              : 
    6824    289893568 :   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    289893568 :   bool seen_perfect = false;
    6830    289893568 :   enum { templates, non_templates, either } which = either;
    6831    289893568 :   if (template_only)
    6832              :     which = templates;
    6833              :   else /*if (flags & LOOKUP_DEFAULTED)*/
    6834    255385549 :     which = non_templates;
    6835              : 
    6836              :   /* Template candidates that we'll potentially ignore if the
    6837              :      perfect candidate optimization succeeds.  */
    6838    289893568 :   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    289893568 :   z_candidate *bad_cands = nullptr;
    6851    289893568 :   bool shortcut_bad_convs = true;
    6852              : 
    6853    424205069 :  again:
    6854   2463064872 :   for (tree fn : lkp_range (fns))
    6855              :     {
    6856   2038873354 :       if (which == templates && TREE_CODE (fn) != TEMPLATE_DECL)
    6857              :         {
    6858    298410719 :           if (template_only)
    6859       766372 :             add_ignored_candidate (candidates, fn);
    6860    298410719 :           continue;
    6861              :         }
    6862   1740462635 :       if (which == non_templates && TREE_CODE (fn) == TEMPLATE_DECL)
    6863              :         {
    6864    601642986 :           add_ignored_candidate (&ignored_template_cands, fn);
    6865    601642986 :           continue;
    6866              :         }
    6867    219032346 :       if ((check_converting && DECL_NONCONVERTING_P (fn))
    6868   1333843199 :           || (check_list_ctor && !is_list_ctor (fn)))
    6869              :         {
    6870     25349528 :           add_ignored_candidate (candidates, fn);
    6871     25349528 :           continue;
    6872              :         }
    6873              : 
    6874   1113470121 :       tree fn_first_arg = NULL_TREE;
    6875   1113470121 :       const vec<tree, va_gc> *fn_args = args;
    6876              : 
    6877   1113470121 :       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    405896938 :           if (first_arg == NULL_TREE)
    6883              :             {
    6884      8129119 :               unsigned int ix;
    6885      8129119 :               tree arg;
    6886      8129119 :               vec<tree, va_gc> *tempvec;
    6887      8129119 :               vec_alloc (tempvec, args->length () - 1);
    6888     21965010 :               for (ix = 1; args->iterate (ix, &arg); ++ix)
    6889      5706772 :                 tempvec->quick_push (arg);
    6890      8129119 :               non_static_args = tempvec;
    6891      8129119 :               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    707573183 :       else if (vec_safe_length (args) == 2 && (flags & LOOKUP_REVERSED))
    6900              :         {
    6901    197328087 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6902    197328087 :           if (same_type_p (TREE_VALUE (parmlist),
    6903              :                            TREE_VALUE (TREE_CHAIN (parmlist))))
    6904     93651610 :             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   1019818511 :       if (ne_context)
    6910              :         {
    6911    140891336 :           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    140709430 :               tree fn_ns = decl_namespace_context (fn);
    6917    140709430 :               if (fn_ns != ne_context)
    6918              :                 {
    6919      7647576 :                   ne_context = fn_ns;
    6920      7647576 :                   tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6921      7647576 :                   ne_fns = lookup_qualified_name (ne_context, ne_name,
    6922              :                                                   LOOK_want::NORMAL,
    6923              :                                                   /*complain*/false);
    6924      7647576 :                   if (ne_fns == error_mark_node
    6925      4896560 :                       || !is_overloaded_fn (ne_fns))
    6926      2751016 :                     ne_fns = NULL_TREE;
    6927              :                 }
    6928              :             }
    6929    140891336 :           bool found = false;
    6930   1517345019 :           for (lkp_iterator ne (ne_fns); !found && ne; ++ne)
    6931   1410074972 :             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   1410074972 :             else if (fns_correspond (fn, *ne))
    6938              :               {
    6939              :                 found = true;
    6940              :                 break;
    6941              :               }
    6942    140891336 :           if (found)
    6943     33621289 :             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    986197222 :       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    986197222 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    6957    474044541 :         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    512152681 :           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    512152681 :           if (perfect_candidate_p (*candidates))
    6984    986183671 :             seen_perfect = true;
    6985              :         }
    6986              : 
    6987    986183671 :       z_candidate *cand = *candidates;
    6988    986183671 :       if (cand->viable == 1)
    6989    276556547 :         seen_strictly_viable = true;
    6990              : 
    6991    986183671 :       if (cand->viable == -1
    6992     20929494 :           && shortcut_bad_convs
    6993   1007112667 :           && (missing_conversion_p (cand)
    6994     12707160 :               || 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      8247364 :           if (complain & (tf_error | tf_conv))
    7002              :             {
    7003      7953030 :               *candidates = cand->next;
    7004      7953030 :               cand->next = bad_cands;
    7005      7953030 :               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       294334 :             cand->viable = 0;
    7014              :         }
    7015              :     }
    7016    424191518 :   if (which == non_templates && !seen_perfect)
    7017              :     {
    7018    134202820 :       which = templates;
    7019    134202820 :       ignored_template_cands = nullptr;
    7020    134202820 :       goto again;
    7021              :     }
    7022    289988698 :   else if (which == templates
    7023    289988698 :            && !seen_strictly_viable
    7024              :            && shortcut_bad_convs
    7025     54071863 :            && 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       241103 :       which = either;
    7031              :       fns = NULL_TREE;
    7032       241103 :       for (z_candidate *cand = bad_cands; cand; cand = cand->next)
    7033              :         {
    7034       132422 :           tree fn = cand->fn;
    7035       132422 :           if (tree ti = cand->template_decl)
    7036          118 :             fn = TI_TEMPLATE (ti);
    7037       132422 :           fns = ovl_make (fn, fns);
    7038              :         }
    7039       108681 :       shortcut_bad_convs = false;
    7040       108681 :       bad_cands = nullptr;
    7041       108681 :       goto again;
    7042              :     }
    7043              : 
    7044    289880017 :   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    451203474 :       for (z_candidate *omitted_cands : { ignored_template_cands, bad_cands })
    7049              :         {
    7050    300802316 :           z_candidate **omitted_cands_tail = &omitted_cands;
    7051    346150017 :           while (*omitted_cands_tail)
    7052     45347701 :             omitted_cands_tail = &(*omitted_cands_tail)->next;
    7053    300802316 :           *omitted_cands_tail = *candidates;
    7054    300802316 :           *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     15766497 : op_is_ordered (tree_code code)
    7064              : {
    7065     15766052 :   switch (code)
    7066              :     {
    7067              :       // 5. b @= a
    7068      3592071 :     case MODIFY_EXPR:
    7069      3592071 :       return (flag_strong_eval_order > 1 ? -1 : 0);
    7070              : 
    7071              :       // 6. a[b]
    7072       452630 :     case ARRAY_REF:
    7073       452185 :       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        53386 :     case MEMBER_REF:
    7081              :       // 7. a << b
    7082        53386 :     case LSHIFT_EXPR:
    7083              :       // 8. a >> b
    7084        53386 :     case RSHIFT_EXPR:
    7085              :       // a && b
    7086              :       // Predates P0145R3.
    7087        53386 :     case TRUTH_ANDIF_EXPR:
    7088              :       // a || b
    7089              :       // Predates P0145R3.
    7090        53386 :     case TRUTH_ORIF_EXPR:
    7091              :       // a , b
    7092              :       // Predates P0145R3.
    7093        53386 :     case COMPOUND_EXPR:
    7094        53386 :       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     32816665 : 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     32816665 :   z_candidate *start_candidates = *candidates;
    7119     32816665 :   bool ismodop = code2 != ERROR_MARK;
    7120     32816665 :   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     32816665 :   bool rewritten = (flags & LOOKUP_REWRITTEN);
    7127     32816665 :   if (rewritten && code != EQ_EXPR && code != SPACESHIP_EXPR)
    7128       865272 :     flags &= ~LOOKUP_REWRITTEN;
    7129              : 
    7130     30473804 :   bool memonly = false;
    7131     30473804 :   switch (code)
    7132              :     {
    7133              :       /* =, ->, [], () must be non-static member functions.  */
    7134      6156004 :     case MODIFY_EXPR:
    7135      6156004 :       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     28751449 :       tree fns;
    7152     28751449 :       if (!lookups)
    7153     21493967 :         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      7257482 :       else if (tree found = purpose_member (fnname, lookups))
    7157      1530165 :         fns = TREE_VALUE (found);
    7158              :       else
    7159              :         fns = NULL_TREE;
    7160     28751449 :       fns = lookup_arg_dependent (fnname, fns, arglist);
    7161     28751449 :       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     32816632 :   tree arg1_type = TREE_TYPE ((*arglist)[0]);
    7168     32816632 :   unsigned nargs = arglist->length () > 1 ? 2 : 1;
    7169     27990665 :   tree arg2_type = nargs > 1 ? TREE_TYPE ((*arglist)[1]) : NULL_TREE;
    7170     32816632 :   if (CLASS_TYPE_P (arg1_type))
    7171              :     {
    7172     19027600 :       tree fns = lookup_fnfields (arg1_type, fnname, 1, complain);
    7173     19027600 :       if (fns == error_mark_node)
    7174              :         return error_mark_node;
    7175     19027588 :       if (fns)
    7176              :         {
    7177      8586005 :           if (code == ARRAY_REF)
    7178              :             {
    7179       456886 :               vec<tree,va_gc> *restlist = make_tree_vector ();
    7180       913772 :               for (unsigned i = 1; i < nargs; ++i)
    7181       456886 :                 vec_safe_push (restlist, (*arglist)[i]);
    7182       456886 :               z_candidate *save_cand = *candidates;
    7183       913772 :               add_candidates (BASELINK_FUNCTIONS (fns),
    7184       456886 :                               (*arglist)[0], restlist, NULL_TREE,
    7185              :                               NULL_TREE, false,
    7186       456886 :                               BASELINK_BINFO (fns),
    7187       456886 :                               BASELINK_ACCESS_BINFO (fns),
    7188              :                               flags, candidates, complain);
    7189              :               /* Release the vec if we didn't add a candidate that uses it.  */
    7190       457484 :               for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7191       457484 :                 if (c->args == restlist)
    7192              :                   {
    7193       456886 :                     restlist = NULL;
    7194       456886 :                     break;
    7195              :                   }
    7196       456886 :               release_tree_vector (restlist);
    7197              :             }
    7198              :           else
    7199      8129119 :             add_candidates (BASELINK_FUNCTIONS (fns),
    7200              :                             NULL_TREE, arglist, NULL_TREE,
    7201              :                             NULL_TREE, false,
    7202      8129119 :                             BASELINK_BINFO (fns),
    7203      8129119 :                             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     13789032 :   else if (! arg2_type || ! CLASS_TYPE_P (arg2_type))
    7214              :     {
    7215              :       struct z_candidate **candp, **next;
    7216              : 
    7217    225852714 :       for (candp = candidates; *candp != start_candidates; candp = next)
    7218              :         {
    7219    212618271 :           unsigned i;
    7220    212618271 :           z_candidate *cand = *candp;
    7221    212618271 :           next = &cand->next;
    7222              : 
    7223    212618271 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    7224              : 
    7225    627233372 :           for (i = 0; i < nargs; ++i)
    7226              :             {
    7227    419540476 :               tree parmtype = TREE_VALUE (parmlist);
    7228    419540476 :               tree argtype = unlowered_expr_type ((*arglist)[i]);
    7229              : 
    7230    419540476 :               if (TYPE_REF_P (parmtype))
    7231    331662714 :                 parmtype = TREE_TYPE (parmtype);
    7232    419540476 :               if (TREE_CODE (argtype) == ENUMERAL_TYPE
    7233    819050128 :                   && (same_type_ignoring_top_level_qualifiers_p
    7234    399509652 :                       (argtype, parmtype)))
    7235              :                 break;
    7236              : 
    7237    414615101 :               parmlist = TREE_CHAIN (parmlist);
    7238              :             }
    7239              : 
    7240              :           /* No argument has an appropriate type, so remove this
    7241              :              candidate function from the list.  */
    7242    212618271 :           if (i == nargs)
    7243              :             {
    7244    207692896 :               *candp = cand->next;
    7245    207692896 :               next = candp;
    7246              :             }
    7247              :         }
    7248              :     }
    7249              : 
    7250     32816620 :   if (!rewritten)
    7251              :     {
    7252              :       /* The standard says to rewrite built-in candidates, too,
    7253              :          but there's no point.  */
    7254     23218087 :       add_builtin_candidates (candidates, code, code2, fnname, arglist,
    7255              :                               flags, complain);
    7256              : 
    7257              :       /* Maybe add C++20 rewritten comparison candidates.  */
    7258     23218087 :       tree_code rewrite_code = ERROR_MARK;
    7259     23218087 :       if (cxx_dialect >= cxx20
    7260     22926928 :           && nargs == 2
    7261     41440426 :           && (OVERLOAD_TYPE_P (arg1_type) || OVERLOAD_TYPE_P (arg2_type)))
    7262     18214719 :         switch (code)
    7263              :           {
    7264      1230952 :           case LT_EXPR:
    7265      1230952 :           case LE_EXPR:
    7266      1230952 :           case GT_EXPR:
    7267      1230952 :           case GE_EXPR:
    7268      1230952 :           case SPACESHIP_EXPR:
    7269      1230952 :             rewrite_code = SPACESHIP_EXPR;
    7270      1230952 :             break;
    7271              : 
    7272              :           case NE_EXPR:
    7273              :           case EQ_EXPR:
    7274              :             rewrite_code = EQ_EXPR;
    7275              :             break;
    7276              : 
    7277              :           default:;
    7278              :           }
    7279              : 
    7280      1230952 :       if (rewrite_code)
    7281              :         {
    7282      5847314 :           tree r;
    7283      5847314 :           flags |= LOOKUP_REWRITTEN;
    7284      5847314 :           if (rewrite_code != code)
    7285              :             {
    7286              :               /* Add rewritten candidates in same order.  */
    7287      2885667 :               r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7288              :                                            arglist, lookups, flags, complain);
    7289      2885667 :               if (r == error_mark_node)
    7290              :                 return error_mark_node;
    7291              :             }
    7292              : 
    7293      5847308 :           z_candidate *save_cand = *candidates;
    7294              : 
    7295              :           /* Add rewritten candidates in reverse order.  */
    7296      5847308 :           flags |= LOOKUP_REVERSED;
    7297      5847308 :           vec<tree,va_gc> *revlist = make_tree_vector ();
    7298      5847308 :           revlist->quick_push ((*arglist)[1]);
    7299      5847308 :           revlist->quick_push ((*arglist)[0]);
    7300      5847308 :           r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7301              :                                        revlist, lookups, flags, complain);
    7302      5847308 :           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      6000467 :           for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7307      2776290 :             if (c->args == revlist)
    7308              :               {
    7309              :                 revlist = NULL;
    7310              :                 break;
    7311              :               }
    7312      5847308 :           release_tree_vector (revlist);
    7313              :         }
    7314              :     }
    7315              : 
    7316              :   return NULL_TREE;
    7317              : }
    7318              : 
    7319              : tree
    7320    205815363 : 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    205815363 :   struct z_candidate *candidates = 0, *cand;
    7325    205815363 :   releasing_vec arglist;
    7326    205815363 :   tree result = NULL_TREE;
    7327    205815363 :   bool result_valid_p = false;
    7328    205815363 :   enum tree_code code2 = ERROR_MARK;
    7329    205815363 :   enum tree_code code_orig_arg1 = ERROR_MARK;
    7330    205815363 :   enum tree_code code_orig_arg2 = ERROR_MARK;
    7331    205815363 :   bool strict_p;
    7332    205815363 :   bool any_viable_p;
    7333              : 
    7334    205815363 :   auto_cond_timevar tv (TV_OVERLOAD);
    7335              : 
    7336    205815363 :   if (error_operand_p (arg1)
    7337    205811454 :       || error_operand_p (arg2)
    7338    411620779 :       || error_operand_p (arg3))
    7339         9947 :     return error_mark_node;
    7340              : 
    7341    205805416 :   conversion_obstack_sentinel cos;
    7342              : 
    7343    205805416 :   bool ismodop = code == MODIFY_EXPR;
    7344    205805416 :   if (ismodop)
    7345              :     {
    7346     10523856 :       code2 = TREE_CODE (arg3);
    7347     10523856 :       arg3 = NULL_TREE;
    7348              :     }
    7349              : 
    7350    205805416 :   tree arg1_type = unlowered_expr_type (arg1);
    7351    205805416 :   tree arg2_type = arg2 ? unlowered_expr_type (arg2) : NULL_TREE;
    7352              : 
    7353    205805416 :   arg1 = prep_operand (arg1);
    7354              : 
    7355    205805416 :   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     17214564 :     case TRUTH_ORIF_EXPR:
    7369     17214564 :     case TRUTH_ANDIF_EXPR:
    7370     17214564 :     case TRUTH_AND_EXPR:
    7371     17214564 :     case TRUTH_OR_EXPR:
    7372              :       /* These are saved for the sake of warn_logical_operator.  */
    7373     17214564 :       code_orig_arg1 = TREE_CODE (arg1);
    7374     17214564 :       code_orig_arg2 = TREE_CODE (arg2);
    7375     17214564 :       break;
    7376     47973667 :     case GT_EXPR:
    7377     47973667 :     case LT_EXPR:
    7378     47973667 :     case GE_EXPR:
    7379     47973667 :     case LE_EXPR:
    7380     47973667 :     case EQ_EXPR:
    7381     47973667 :     case NE_EXPR:
    7382              :       /* These are saved for the sake of maybe_warn_bool_compare.  */
    7383     47973667 :       code_orig_arg1 = TREE_CODE (arg1_type);
    7384     47973667 :       code_orig_arg2 = TREE_CODE (arg2_type);
    7385     47973667 :       break;
    7386              : 
    7387              :     default:
    7388              :       break;
    7389              :     }
    7390              : 
    7391    205805416 :   arg2 = prep_operand (arg2);
    7392    205805416 :   arg3 = prep_operand (arg3);
    7393              : 
    7394    205805416 :   if (code == COND_EXPR)
    7395              :     /* Use build_conditional_expr instead.  */
    7396            0 :     gcc_unreachable ();
    7397    205805416 :   else if (! OVERLOAD_TYPE_P (arg1_type)
    7398    387934800 :            && (! arg2 || ! OVERLOAD_TYPE_P (arg2_type)))
    7399    181721726 :     goto builtin;
    7400              : 
    7401     24083690 :   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    7402              :     {
    7403       318953 :       arg2 = integer_zero_node;
    7404       318953 :       arg2_type = integer_type_node;
    7405              :     }
    7406              : 
    7407     24083690 :   arglist->quick_push (arg1);
    7408     24083690 :   if (arg2 != NULL_TREE)
    7409     19257723 :     arglist->quick_push (arg2);
    7410     24083690 :   if (arg3 != NULL_TREE)
    7411            0 :     arglist->quick_push (arg3);
    7412              : 
    7413     24083690 :   result = add_operator_candidates (&candidates, code, code2, arglist,
    7414              :                                     lookups, flags, complain);
    7415     24083657 :   if (result == error_mark_node)
    7416              :     return error_mark_node;
    7417              : 
    7418     24083645 :   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     22253157 :     default:
    7432     22253157 :       strict_p = false;
    7433     22253157 :       break;
    7434              :     }
    7435              : 
    7436     24083645 :   candidates = splice_viable (candidates, strict_p, &any_viable_p);
    7437     24083645 :   if (!any_viable_p)
    7438              :     {
    7439      1870510 :       switch (code)
    7440              :         {
    7441          241 :         case POSTINCREMENT_EXPR:
    7442          241 :         case POSTDECREMENT_EXPR:
    7443              :           /* Don't try anything fancy if we're not allowed to produce
    7444              :              errors.  */
    7445          241 :           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        37065 :         default:
    7483        37065 :           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         1346 :               if (invalid_nonstatic_memfn_p (loc, arg1, tf_error)
    7489         1343 :                     || invalid_nonstatic_memfn_p (loc, arg2, tf_error)
    7490         2683 :                     || 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         1337 :                     auto_diagnostic_group d;
    7497         1337 :                     op_error (loc, code, code2, arg1, arg2, arg3, false);
    7498         1337 :                     print_z_candidates (loc, candidates);
    7499         1337 :                   }
    7500              :             }
    7501        37065 :           result = error_mark_node;
    7502        37065 :           break;
    7503              :         }
    7504              :     }
    7505              :   else
    7506              :     {
    7507     22213135 :       cand = tourney (candidates, complain);
    7508     22213135 :       if (cand == 0)
    7509              :         {
    7510          184 :           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          184 :           result = error_mark_node;
    7517          184 :           if (overload)
    7518          165 :             *overload = error_mark_node;
    7519              :         }
    7520     22212951 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    7521              :         {
    7522     18331193 :           if (overload)
    7523              :             {
    7524     14106606 :               if (cand->rewritten ())
    7525              :                 /* build_min_non_dep_op_overload needs to know whether the
    7526              :                    candidate is rewritten/reversed.  */
    7527      1699724 :                 *overload = build_tree_list (build_int_cst (integer_type_node,
    7528      1699724 :                                                             cand->flags),
    7529              :                                              cand->fn);
    7530              :               else
    7531     12406882 :                 *overload = cand->fn;
    7532              :             }
    7533              : 
    7534     18331193 :           if (resolve_args (arglist, complain) == NULL)
    7535            6 :             result = error_mark_node;
    7536              :           else
    7537              :             {
    7538     18331187 :               tsubst_flags_t ocomplain = complain;
    7539     18331187 :               if (cand->rewritten ())
    7540              :                 /* We'll wrap this call in another one.  */
    7541      1700306 :                 ocomplain &= ~tf_decltype;
    7542     18331187 :               if (cand->reversed ())
    7543              :                 {
    7544              :                   /* We swapped these in add_candidate, swap them back now.  */
    7545        16531 :                   std::swap (cand->convs[0], cand->convs[1]);
    7546        16531 :                   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     18331187 :               result = build_over_call (cand, LOOKUP_NORMAL, ocomplain);
    7552              :             }
    7553              : 
    7554     34107067 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7555              :             /* There won't be a CALL_EXPR.  */;
    7556     15768622 :           else if (result && result != error_mark_node)
    7557              :             {
    7558     15766052 :               tree call = extract_call_expr (result);
    7559     15766052 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7560              : 
    7561              :               /* Specify evaluation order as per P0145R2.  */
    7562     15766052 :               CALL_EXPR_ORDERED_ARGS (call) = false;
    7563     15766052 :               switch (op_is_ordered (code))
    7564              :                 {
    7565      3567387 :                 case -1:
    7566      3567387 :                   CALL_EXPR_REVERSE_ARGS (call) = true;
    7567      3567387 :                   break;
    7568              : 
    7569       504499 :                 case 1:
    7570       504499 :                   CALL_EXPR_ORDERED_ARGS (call) = true;
    7571       504499 :                   break;
    7572              : 
    7573              :                 default:
    7574              :                   break;
    7575              :                 }
    7576              :             }
    7577              : 
    7578              :           /* If this was a C++20 rewritten comparison, adjust the result.  */
    7579     18331190 :           if (cand->rewritten ())
    7580              :             {
    7581      1700306 :               switch (code)
    7582              :                 {
    7583         7372 :                 case EQ_EXPR:
    7584         7372 :                   gcc_checking_assert (cand->reversed ());
    7585       833739 :                   gcc_fallthrough ();
    7586       833739 :                 case NE_EXPR:
    7587       833739 :                   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       833737 :                   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       833699 :                   else if (code == NE_EXPR)
    7606              :                     /* !(y == x) or !(x == y)  */
    7607       826348 :                     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          593 :                 case SPACESHIP_EXPR:
    7618          593 :                   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       866275 :                   gcc_fallthrough ();
    7623       866275 :                 case LT_EXPR:
    7624       866275 :                 case LE_EXPR:
    7625       866275 :                 case GT_EXPR:
    7626       866275 :                 case GE_EXPR:
    7627       866275 :                   {
    7628       866275 :                     tree lhs = result;
    7629       866275 :                     tree rhs = integer_zero_node;
    7630       866275 :                     if (cand->reversed ())
    7631         2020 :                       std::swap (lhs, rhs);
    7632       866275 :                     warning_sentinel ws (warn_zero_as_null_pointer_constant);
    7633       866275 :                     result = build_new_op (loc, code,
    7634              :                                            LOOKUP_NORMAL|LOOKUP_REWRITTEN,
    7635              :                                            lhs, rhs, NULL_TREE, lookups,
    7636              :                                            NULL, complain);
    7637       866275 :                   }
    7638       866275 :                   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     18331190 :           if (code == ARRAY_REF)
    7649       456869 :             result = keep_unused_object_arg (result, arg1, cand->fn);
    7650              :         }
    7651              :       else
    7652              :         {
    7653              :           /* Give any warnings we noticed during overload resolution.  */
    7654      3881758 :           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      3881758 :           switch (code)
    7663              :             {
    7664      3042958 :             case GT_EXPR:
    7665      3042958 :             case LT_EXPR:
    7666      3042958 :             case GE_EXPR:
    7667      3042958 :             case LE_EXPR:
    7668      3042958 :             case EQ_EXPR:
    7669      3042958 :             case NE_EXPR:
    7670      3042958 :               if (TREE_CODE (arg1_type) == ENUMERAL_TYPE
    7671      2846873 :                   && TREE_CODE (arg2_type) == ENUMERAL_TYPE
    7672      5816589 :                   && (TYPE_MAIN_VARIANT (arg1_type)
    7673      2773631 :                       != TYPE_MAIN_VARIANT (arg2_type)))
    7674              :                 {
    7675           80 :                   if (cxx_dialect >= cxx26
    7676           26 :                       && (complain & tf_warning_or_error) == 0)
    7677            2 :                     result = error_mark_node;
    7678           78 :                   else if (cxx_dialect >= cxx26 || (complain & tf_warning))
    7679          130 :                     emit_diagnostic ((cxx_dialect >= cxx26
    7680              :                                       ? diagnostics::kind::pedwarn
    7681              :                                       : diagnostics::kind::warning),
    7682           77 :                                      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      3881758 :           conversion *conv = cand->convs[0];
    7697      3881758 :           if (conv->user_conv_p)
    7698              :             {
    7699        48653 :               conv = strip_standard_conversion (conv);
    7700        48653 :               arg1 = convert_like (conv, arg1, complain);
    7701              :             }
    7702              : 
    7703      3881758 :           if (arg2)
    7704              :             {
    7705      3409048 :               conv = cand->convs[1];
    7706      3409048 :               if (conv->user_conv_p)
    7707              :                 {
    7708         9848 :                   conv = strip_standard_conversion (conv);
    7709         9848 :                   arg2 = convert_like (conv, arg2, complain);
    7710              :                 }
    7711              :             }
    7712              : 
    7713      3881758 :           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     24083413 :   if (result || result_valid_p)
    7726              :     return result;
    7727              : 
    7728      3881756 :  builtin:
    7729    185603482 :   switch (code)
    7730              :     {
    7731      4368283 :     case MODIFY_EXPR:
    7732      4368283 :       return cp_build_modify_expr (loc, arg1, code2, arg2, complain);
    7733              : 
    7734     19232633 :     case INDIRECT_REF:
    7735     19232633 :       return cp_build_indirect_ref (loc, arg1, RO_UNARY_STAR, complain);
    7736              : 
    7737     17213308 :     case TRUTH_ANDIF_EXPR:
    7738     17213308 :     case TRUTH_ORIF_EXPR:
    7739     17213308 :     case TRUTH_AND_EXPR:
    7740     17213308 :     case TRUTH_OR_EXPR:
    7741     17213308 :       if ((complain & tf_warning) && !processing_template_decl)
    7742      7158037 :         warn_logical_operator (loc, code, boolean_type_node,
    7743              :                                code_orig_arg1, arg1,
    7744              :                                code_orig_arg2, arg2);
    7745              :       /* Fall through.  */
    7746     60853247 :     case GT_EXPR:
    7747     60853247 :     case LT_EXPR:
    7748     60853247 :     case GE_EXPR:
    7749     60853247 :     case LE_EXPR:
    7750     60853247 :     case EQ_EXPR:
    7751     60853247 :     case NE_EXPR:
    7752     60853247 :       if ((complain & tf_warning)
    7753     55167836 :           && ((code_orig_arg1 == BOOLEAN_TYPE)
    7754     55167836 :               ^ (code_orig_arg2 == BOOLEAN_TYPE)))
    7755        25673 :         maybe_warn_bool_compare (loc, code, arg1, arg2);
    7756     55167836 :       if (complain & tf_warning && warn_tautological_compare)
    7757       450331 :         warn_tautological_cmp (loc, code, arg1, arg2);
    7758              :       /* Fall through.  */
    7759    127359358 :     case SPACESHIP_EXPR:
    7760    127359358 :     case PLUS_EXPR:
    7761    127359358 :     case MINUS_EXPR:
    7762    127359358 :     case MULT_EXPR:
    7763    127359358 :     case TRUNC_DIV_EXPR:
    7764    127359358 :     case MAX_EXPR:
    7765    127359358 :     case MIN_EXPR:
    7766    127359358 :     case LSHIFT_EXPR:
    7767    127359358 :     case RSHIFT_EXPR:
    7768    127359358 :     case TRUNC_MOD_EXPR:
    7769    127359358 :     case BIT_AND_EXPR:
    7770    127359358 :     case BIT_IOR_EXPR:
    7771    127359358 :     case BIT_XOR_EXPR:
    7772    127359358 :       return cp_build_binary_op (loc, code, arg1, arg2, complain);
    7773              : 
    7774     29463486 :     case UNARY_PLUS_EXPR:
    7775     29463486 :     case NEGATE_EXPR:
    7776     29463486 :     case BIT_NOT_EXPR:
    7777     29463486 :     case TRUTH_NOT_EXPR:
    7778     29463486 :     case PREINCREMENT_EXPR:
    7779     29463486 :     case POSTINCREMENT_EXPR:
    7780     29463486 :     case PREDECREMENT_EXPR:
    7781     29463486 :     case POSTDECREMENT_EXPR:
    7782     29463486 :     case REALPART_EXPR:
    7783     29463486 :     case IMAGPART_EXPR:
    7784     29463486 :     case ABS_EXPR:
    7785     29463486 :     case CO_AWAIT_EXPR:
    7786     29463486 :       return cp_build_unary_op (code, arg1, false, complain);
    7787              : 
    7788      2282139 :     case ARRAY_REF:
    7789      2282139 :       return cp_build_array_ref (input_location, arg1, arg2, complain);
    7790              : 
    7791          755 :     case MEMBER_REF:
    7792          755 :       return build_m_component_ref (cp_build_indirect_ref (loc, arg1,
    7793              :                                                            RO_ARROW_STAR,
    7794              :                                                            complain),
    7795          755 :                                     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    205815327 : }
    7808              : 
    7809              : /* Build a new call to operator[].  This may change ARGS.  */
    7810              : 
    7811              : tree
    7812          490 : 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          490 :   struct z_candidate *candidates = 0, *cand;
    7817          490 :   tree fns, first_mem_arg = NULL_TREE;
    7818          490 :   bool any_viable_p;
    7819          490 :   tree result = NULL_TREE;
    7820              : 
    7821          490 :   auto_cond_timevar tv (TV_OVERLOAD);
    7822              : 
    7823          490 :   obj = mark_lvalue_use (obj);
    7824              : 
    7825          490 :   if (error_operand_p (obj))
    7826            0 :     return error_mark_node;
    7827              : 
    7828          490 :   tree type = TREE_TYPE (obj);
    7829              : 
    7830          490 :   obj = prep_operand (obj);
    7831              : 
    7832          490 :   if (TYPE_BINFO (type))
    7833              :     {
    7834          490 :       fns = lookup_fnfields (TYPE_BINFO (type), ovl_op_identifier (ARRAY_REF),
    7835              :                              1, complain);
    7836          490 :       if (fns == error_mark_node)
    7837              :         return error_mark_node;
    7838              :     }
    7839              :   else
    7840              :     fns = NULL_TREE;
    7841              : 
    7842          490 :   if (args != NULL && *args != NULL)
    7843              :     {
    7844          490 :       *args = resolve_args (*args, complain);
    7845          490 :       if (*args == NULL)
    7846            0 :         return error_mark_node;
    7847              :     }
    7848              : 
    7849          490 :   conversion_obstack_sentinel cos;
    7850              : 
    7851          490 :   if (fns)
    7852              :     {
    7853          488 :       first_mem_arg = obj;
    7854              : 
    7855          488 :       add_candidates (BASELINK_FUNCTIONS (fns),
    7856              :                       first_mem_arg, *args, NULL_TREE,
    7857              :                       NULL_TREE, false,
    7858          488 :                       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          490 :   candidates = splice_viable (candidates, true, &any_viable_p);
    7865          490 :   if (!any_viable_p)
    7866              :     {
    7867           45 :       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           45 :       result = error_mark_node;
    7875              :     }
    7876              :   else
    7877              :     {
    7878          445 :       cand = tourney (candidates, complain);
    7879          445 :       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          445 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    7891          445 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    7892          890 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, ARRAY_REF))
    7893              :         {
    7894          445 :           if (overload)
    7895          445 :             *overload = cand->fn;
    7896          445 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    7897          890 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7898              :             /* There won't be a CALL_EXPR.  */;
    7899          445 :           else if (result && result != error_mark_node)
    7900              :             {
    7901          445 :               tree call = extract_call_expr (result);
    7902          445 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7903              : 
    7904              :               /* Specify evaluation order as per P0145R2.  */
    7905          445 :               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          445 :           result = keep_unused_object_arg (result, obj, cand->fn);
    7912              :         }
    7913              :       else
    7914            0 :         gcc_unreachable ();
    7915              :     }
    7916              : 
    7917          490 :   return result;
    7918          490 : }
    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     43264657 : extract_call_expr (tree call)
    7926              : {
    7927     43265337 :   while (TREE_CODE (call) == COMPOUND_EXPR)
    7928          680 :     call = TREE_OPERAND (call, 1);
    7929     43264657 :   if (REFERENCE_REF_P (call))
    7930     10204613 :     call = TREE_OPERAND (call, 0);
    7931     43264657 :   if (TREE_CODE (call) == TARGET_EXPR)
    7932      2913286 :     call = TARGET_EXPR_INITIAL (call);
    7933              : 
    7934     43264657 :   if (TREE_CODE (call) != CALL_EXPR
    7935       843090 :       && TREE_CODE (call) != AGGR_INIT_EXPR
    7936       744939 :       && call != error_mark_node)
    7937       744921 :     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       639652 : second_parm_is_size_t (tree fn)
    7946              : {
    7947       639652 :   tree t = FUNCTION_ARG_CHAIN (fn);
    7948       639652 :   if (!t || !same_type_p (TREE_VALUE (t), size_type_node))
    7949       639637 :     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       331370 : aligned_allocation_fn_p (tree t)
    7961              : {
    7962       331370 :   if (!aligned_new_threshold)
    7963              :     return false;
    7964              : 
    7965       322184 :   tree a = FUNCTION_ARG_CHAIN (t);
    7966       322184 :   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      5450544 : std_destroying_delete_t_p (tree t)
    7973              : {
    7974      5450544 :   return (TYPE_CONTEXT (t) == std_node
    7975      5450544 :           && 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      5450559 : destroying_delete_p (tree t)
    7986              : {
    7987      5450559 :   tree a = TYPE_ARG_TYPES (TREE_TYPE (t));
    7988      5450559 :   if (!a || !TREE_CHAIN (a))
    7989              :     return NULL_TREE;
    7990      5450544 :   tree type = TREE_VALUE (TREE_CHAIN (a));
    7991      5450544 :   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      3716348 : usual_deallocation_fn_p (tree t, dealloc_info *di)
    8007              : {
    8008      3716348 :   if (di) *di = dealloc_info();
    8009              : 
    8010              :   /* A template instance is never a usual deallocation function,
    8011              :      regardless of its signature.  */
    8012      3716348 :   if (TREE_CODE (t) == TEMPLATE_DECL
    8013      3716348 :       || 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      3716336 :   bool global = DECL_NAMESPACE_SCOPE_P (t);
    8022      3716336 :   tree chain = FUNCTION_ARG_CHAIN (t);
    8023      3716336 :   if (chain && destroying_delete_p (t))
    8024              :     {
    8025           78 :       if (di) di->destroying = TREE_VALUE (chain);
    8026           78 :       chain = TREE_CHAIN (chain);
    8027              :     }
    8028      3716336 :   if (chain
    8029      3716333 :       && (!global || flag_sized_deallocation)
    8030      7418713 :       && same_type_p (TREE_VALUE (chain), size_type_node))
    8031              :     {
    8032      1071500 :       if (di) di->sized = true;
    8033      1071500 :       chain = TREE_CHAIN (chain);
    8034              :     }
    8035      3716333 :   if (chain && aligned_new_threshold
    8036      7417680 :       && same_type_p (TREE_VALUE (chain), align_type_node))
    8037              :     {
    8038      1590505 :       if (di) di->aligned = true;
    8039      1590505 :       chain = TREE_CHAIN (chain);
    8040              :     }
    8041      3716336 :   return (chain == void_list_node);
    8042              : }
    8043              : 
    8044              : /* Just return whether FN is a usual deallocation function.  */
    8045              : 
    8046              : bool
    8047         8836 : usual_deallocation_fn_p (tree fn)
    8048              : {
    8049         8836 :   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      1180834 : 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      1180834 :   tree fn = NULL_TREE;
    8080      1180834 :   tree fns, fnname, type, t;
    8081      1180834 :   dealloc_info di_fn = { };
    8082              : 
    8083      1180834 :   if (addr == error_mark_node)
    8084              :     return error_mark_node;
    8085              : 
    8086      1180834 :   type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
    8087              : 
    8088      1180834 :   fnname = ovl_op_identifier (false, code);
    8089              : 
    8090       820699 :   if (CLASS_TYPE_P (type)
    8091       820663 :       && COMPLETE_TYPE_P (complete_type (type))
    8092      2001462 :       && !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       485809 :       fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1, complain);
    8102       485809 :       if (fns == error_mark_node)
    8103              :         return error_mark_node;
    8104              :     }
    8105              :   else
    8106              :     fns = NULL_TREE;
    8107              : 
    8108       485806 :   if (fns == NULL_TREE)
    8109      1179762 :     fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    8110              : 
    8111              :   /* Strip const and volatile from addr.  */
    8112      1180831 :   tree oaddr = addr;
    8113      1180831 :   addr = cp_convert (ptr_type_node, addr, complain);
    8114              : 
    8115      1180831 :   tree excluded_destroying = NULL_TREE;
    8116              : 
    8117      1180831 :   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       640536 :       t = FUNCTION_ARG_CHAIN (alloc_fn);
    8127       640536 :       t = tree_cons (NULL_TREE, ptr_type_node, t);
    8128       640536 :       t = build_function_type (void_type_node, t);
    8129              : 
    8130       640536 :       fn = instantiate_type (t, fns, tf_none);
    8131       640536 :       if (fn == error_mark_node)
    8132              :         return NULL_TREE;
    8133              : 
    8134       639652 :       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       639652 :       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      1179947 :         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      4788102 :     for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8198              :       {
    8199      3707512 :         dealloc_info di_elt;
    8200      3707512 :         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      2141013 :             if (alloc_fn && di_elt.destroying)
    8206              :               {
    8207           13 :                 excluded_destroying = elt;
    8208      1091701 :                 continue;
    8209              :               }
    8210              : 
    8211      2141000 :             if (!fn)
    8212              :               {
    8213       540270 :                 fn = elt;
    8214       540270 :                 di_fn = di_elt;
    8215       540270 :                 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      1600730 :             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      1600718 :             if (aligned_new_threshold)
    8240              :               {
    8241      1600451 :                 bool want_align = type_has_new_extended_alignment (type);
    8242      1600451 :                 if (di_elt.aligned != di_fn.aligned)
    8243              :                   {
    8244       551406 :                     if (want_align == di_elt.aligned)
    8245              :                       {
    8246       515549 :                         fn = elt;
    8247       515549 :                         di_fn = di_elt;
    8248              :                       }
    8249       551406 :                     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      1049312 :             bool want_size;
    8256      1049312 :             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      1049204 :                 want_size = COMPLETE_TYPE_P (type);
    8270      1049204 :                 if (code == VEC_DELETE_EXPR
    8271      1049204 :                     && !TYPE_VEC_NEW_USES_COOKIE (type))
    8272              :                   /* We need a cookie to determine the array size.  */
    8273              :                   want_size = false;
    8274              :               }
    8275      1049312 :             gcc_assert (di_fn.sized != di_elt.sized);
    8276      1049312 :             if (want_size == di_elt.sized)
    8277              :               {
    8278        43626 :                 fn = elt;
    8279        43626 :                 di_fn = di_elt;
    8280              :               }
    8281              :           }
    8282              :       }
    8283              : 
    8284              :   /* If we have a matching function, call it.  */
    8285      1179947 :   if (fn)
    8286              :     {
    8287      1179922 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    8288              : 
    8289              :       /* If the FN is a member function, make sure that it is
    8290              :          accessible.  */
    8291      1179922 :       if (BASELINK_P (fns))
    8292         1002 :         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      1179922 :       if (DECL_DELETED_FN (fn) && alloc_fn)
    8297              :         return NULL_TREE;
    8298              : 
    8299      1179916 :       tree ret;
    8300      1179916 :       if (placement)
    8301              :         {
    8302              :           /* The placement args might not be suitable for overload
    8303              :              resolution at this point, so build the call directly.  */
    8304       639652 :           int nargs = call_expr_nargs (placement);
    8305       639652 :           tree *argarray = XALLOCAVEC (tree, nargs);
    8306       639652 :           int i;
    8307       639652 :           argarray[0] = addr;
    8308      1279355 :           for (i = 1; i < nargs; i++)
    8309       639703 :             argarray[i] = CALL_EXPR_ARG (placement, i);
    8310       639652 :           if (!mark_used (fn, complain) && !(complain & tf_error))
    8311            0 :             return error_mark_node;
    8312       639652 :           ret = build_cxx_call (fn, nargs, argarray, complain);
    8313              :         }
    8314              :       else
    8315              :         {
    8316       540264 :           tree destroying = di_fn.destroying;
    8317       540264 :           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       540264 :           releasing_vec args;
    8331       540264 :           args->quick_push (addr);
    8332       540264 :           if (destroying)
    8333           25 :             args->quick_push (destroying);
    8334       540264 :           if (di_fn.sized)
    8335       503266 :             args->quick_push (size);
    8336       540264 :           if (di_fn.aligned)
    8337              :             {
    8338        17932 :               tree al = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (type));
    8339        17932 :               args->quick_push (al);
    8340              :             }
    8341       540264 :           ret = cp_build_function_call_vec (fn, &args, complain);
    8342       540264 :         }
    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      1179916 :       tree call = extract_call_expr (ret);
    8352      1179916 :       if (TREE_CODE (call) == CALL_EXPR && !destroying_delete_p (fn))
    8353      1179885 :         CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    8354              : 
    8355      1179916 :       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) && !placement)
    8374              :         {
    8375           15 :           auto_diagnostic_group d;
    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           15 :         }
    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      1177593 : 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      1177593 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/false,
    8401      1177593 :                                  placement, alloc_fn, complain);
    8402              : }
    8403              : 
    8404              : /* Arguments as per build_op_delete_call_1 ().  */
    8405              : 
    8406              : tree
    8407         3241 : 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         3241 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/true,
    8412         3241 :                                  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         1181 : 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         1181 :   if (no_access_reason == ak_none)
    8434              :     {
    8435              :       /* Examine the access of DECL to find out why.  */
    8436          999 :       if (TREE_PRIVATE (decl))
    8437              :         no_access_reason = ak_private;
    8438          225 :       else if (TREE_PROTECTED (decl))
    8439          180 :         no_access_reason = ak_protected;
    8440              :     }
    8441              : 
    8442              :   /* Now generate an error message depending on calculated access.  */
    8443         1181 :   auto_diagnostic_group d;
    8444         1181 :   if (no_access_reason == ak_private)
    8445              :     {
    8446          956 :       if (issue_error)
    8447          942 :         error ("%q#D is private within this context", diag_decl);
    8448          956 :       inform (DECL_SOURCE_LOCATION (diag_location), "declared private here");
    8449              :     }
    8450          225 :   else if (no_access_reason == ak_protected)
    8451              :     {
    8452          180 :       if (issue_error)
    8453          166 :         error ("%q#D is protected within this context", diag_decl);
    8454          180 :       inform (DECL_SOURCE_LOCATION (diag_location), "declared protected here");
    8455              :     }
    8456              :   /* Couldn't figure out why DECL is inaccessible, so just say it's
    8457              :      inaccessible.  */
    8458              :   else
    8459              :     {
    8460           45 :       if (issue_error)
    8461           45 :         error ("%q#D is inaccessible within this context", diag_decl);
    8462           45 :       inform (DECL_SOURCE_LOCATION (diag_decl), "declared here");
    8463              :     }
    8464         1181 : }
    8465              : 
    8466              : /* Initialize a temporary of type TYPE with EXPR.  The FLAGS are a
    8467              :    bitwise or of LOOKUP_* values.  If any errors are warnings are
    8468              :    generated, set *DIAGNOSTIC_FN to "error" or "warning",
    8469              :    respectively.  If no diagnostics are generated, set *DIAGNOSTIC_FN
    8470              :    to NULL.  */
    8471              : 
    8472              : static tree
    8473     13109736 : build_temp (tree expr, tree type, int flags,
    8474              :             enum diagnostics::kind *diagnostic_kind, tsubst_flags_t complain)
    8475              : {
    8476     13109736 :   int savew, savee;
    8477              : 
    8478     13109736 :   *diagnostic_kind = diagnostics::kind::unspecified;
    8479              : 
    8480              :   /* If the source is a packed field, calling the copy constructor will require
    8481              :      binding the field to the reference parameter to the copy constructor, and
    8482              :      we'll end up with an infinite loop.  If we can use a bitwise copy, then
    8483              :      do that now.  */
    8484     13109736 :   if ((lvalue_kind (expr) & clk_packed)
    8485            6 :       && CLASS_TYPE_P (TREE_TYPE (expr))
    8486     13109742 :       && !type_has_nontrivial_copy_init (TREE_TYPE (expr)))
    8487            3 :     return get_target_expr (expr, complain);
    8488              : 
    8489              :   /* In decltype, we might have decided not to wrap this call in a TARGET_EXPR.
    8490              :      But it turns out to be a subexpression, so perform temporary
    8491              :      materialization now.  */
    8492     13109733 :   if (TREE_CODE (expr) == CALL_EXPR
    8493            6 :       && CLASS_TYPE_P (type)
    8494     13109739 :       && same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (expr)))
    8495            3 :     expr = build_cplus_new (type, expr, complain);
    8496              : 
    8497     13109733 :   savew = warningcount + werrorcount, savee = errorcount;
    8498     13109733 :   releasing_vec args (make_tree_vector_single (expr));
    8499     13109733 :   expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
    8500              :                                     &args, type, flags, complain);
    8501     13109733 :   if (warningcount + werrorcount > savew)
    8502            0 :     *diagnostic_kind = diagnostics::kind::warning;
    8503     13109733 :   else if (errorcount > savee)
    8504           78 :     *diagnostic_kind = diagnostics::kind::error;
    8505     13109733 :   return expr;
    8506     13109733 : }
    8507              : 
    8508              : /* Get any location for EXPR, falling back to input_location.
    8509              : 
    8510              :    If the result is in a system header and is the virtual location for
    8511              :    a token coming from the expansion of a macro, unwind it to the
    8512              :    location of the expansion point of the macro (e.g. to avoid the
    8513              :    diagnostic being suppressed for expansions of NULL where "NULL" is
    8514              :    in a system header).  */
    8515              : 
    8516              : static location_t
    8517      2295398 : get_location_for_expr_unwinding_for_system_header (tree expr)
    8518              : {
    8519      2295398 :   location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
    8520      2295398 :   loc = expansion_point_location_if_in_system_header (loc);
    8521      2295398 :   return loc;
    8522              : }
    8523              : 
    8524              : /* Perform warnings about peculiar, but valid, conversions from/to NULL.
    8525              :    Also handle a subset of zero as null warnings.
    8526              :    EXPR is implicitly converted to type TOTYPE.
    8527              :    FN and ARGNUM are used for diagnostics.  */
    8528              : 
    8529              : static void
    8530    513819770 : conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
    8531              : {
    8532              :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    8533    513819770 :   if (TREE_CODE (totype) != BOOLEAN_TYPE
    8534    310374662 :       && ARITHMETIC_TYPE_P (totype)
    8535    690944211 :       && null_node_p (expr))
    8536              :     {
    8537           94 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8538           94 :       if (fn)
    8539              :         {
    8540           33 :           auto_diagnostic_group d;
    8541           33 :           if (warning_at (loc, OPT_Wconversion_null,
    8542              :                           "passing NULL to non-pointer argument %P of %qD",
    8543              :                           argnum, fn))
    8544           27 :             inform (get_fndecl_argument_location (fn, argnum),
    8545              :                     "declared here");
    8546           33 :         }
    8547              :       else
    8548           61 :         warning_at (loc, OPT_Wconversion_null,
    8549              :                     "converting to non-pointer type %qT from NULL", totype);
    8550              :     }
    8551              : 
    8552              :   /* Issue warnings if "false" is converted to a NULL pointer */
    8553    513819676 :   else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
    8554    513819676 :            && TYPE_PTR_P (totype))
    8555              :     {
    8556            7 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8557            7 :       if (fn)
    8558              :         {
    8559            3 :           auto_diagnostic_group d;
    8560            3 :           if (warning_at (loc, OPT_Wconversion_null,
    8561              :                           "converting %<false%> to pointer type for argument "
    8562              :                           "%P of %qD", argnum, fn))
    8563            3 :             inform (get_fndecl_argument_location (fn, argnum),
    8564              :                     "declared here");
    8565            3 :         }
    8566              :       else
    8567            4 :         warning_at (loc, OPT_Wconversion_null,
    8568              :                     "converting %<false%> to pointer type %qT", totype);
    8569              :     }
    8570              :   /* Handle zero as null pointer warnings for cases other
    8571              :      than EQ_EXPR and NE_EXPR */
    8572    473688005 :   else if ((TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype))
    8573    514122372 :            && null_ptr_cst_p (expr))
    8574              :     {
    8575      2295297 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8576      2295297 :       maybe_warn_zero_as_null_pointer_constant (expr, loc);
    8577              :     }
    8578    513819770 : }
    8579              : 
    8580              : /* We gave a diagnostic during a conversion.  If this was in the second
    8581              :    standard conversion sequence of a user-defined conversion sequence, say
    8582              :    which user-defined conversion.  */
    8583              : 
    8584              : static void
    8585         5235 : maybe_print_user_conv_context (conversion *convs)
    8586              : {
    8587         5235 :   if (convs->user_conv_p)
    8588          167 :     for (conversion *t = convs; t; t = next_conversion (t))
    8589          142 :       if (t->kind == ck_user)
    8590              :         {
    8591           43 :           print_z_candidate (0, N_("  after user-defined conversion:"),
    8592              :                              t->cand);
    8593           43 :           break;
    8594              :         }
    8595         5235 : }
    8596              : 
    8597              : /* Locate the parameter with the given index within FNDECL.
    8598              :    ARGNUM is zero based, -1 indicates the `this' argument of a method.
    8599              :    Return the location of the FNDECL itself if there are problems.  */
    8600              : 
    8601              : location_t
    8602      8631274 : get_fndecl_argument_location (tree fndecl, int argnum)
    8603              : {
    8604              :   /* The locations of implicitly-declared functions are likely to be
    8605              :      more meaningful than those of their parameters.  */
    8606      8631274 :   if (DECL_ARTIFICIAL (fndecl))
    8607          297 :     return DECL_SOURCE_LOCATION (fndecl);
    8608              : 
    8609      8630977 :   if (argnum == -1)
    8610           51 :     return DECL_SOURCE_LOCATION (fndecl);
    8611              : 
    8612      8630926 :   int i;
    8613      8630926 :   tree param;
    8614              : 
    8615              :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8616      8630926 :   for (i = 0, param = FUNCTION_FIRST_USER_PARM (fndecl);
    8617     21669139 :        i < argnum && param;
    8618     13038213 :        i++, param = TREE_CHAIN (param))
    8619              :     ;
    8620              : 
    8621              :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    8622              :      return the location of FNDECL.  */
    8623      8630926 :   if (param == NULL)
    8624           38 :     return DECL_SOURCE_LOCATION (fndecl);
    8625              : 
    8626      8630888 :   return DECL_SOURCE_LOCATION (param);
    8627              : }
    8628              : 
    8629              : /* If FNDECL is non-NULL, issue a note highlighting ARGNUM
    8630              :    within its declaration (or the fndecl itself if something went
    8631              :    wrong).  */
    8632              : 
    8633              : void
    8634         6986 : maybe_inform_about_fndecl_for_bogus_argument_init (tree fn, int argnum,
    8635              :                                                    const char *highlight_color)
    8636              : {
    8637         6986 :   if (fn)
    8638              :     {
    8639         1106 :       gcc_rich_location richloc (get_fndecl_argument_location (fn, argnum));
    8640         1106 :       richloc.set_highlight_color (highlight_color);
    8641         1106 :       inform (&richloc,
    8642              :               "initializing argument %P of %qD", argnum, fn);
    8643         1106 :     }
    8644         6986 : }
    8645              : 
    8646              : /* Maybe warn about C++20 Conversions to arrays of unknown bound.  C is
    8647              :    the conversion, EXPR is the expression we're converting.  */
    8648              : 
    8649              : static void
    8650     36620859 : maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
    8651              : {
    8652     36620859 :   if (cxx_dialect >= cxx20)
    8653              :     return;
    8654              : 
    8655       424705 :   tree type = TREE_TYPE (expr);
    8656       424705 :   type = strip_pointer_operator (type);
    8657              : 
    8658       424705 :   if (TREE_CODE (type) != ARRAY_TYPE
    8659       424705 :       || TYPE_DOMAIN (type) == NULL_TREE)
    8660              :     return;
    8661              : 
    8662         1851 :   if (pedantic && conv_binds_to_array_of_unknown_bound (c))
    8663           10 :     pedwarn (loc, OPT_Wc__20_extensions,
    8664              :              "conversions to arrays of unknown bound "
    8665              :              "are only available with %<-std=c++20%> or %<-std=gnu++20%>");
    8666              : }
    8667              : 
    8668              : /* We call this recursively in convert_like_internal.  */
    8669              : static tree convert_like (conversion *, tree, tree, int, bool, bool, bool,
    8670              :                           tsubst_flags_t);
    8671              : 
    8672              : /* Adjust the result EXPR of a conversion to the expected type TOTYPE, which
    8673              :    must be equivalent but might be a typedef.  */
    8674              : 
    8675              : static tree
    8676    858318894 : maybe_adjust_type_name (tree type, tree expr, conversion_kind kind)
    8677              : {
    8678    858318894 :   if (expr == error_mark_node
    8679    858318843 :       || processing_template_decl)
    8680              :     return expr;
    8681              : 
    8682    752492740 :   tree etype = TREE_TYPE (expr);
    8683    752492740 :   if (etype == type)
    8684              :     return expr;
    8685              : 
    8686    100062927 :   gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p (etype, type)
    8687              :                        || is_bitfield_expr_with_lowered_type (expr)
    8688              :                        || seen_error ());
    8689              : 
    8690     97461628 :   if (SCALAR_TYPE_P (type)
    8691    191881971 :       && (kind == ck_rvalue
    8692              :           /* ??? We should be able to do this for ck_identity of more prvalue
    8693              :              expressions, but checking !obvalue_p here breaks, so for now let's
    8694              :              just handle NON_LVALUE_EXPR (such as the location wrapper for a
    8695              :              literal).  Maybe we want to express already-rvalue in the
    8696              :              conversion somehow?  */
    8697     84766896 :           || TREE_CODE (expr) == NON_LVALUE_EXPR))
    8698     11107671 :     expr = build_nop (type, expr);
    8699              : 
    8700              :   return expr;
    8701              : }
    8702              : 
    8703              : /* Perform the conversions in CONVS on the expression EXPR.  FN and
    8704              :    ARGNUM are used for diagnostics.  ARGNUM is zero based, -1
    8705              :    indicates the `this' argument of a method.  INNER is nonzero when
    8706              :    being called to continue a conversion chain. It is negative when a
    8707              :    reference binding will be applied, positive otherwise.  If
    8708              :    ISSUE_CONVERSION_WARNINGS is true, warnings about suspicious
    8709              :    conversions will be emitted if appropriate.  If C_CAST_P is true,
    8710              :    this conversion is coming from a C-style cast; in that case,
    8711              :    conversions to inaccessible bases are permitted.  */
    8712              : 
    8713              : static tree
    8714   1046181049 : convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
    8715              :                        bool issue_conversion_warnings, bool c_cast_p,
    8716              :                        bool nested_p, tsubst_flags_t complain)
    8717              : {
    8718   1046181049 :   tree totype = convs->type;
    8719   1046181049 :   enum diagnostics::kind diag_kind;
    8720   1046181049 :   int flags;
    8721   1046181049 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    8722   1046181049 :   const bool stub_object_p = is_stub_object (expr);
    8723              : 
    8724   1046181049 :   if (convs->bad_p && !(complain & tf_error))
    8725        42979 :     return error_mark_node;
    8726              : 
    8727   1046138070 :   gcc_checking_assert (!TYPE_REF_P (TREE_TYPE (expr)));
    8728              : 
    8729   1046138070 :   if (convs->bad_p
    8730         6957 :       && convs->kind != ck_user
    8731         6862 :       && convs->kind != ck_list
    8732         6856 :       && convs->kind != ck_ambig
    8733         6856 :       && (convs->kind != ck_ref_bind
    8734         5242 :           || (convs->user_conv_p && next_conversion (convs)->bad_p))
    8735         1635 :       && (convs->kind != ck_rvalue
    8736           15 :           || SCALAR_TYPE_P (totype))
    8737   1046139696 :       && convs->kind != ck_base)
    8738              :     {
    8739         1626 :       int complained = 0;
    8740         1626 :       conversion *t = convs;
    8741         1626 :       auto_diagnostic_group d;
    8742              : 
    8743              :       /* Give a helpful error if this is bad because of excess braces.  */
    8744           46 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8745           46 :           && SCALAR_TYPE_P (totype)
    8746           34 :           && CONSTRUCTOR_NELTS (expr) > 0
    8747         1660 :           && BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
    8748              :         {
    8749           11 :           complained = permerror (loc, "too many braces around initializer "
    8750              :                                   "for %qT", totype);
    8751           33 :           while (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8752           55 :                  && CONSTRUCTOR_NELTS (expr) == 1)
    8753           22 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    8754              :         }
    8755              : 
    8756              :       /* Give a helpful error if this is bad because a conversion to bool
    8757              :          from std::nullptr_t requires direct-initialization.  */
    8758         1626 :       if (NULLPTR_TYPE_P (TREE_TYPE (expr))
    8759         1626 :           && TREE_CODE (totype) == BOOLEAN_TYPE)
    8760           15 :         complained = permerror (loc, "converting to %qH from %qI requires "
    8761              :                                 "direct-initialization",
    8762           15 :                                 totype, TREE_TYPE (expr));
    8763              : 
    8764         1626 :       if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (expr))
    8765          105 :           && SCALAR_FLOAT_TYPE_P (totype)
    8766         1731 :           && (extended_float_type_p (TREE_TYPE (expr))
    8767           27 :               || extended_float_type_p (totype)))
    8768          105 :         switch (cp_compare_floating_point_conversion_ranks (TREE_TYPE (expr),
    8769              :                                                             totype))
    8770              :           {
    8771          102 :           case 2:
    8772          102 :             if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow "
    8773              :                          "converting to %qH from %qI with greater "
    8774          102 :                          "conversion rank", totype, TREE_TYPE (expr)))
    8775         1626 :               complained = 1;
    8776           21 :             else if (!complained)
    8777           21 :               complained = -1;
    8778              :             break;
    8779            3 :           case 3:
    8780            3 :             if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow "
    8781              :                          "converting to %qH from %qI with unordered "
    8782            3 :                          "conversion rank", totype, TREE_TYPE (expr)))
    8783              :               complained = 1;
    8784            0 :             else if (!complained)
    8785           21 :               complained = -1;
    8786              :             break;
    8787              :           default:
    8788              :             break;
    8789              :           }
    8790              : 
    8791         3268 :       for (; t ; t = next_conversion (t))
    8792              :         {
    8793         3259 :           if (t->kind == ck_user && t->cand->reason)
    8794              :             {
    8795           52 :               auto_diagnostic_group d;
    8796           52 :               complained = permerror (loc, "invalid user-defined conversion "
    8797           52 :                                       "from %qH to %qI", TREE_TYPE (expr),
    8798              :                                       totype);
    8799           52 :               if (complained)
    8800              :                 {
    8801           52 :                   auto_diagnostic_nesting_level sentinel;
    8802           52 :                   print_z_candidate (loc, N_("candidate is:"), t->cand);
    8803           52 :                 }
    8804           52 :               expr = convert_like (t, expr, fn, argnum,
    8805              :                                    /*issue_conversion_warnings=*/false,
    8806              :                                    /*c_cast_p=*/false, /*nested_p=*/true,
    8807              :                                    complain);
    8808           52 :               break;
    8809           52 :             }
    8810         3207 :           else if (t->kind == ck_user || !t->bad_p)
    8811              :             {
    8812         1565 :               expr = convert_like (t, expr, fn, argnum,
    8813              :                                    /*issue_conversion_warnings=*/false,
    8814              :                                    /*c_cast_p=*/false, /*nested_p=*/true,
    8815              :                                    complain);
    8816         1565 :               if (t->bad_p)
    8817            0 :                 complained = 1;
    8818              :               break;
    8819              :             }
    8820         1642 :           else if (t->kind == ck_ambig)
    8821            0 :             return convert_like (t, expr, fn, argnum,
    8822              :                                  /*issue_conversion_warnings=*/false,
    8823              :                                  /*c_cast_p=*/false, /*nested_p=*/true,
    8824            0 :                                  complain);
    8825         1642 :           else if (t->kind == ck_identity)
    8826              :             break;
    8827              :         }
    8828         1626 :       if (!complained && stub_object_p)
    8829              :         {
    8830              :           /* An error diagnosed within a trait, don't give extra labels.  */
    8831           12 :           error_at (loc, "invalid conversion from %qH to %qI",
    8832            6 :                     TREE_TYPE (expr), totype);
    8833            6 :           complained = 1;
    8834              :         }
    8835         1620 :       else if (!complained && expr != error_mark_node)
    8836              :         {
    8837         1435 :           range_label_for_type_mismatch label (TREE_TYPE (expr), totype);
    8838         1435 :           gcc_rich_location richloc (loc, &label, highlight_colors::percent_h);
    8839         1435 :           complained = permerror (&richloc,
    8840              :                                   "invalid conversion from %qH to %qI",
    8841         1435 :                                   TREE_TYPE (expr), totype);
    8842         1435 :           if (complained)
    8843         1380 :             maybe_emit_indirection_note (loc, expr, totype);
    8844         1435 :         }
    8845         1626 :       if (convs->kind == ck_ref_bind)
    8846           21 :         expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
    8847              :                                      LOOKUP_NORMAL, NULL_TREE,
    8848              :                                      complain);
    8849              :       else
    8850         1605 :         expr = cp_convert (totype, expr, complain);
    8851         1626 :       if (complained == 1)
    8852         1548 :         maybe_inform_about_fndecl_for_bogus_argument_init
    8853         1548 :           (fn, argnum, highlight_colors::percent_i);
    8854         1626 :       return expr;
    8855         1626 :     }
    8856              : 
    8857   1046136444 :   if (issue_conversion_warnings && (complain & tf_warning))
    8858    513819770 :     conversion_null_warnings (totype, expr, fn, argnum);
    8859              : 
    8860   1046136444 :   switch (convs->kind)
    8861              :     {
    8862      6190794 :     case ck_user:
    8863      6190794 :       {
    8864      6190794 :         struct z_candidate *cand = convs->cand;
    8865              : 
    8866      6190794 :         if (cand == NULL)
    8867              :           /* We chose the surrogate function from add_conv_candidate, now we
    8868              :              actually need to build the conversion.  */
    8869           56 :           cand = build_user_type_conversion_1 (totype, expr,
    8870              :                                                LOOKUP_NO_CONVERSION, complain);
    8871              : 
    8872      6190794 :         tree convfn = cand->fn;
    8873              : 
    8874              :         /* When converting from an init list we consider explicit
    8875              :            constructors, but actually trying to call one is an error.  */
    8876      6654461 :         if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
    8877         9705 :             && BRACE_ENCLOSED_INITIALIZER_P (expr)
    8878              :             /* Unless this is for direct-list-initialization.  */
    8879         9702 :             && (!CONSTRUCTOR_IS_DIRECT_INIT (expr) || convs->need_temporary_p)
    8880              :             /* And in C++98 a default constructor can't be explicit.  */
    8881      6191033 :             && cxx_dialect >= cxx11)
    8882              :           {
    8883          237 :             if (!(complain & tf_error))
    8884           53 :               return error_mark_node;
    8885          184 :             location_t loc = location_of (expr);
    8886          184 :             if (CONSTRUCTOR_NELTS (expr) == 0
    8887          184 :                 && FUNCTION_FIRST_USER_PARMTYPE (convfn) != void_list_node)
    8888              :               {
    8889            9 :                 auto_diagnostic_group d;
    8890            9 :                 if (pedwarn (loc, 0, "converting to %qT from initializer list "
    8891              :                              "would use explicit constructor %qD",
    8892              :                              totype, convfn))
    8893              :                   {
    8894            9 :                     inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8895              :                             convfn);
    8896            9 :                     inform (loc, "in C++11 and above a default constructor "
    8897              :                             "can be explicit");
    8898              :                   }
    8899            9 :               }
    8900              :             else
    8901              :               {
    8902          175 :                 auto_diagnostic_group d;
    8903          175 :                 error ("converting to %qT from initializer list would use "
    8904              :                        "explicit constructor %qD", totype, convfn);
    8905          175 :                 inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8906              :                         convfn);
    8907          175 :               }
    8908              :           }
    8909              : 
    8910              :         /* If we're initializing from {}, it's value-initialization.  */
    8911       831303 :         if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8912       831295 :             && CONSTRUCTOR_NELTS (expr) == 0
    8913       142430 :             && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)
    8914      6333144 :             && !processing_template_decl)
    8915              :           {
    8916       142403 :             if (abstract_virtuals_error (NULL_TREE, totype, complain))
    8917           15 :               return error_mark_node;
    8918       142388 :             expr = build_value_init (totype, complain);
    8919       142388 :             expr = get_target_expr (expr, complain);
    8920       142388 :             if (expr != error_mark_node)
    8921       142248 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8922       142388 :             return expr;
    8923              :           }
    8924              : 
    8925              :         /* We don't know here whether EXPR is being used as an lvalue or
    8926              :            rvalue, but we know it's read.  */
    8927      6048338 :         mark_exp_read (expr);
    8928              : 
    8929              :         /* Give the conversion call the location of EXPR rather than the
    8930              :            location of the context that caused the conversion.  */
    8931      6048338 :         iloc_sentinel ils (loc);
    8932              : 
    8933              :         /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow
    8934              :            any more UDCs.  */
    8935      6048338 :         expr = build_over_call (cand, LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
    8936              :                                 complain);
    8937              : 
    8938              :         /* If this is a constructor or a function returning an aggr type,
    8939              :            we need to build up a TARGET_EXPR.  */
    8940     12096676 :         if (DECL_CONSTRUCTOR_P (convfn))
    8941              :           {
    8942      2706242 :             expr = build_cplus_new (totype, expr, complain);
    8943              : 
    8944              :             /* Remember that this was list-initialization.  */
    8945      2706242 :             if (convs->check_narrowing && expr != error_mark_node)
    8946       712476 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8947              :           }
    8948              : 
    8949      6048338 :         return expr;
    8950      6048338 :       }
    8951    736840876 :     case ck_identity:
    8952    736840876 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    8953              :         {
    8954      1088719 :           int nelts = CONSTRUCTOR_NELTS (expr);
    8955       169151 :           if (nelts == 0)
    8956       919568 :             expr = build_value_init (totype, complain);
    8957       169151 :           else if (nelts == 1)
    8958       169151 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    8959              :           else
    8960            0 :             gcc_unreachable ();
    8961              :         }
    8962    736840876 :       expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p,
    8963              :                        /*read_p=*/true, UNKNOWN_LOCATION,
    8964              :                        /*reject_builtin=*/true);
    8965              : 
    8966    736840876 :       if (type_unknown_p (expr))
    8967        17480 :         expr = instantiate_type (totype, expr, complain);
    8968    736840876 :       if (!nested_p && TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    8969        62194 :         expr = cp_convert (totype, TREE_OPERAND (expr, 0), complain);
    8970    736840876 :       if (expr == null_node
    8971    736840876 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype))
    8972              :         /* If __null has been converted to an integer type, we do not want to
    8973              :            continue to warn about uses of EXPR as an integer, rather than as a
    8974              :            pointer.  */
    8975       146009 :         expr = build_int_cst (totype, 0);
    8976    736840876 :       return maybe_adjust_type_name (totype, expr, convs->kind);
    8977           53 :     case ck_ambig:
    8978              :       /* We leave bad_p off ck_ambig because overload resolution considers
    8979              :          it valid, it just fails when we try to perform it.  So we need to
    8980              :          check complain here, too.  */
    8981           53 :       if (complain & tf_error)
    8982              :         {
    8983              :           /* Call build_user_type_conversion again for the error.  */
    8984           53 :           auto_diagnostic_group d;
    8985            3 :           int flags = (convs->need_temporary_p
    8986           53 :                        ? LOOKUP_IMPLICIT : LOOKUP_NORMAL);
    8987           53 :           build_user_type_conversion (totype, convs->u.expr, flags, complain);
    8988           53 :           gcc_assert (seen_error ());
    8989           53 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    8990           53 :         }
    8991           53 :       return error_mark_node;
    8992              : 
    8993        15730 :     case ck_list:
    8994        15730 :       {
    8995              :         /* Conversion to std::initializer_list<T>.  */
    8996        15730 :         tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (totype), 0);
    8997        15730 :         unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (expr);
    8998        15730 :         tree array;
    8999              : 
    9000        15730 :         if (tree init = maybe_init_list_as_array (elttype, expr))
    9001              :           {
    9002          132 :             elttype
    9003          132 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    9004              :                                                    | TYPE_QUAL_CONST));
    9005          132 :             tree index_type = TYPE_DOMAIN (TREE_TYPE (init));
    9006          132 :             array = build_cplus_array_type (elttype, index_type);
    9007          132 :             len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (index_type)) + 1;
    9008          132 :             array = build_vec_init_expr (array, init, complain);
    9009          132 :             array = get_target_expr (array);
    9010          132 :             array = cp_build_addr_expr (array, complain);
    9011              :           }
    9012        15598 :         else if (len)
    9013              :           {
    9014        14947 :             tree val;
    9015        14947 :             unsigned ix;
    9016        14947 :             tree new_ctor = build_constructor (init_list_type_node, NULL);
    9017              : 
    9018              :             /* Convert all the elements.  */
    9019       121975 :             FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val)
    9020              :               {
    9021       107043 :                 if (TREE_CODE (val) == RAW_DATA_CST)
    9022              :                   {
    9023              :                     /* For conversion to initializer_list<unsigned char> or
    9024              :                        initializer_list<char> or initializer_list<signed char>
    9025              :                        we can optimize and keep RAW_DATA_CST with adjusted
    9026              :                        type if we report narrowing errors if needed, for
    9027              :                        others this converts each element separately.  */
    9028           48 :                     if (convs->u.list[ix]->kind == ck_std)
    9029              :                       {
    9030           18 :                         tree et = convs->u.list[ix]->type;
    9031           18 :                         conversion *next = next_conversion (convs->u.list[ix]);
    9032           18 :                         gcc_assert (et
    9033              :                                     && (TREE_CODE (et) == INTEGER_TYPE
    9034              :                                         || is_byte_access_type (et))
    9035              :                                     && TYPE_PRECISION (et) == CHAR_BIT
    9036              :                                     && next
    9037              :                                     && next->kind == ck_identity);
    9038           18 :                         if (!TYPE_UNSIGNED (et)
    9039              :                             /* For RAW_DATA_CST, TREE_TYPE (val) can be
    9040              :                                either integer_type_node (when it has been
    9041              :                                created by the lexer from CPP_EMBED) or
    9042              :                                after digestion/conversion some integral
    9043              :                                type with CHAR_BIT precision.  For int with
    9044              :                                precision higher than CHAR_BIT or unsigned char
    9045              :                                diagnose narrowing conversions from
    9046              :                                that int/unsigned char to signed char if any
    9047              :                                byte has most significant bit set.  */
    9048           18 :                             && (TYPE_UNSIGNED (TREE_TYPE (val))
    9049           12 :                                 || (TYPE_PRECISION (TREE_TYPE (val))
    9050              :                                     > CHAR_BIT)))
    9051         2460 :                           for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
    9052              :                             {
    9053         2454 :                               if (RAW_DATA_SCHAR_ELT (val, i) >= 0)
    9054         2448 :                                 continue;
    9055            6 :                               else if (complain & tf_error)
    9056              :                                 {
    9057            6 :                                   location_t loc
    9058            6 :                                     = cp_expr_loc_or_input_loc (val);
    9059            6 :                                   int savederrorcount = errorcount;
    9060           18 :                                   permerror_opt (loc, OPT_Wnarrowing,
    9061              :                                                  "narrowing conversion of "
    9062              :                                                  "%qd from %qH to %qI",
    9063            6 :                                                  RAW_DATA_UCHAR_ELT (val, i),
    9064            6 :                                                  TREE_TYPE (val), et);
    9065            6 :                                   if (errorcount != savederrorcount)
    9066            6 :                                     return error_mark_node;
    9067              :                                 }
    9068              :                               else
    9069            0 :                                 return error_mark_node;
    9070              :                             }
    9071           12 :                         tree sub = copy_node (val);
    9072           12 :                         TREE_TYPE (sub) = et;
    9073           12 :                         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    9074              :                                                 NULL_TREE, sub);
    9075              :                       }
    9076              :                     else
    9077              :                       {
    9078           30 :                         conversion *conv = convs->u.list[ix];
    9079           30 :                         gcc_assert (conv->kind == ck_list);
    9080        15495 :                         for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
    9081              :                           {
    9082        15465 :                             tree elt
    9083        15465 :                               = build_int_cst (TREE_TYPE (val),
    9084        15465 :                                                RAW_DATA_UCHAR_ELT (val, i));
    9085        15465 :                             tree sub
    9086        15465 :                               = convert_like (conv->u.list[i], elt,
    9087              :                                               fn, argnum, false, false,
    9088              :                                               /*nested_p=*/true, complain);
    9089        15465 :                             if (sub == error_mark_node)
    9090              :                               return sub;
    9091        15465 :                             if (!check_narrowing (TREE_TYPE (sub), elt,
    9092              :                                                   complain))
    9093            0 :                               return error_mark_node;
    9094        15465 :                             tree nc = new_ctor;
    9095        15465 :                             CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (nc),
    9096              :                                                     NULL_TREE, sub);
    9097        15465 :                             if (!TREE_CONSTANT (sub))
    9098        11679 :                               TREE_CONSTANT (new_ctor) = false;
    9099              :                           }
    9100              :                       }
    9101           42 :                     len += RAW_DATA_LENGTH (val) - 1;
    9102           42 :                     continue;
    9103           42 :                   }
    9104       106995 :                 tree sub = convert_like (convs->u.list[ix], val, fn,
    9105              :                                          argnum, false, false,
    9106              :                                          /*nested_p=*/true, complain);
    9107       106995 :                 if (sub == error_mark_node)
    9108              :                   return sub;
    9109         1593 :                 if (!BRACE_ENCLOSED_INITIALIZER_P (val)
    9110       107006 :                     && !check_narrowing (TREE_TYPE (sub), val, complain))
    9111            0 :                   return error_mark_node;
    9112       106986 :                 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    9113              :                                         NULL_TREE, sub);
    9114       106986 :                 if (!TREE_CONSTANT (sub))
    9115        10709 :                   TREE_CONSTANT (new_ctor) = false;
    9116              :               }
    9117              :             /* Build up the array.  */
    9118        14932 :             elttype
    9119        14932 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    9120              :                                                    | TYPE_QUAL_CONST));
    9121        14932 :             array = build_array_of_n_type (elttype, len);
    9122        14932 :             array = finish_compound_literal (array, new_ctor, complain);
    9123              :             /* This is dubious now, should be blessed by P2752.  */
    9124        14932 :             DECL_MERGEABLE (TARGET_EXPR_SLOT (array)) = true;
    9125        14932 :             array = cp_build_addr_expr (array, complain);
    9126              :           }
    9127              :         else
    9128          651 :           array = nullptr_node;
    9129              : 
    9130        15715 :         array = cp_convert (build_pointer_type (elttype), array, complain);
    9131        15715 :         if (array == error_mark_node)
    9132              :           return error_mark_node;
    9133              : 
    9134              :         /* Build up the initializer_list object.  Note: fail gracefully
    9135              :            if the object cannot be completed because, for example, no
    9136              :            definition is provided (c++/80956).  */
    9137        15715 :         totype = complete_type_or_maybe_complain (totype, NULL_TREE, complain);
    9138        15715 :         if (!totype)
    9139            0 :           return error_mark_node;
    9140        15715 :         tree field = next_aggregate_field (TYPE_FIELDS (totype));
    9141        15715 :         vec<constructor_elt, va_gc> *vec = NULL;
    9142        15715 :         CONSTRUCTOR_APPEND_ELT (vec, field, array);
    9143        15715 :         field = next_aggregate_field (DECL_CHAIN (field));
    9144        15715 :         CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len));
    9145        15715 :         tree new_ctor = build_constructor (totype, vec);
    9146        15715 :         return get_target_expr (new_ctor, complain);
    9147              :       }
    9148              : 
    9149      1220279 :     case ck_aggr:
    9150      1220279 :       if (TREE_CODE (totype) == COMPLEX_TYPE)
    9151              :         {
    9152        27391 :           tree real = CONSTRUCTOR_ELT (expr, 0)->value;
    9153        27391 :           tree imag = CONSTRUCTOR_ELT (expr, 1)->value;
    9154        27391 :           real = perform_implicit_conversion (TREE_TYPE (totype),
    9155              :                                               real, complain);
    9156        27391 :           imag = perform_implicit_conversion (TREE_TYPE (totype),
    9157              :                                               imag, complain);
    9158        27391 :           expr = build2 (COMPLEX_EXPR, totype, real, imag);
    9159        27391 :           return expr;
    9160              :         }
    9161      1192888 :       expr = reshape_init (totype, expr, complain);
    9162      1192888 :       expr = get_target_expr (digest_init (totype, expr, complain),
    9163              :                                      complain);
    9164      1192888 :       if (expr != error_mark_node)
    9165      1192877 :         TARGET_EXPR_LIST_INIT_P (expr) = true;
    9166              :       return expr;
    9167              : 
    9168    301868712 :     default:
    9169    301868712 :       break;
    9170    301868712 :     };
    9171              : 
    9172    301868712 :   conversion *nc = next_conversion (convs);
    9173    301868712 :   if (convs->kind == ck_ref_bind && nc->kind == ck_qual
    9174         7416 :       && !convs->need_temporary_p)
    9175              :     /* direct_reference_binding might have inserted a ck_qual under
    9176              :        this ck_ref_bind for the benefit of conversion sequence ranking.
    9177              :        Don't actually perform that conversion.  */
    9178         5559 :     nc = next_conversion (nc);
    9179              : 
    9180    301868712 :   expr = convert_like (nc, expr, fn, argnum,
    9181              :                        convs->kind == ck_ref_bind
    9182    301868712 :                        ? issue_conversion_warnings : false,
    9183              :                        c_cast_p, /*nested_p=*/true, complain & ~tf_no_cleanup);
    9184    301868712 :   if (expr == error_mark_node)
    9185              :     return error_mark_node;
    9186              : 
    9187    301868189 :   switch (convs->kind)
    9188              :     {
    9189    134377614 :     case ck_rvalue:
    9190    134377614 :       expr = decay_conversion (expr, complain);
    9191    134377614 :       if (expr == error_mark_node)
    9192              :         {
    9193           15 :           if (complain & tf_error)
    9194              :             {
    9195           12 :               auto_diagnostic_group d;
    9196           12 :               maybe_print_user_conv_context (convs);
    9197           12 :               maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9198           12 :             }
    9199           15 :           return error_mark_node;
    9200              :         }
    9201              : 
    9202    134377599 :       if ((complain & tf_warning) && fn
    9203     38690066 :           && warn_suggest_attribute_format)
    9204              :         {
    9205          706 :           tree rhstype = TREE_TYPE (expr);
    9206          706 :           const enum tree_code coder = TREE_CODE (rhstype);
    9207          706 :           const enum tree_code codel = TREE_CODE (totype);
    9208          706 :           if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    9209          250 :               && coder == codel
    9210          956 :               && check_missing_format_attribute (totype, rhstype))
    9211            6 :             warning (OPT_Wsuggest_attribute_format,
    9212              :                      "argument of function call might be a candidate "
    9213              :                      "for a format attribute");
    9214              :         }
    9215              : 
    9216    134377599 :       if (! MAYBE_CLASS_TYPE_P (totype))
    9217    121478018 :         return maybe_adjust_type_name (totype, expr, convs->kind);
    9218              : 
    9219              :       /* Don't introduce copies when passing arguments along to the inherited
    9220              :          constructor.  */
    9221     12899581 :       if (current_function_decl
    9222     10200236 :           && flag_new_inheriting_ctors
    9223     33299573 :           && DECL_INHERITED_CTOR (current_function_decl))
    9224              :         return expr;
    9225              : 
    9226     12895559 :       if (TREE_CODE (expr) == TARGET_EXPR
    9227     12895559 :           && TARGET_EXPR_LIST_INIT_P (expr))
    9228              :         /* Copy-list-initialization doesn't actually involve a copy.  */
    9229              :         return expr;
    9230              : 
    9231              :       /* Fall through.  */
    9232     14833015 :     case ck_base:
    9233     14833015 :       if (convs->kind == ck_base && !convs->need_temporary_p)
    9234              :         {
    9235              :           /* We are going to bind a reference directly to a base-class
    9236              :              subobject of EXPR.  */
    9237              :           /* Build an expression for `*((base*) &expr)'.  */
    9238      1723279 :           expr = convert_to_base (expr, totype,
    9239      1723279 :                                   !c_cast_p, /*nonnull=*/true, complain);
    9240      1723279 :           return expr;
    9241              :         }
    9242              : 
    9243              :       /* Copy-initialization where the cv-unqualified version of the source
    9244              :          type is the same class as, or a derived class of, the class of the
    9245              :          destination [is treated as direct-initialization].  [dcl.init] */
    9246     13109736 :       flags = LOOKUP_NORMAL;
    9247              :       /* This conversion is being done in the context of a user-defined
    9248              :          conversion (i.e. the second step of copy-initialization), so
    9249              :          don't allow any more.  */
    9250     13109736 :       if (convs->user_conv_p)
    9251       248874 :         flags |= LOOKUP_NO_CONVERSION;
    9252              :       /* We might be performing a conversion of the argument
    9253              :          to the user-defined conversion, i.e., not a conversion of the
    9254              :          result of the user-defined conversion.  In which case we skip
    9255              :          explicit constructors.  */
    9256     13109736 :       if (convs->copy_init_p)
    9257     12851166 :         flags |= LOOKUP_ONLYCONVERTING;
    9258     13109736 :       expr = build_temp (expr, totype, flags, &diag_kind, complain);
    9259     13109736 :       if (diag_kind != diagnostics::kind::unspecified && complain)
    9260              :         {
    9261           78 :           auto_diagnostic_group d;
    9262           78 :           maybe_print_user_conv_context (convs);
    9263           78 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9264           78 :         }
    9265              : 
    9266     13109736 :       return build_cplus_new (totype, expr, complain);
    9267              : 
    9268     56976554 :     case ck_ref_bind:
    9269     56976554 :       {
    9270     56976554 :         tree ref_type = totype;
    9271              : 
    9272     56976554 :         if (convs->bad_p && !next_conversion (convs)->bad_p)
    9273              :           {
    9274         5145 :             tree extype = TREE_TYPE (expr);
    9275         5145 :             auto_diagnostic_group d;
    9276         5145 :             if (TYPE_REF_IS_RVALUE (ref_type)
    9277         5145 :                 && lvalue_p (expr))
    9278         1638 :               error_at (loc, "cannot bind rvalue reference of type %qH to "
    9279              :                         "lvalue of type %qI", totype, extype);
    9280         6168 :             else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr)
    9281         4987 :                      && !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type)))
    9282              :               {
    9283         1231 :                 conversion *next = next_conversion (convs);
    9284         1231 :                 if (next->kind == ck_std)
    9285              :                   {
    9286           59 :                     next = next_conversion (next);
    9287           59 :                     error_at (loc, "cannot bind non-const lvalue reference of "
    9288              :                               "type %qH to a value of type %qI",
    9289              :                               totype, next->type);
    9290              :                   }
    9291         1172 :                 else if (!CP_TYPE_CONST_P (TREE_TYPE (ref_type)))
    9292          831 :                   error_at (loc, "cannot bind non-const lvalue reference of "
    9293              :                             "type %qH to an rvalue of type %qI", totype, extype);
    9294              :                 else // extype is volatile
    9295          341 :                   error_at (loc, "cannot bind lvalue reference of type "
    9296              :                             "%qH to an rvalue of type %qI", totype,
    9297              :                             extype);
    9298              :               }
    9299         2276 :             else if (!reference_compatible_p (TREE_TYPE (totype), extype))
    9300              :               {
    9301              :                 /* If we're converting from T[] to T[N], don't talk
    9302              :                    about discarding qualifiers.  (Converting from T[N] to
    9303              :                    T[] is allowed by P0388R4.)  */
    9304         2276 :                 if (TREE_CODE (extype) == ARRAY_TYPE
    9305           27 :                     && TYPE_DOMAIN (extype) == NULL_TREE
    9306           15 :                     && TREE_CODE (TREE_TYPE (totype)) == ARRAY_TYPE
    9307         2291 :                     && TYPE_DOMAIN (TREE_TYPE (totype)) != NULL_TREE)
    9308           15 :                   error_at (loc, "cannot bind reference of type %qH to %qI "
    9309              :                             "due to different array bounds", totype, extype);
    9310              :                 else
    9311         2261 :                   error_at (loc, "binding reference of type %qH to %qI "
    9312              :                             "discards qualifiers", totype, extype);
    9313              :               }
    9314              :             else
    9315            0 :               gcc_unreachable ();
    9316         5145 :             maybe_print_user_conv_context (convs);
    9317         5145 :             maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9318              : 
    9319         5145 :             return error_mark_node;
    9320         5145 :           }
    9321     56971409 :         else if (complain & tf_warning)
    9322     35273178 :           maybe_warn_array_conv (loc, convs, expr);
    9323              : 
    9324              :         /* If necessary, create a temporary.
    9325              : 
    9326              :            VA_ARG_EXPR and CONSTRUCTOR expressions are special cases
    9327              :            that need temporaries, even when their types are reference
    9328              :            compatible with the type of reference being bound, so the
    9329              :            upcoming call to cp_build_addr_expr doesn't fail.  */
    9330     56971409 :         if (convs->need_temporary_p
    9331     54590450 :             || TREE_CODE (expr) == CONSTRUCTOR
    9332     54590246 :             || TREE_CODE (expr) == VA_ARG_EXPR)
    9333              :           {
    9334              :             /* Otherwise, a temporary of type "cv1 T1" is created and
    9335              :                initialized from the initializer expression using the rules
    9336              :                for a non-reference copy-initialization (8.5).  */
    9337              : 
    9338      2381163 :             tree type = TREE_TYPE (ref_type);
    9339      2381163 :             cp_lvalue_kind lvalue = lvalue_kind (expr);
    9340              : 
    9341      2381163 :             gcc_assert (similar_type_p (type, next_conversion (convs)->type));
    9342      2381163 :             if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
    9343      3221319 :                 && !TYPE_REF_IS_RVALUE (ref_type))
    9344              :               {
    9345              :                 /* If the reference is volatile or non-const, we
    9346              :                    cannot create a temporary.  */
    9347          105 :                 if (complain & tf_error)
    9348              :                   {
    9349          103 :                     if (lvalue & clk_bitfield)
    9350           30 :                       error_at (loc, "cannot bind bit-field %qE to %qT",
    9351              :                                 expr, ref_type);
    9352           73 :                     else if (lvalue & clk_packed)
    9353            9 :                       error_at (loc, "cannot bind packed field %qE to %qT",
    9354              :                                 expr, ref_type);
    9355              :                     else
    9356           64 :                       error_at (loc, "cannot bind rvalue %qE to %qT",
    9357              :                                 expr, ref_type);
    9358              :                   }
    9359          105 :                 return error_mark_node;
    9360              :               }
    9361              :             /* If the source is a packed field, and we must use a copy
    9362              :                constructor, then building the target expr will require
    9363              :                binding the field to the reference parameter to the
    9364              :                copy constructor, and we'll end up with an infinite
    9365              :                loop.  If we can use a bitwise copy, then we'll be
    9366              :                OK.  */
    9367      2381058 :             if ((lvalue & clk_packed)
    9368           20 :                 && CLASS_TYPE_P (type)
    9369      2381075 :                 && type_has_nontrivial_copy_init (type))
    9370              :               {
    9371            6 :                 error_at (loc, "cannot bind packed field %qE to %qT",
    9372              :                           expr, ref_type);
    9373            6 :                 return error_mark_node;
    9374              :               }
    9375      2381052 :             if (lvalue & clk_bitfield)
    9376              :               {
    9377           24 :                 expr = convert_bitfield_to_declared_type (expr);
    9378           24 :                 expr = fold_convert (type, expr);
    9379              :               }
    9380              : 
    9381              :             /* Creating &TARGET_EXPR<> in a template would break when
    9382              :                tsubsting the expression, so use an IMPLICIT_CONV_EXPR
    9383              :                instead.  This can happen even when there's no class
    9384              :                involved, e.g., when converting an integer to a reference
    9385              :                type.  */
    9386      2381052 :             if (processing_template_decl)
    9387         9276 :               return build1 (IMPLICIT_CONV_EXPR, totype, expr);
    9388      2371776 :             expr = build_target_expr_with_type (expr, type, complain);
    9389              :           }
    9390              : 
    9391              :         /* Take the address of the thing to which we will bind the
    9392              :            reference.  */
    9393     56962022 :         expr = cp_build_addr_expr (expr, complain);
    9394     56962022 :         if (expr == error_mark_node)
    9395              :           return error_mark_node;
    9396              : 
    9397              :         /* Convert it to a pointer to the type referred to by the
    9398              :            reference.  This will adjust the pointer if a derived to
    9399              :            base conversion is being performed.  */
    9400     56962022 :         expr = cp_convert (build_pointer_type (TREE_TYPE (ref_type)),
    9401              :                            expr, complain);
    9402              :         /* Convert the pointer to the desired reference type.  */
    9403     56962022 :         return build_nop (ref_type, expr);
    9404              :       }
    9405              : 
    9406      2693720 :     case ck_lvalue:
    9407      2693720 :       return decay_conversion (expr, complain);
    9408              : 
    9409       226884 :     case ck_fnptr:
    9410              :       /* ??? Should the address of a transaction-safe pointer point to the TM
    9411              :         clone, and this conversion look up the primary function?  */
    9412       226884 :       return build_nop (totype, expr);
    9413              : 
    9414      1533853 :     case ck_qual:
    9415              :       /* Warn about deprecated conversion if appropriate.  */
    9416      1533853 :       if (complain & tf_warning)
    9417              :         {
    9418      1347681 :           string_conv_p (totype, expr, 1);
    9419      1347681 :           maybe_warn_array_conv (loc, convs, expr);
    9420              :         }
    9421              :       break;
    9422              : 
    9423      2870210 :     case ck_ptr:
    9424      2870210 :       if (convs->base_p)
    9425       207290 :         expr = convert_to_base (expr, totype, !c_cast_p,
    9426              :                                 /*nonnull=*/false, complain);
    9427      2870210 :       return build_nop (totype, expr);
    9428              : 
    9429        27664 :     case ck_pmem:
    9430        27664 :       return convert_ptrmem (totype, expr, /*allow_inverse_p=*/false,
    9431        27664 :                              c_cast_p, complain);
    9432              : 
    9433              :     default:
    9434              :       break;
    9435              :     }
    9436              : 
    9437    102731604 :   if (convs->check_narrowing
    9438    156417719 :       && !check_narrowing (totype, expr, complain,
    9439     53686115 :                            convs->check_narrowing_const_only))
    9440          468 :     return error_mark_node;
    9441              : 
    9442    205462272 :   warning_sentinel w (warn_zero_as_null_pointer_constant);
    9443    102731136 :   if (issue_conversion_warnings)
    9444     80720070 :     expr = cp_convert_and_check (totype, expr, complain);
    9445              :   else
    9446              :     {
    9447     22011066 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9448           39 :         expr = TREE_OPERAND (expr, 0);
    9449     22011066 :       expr = cp_convert (totype, expr, complain);
    9450              :     }
    9451              : 
    9452    102731136 :   return expr;
    9453              : }
    9454              : 
    9455              : /* Return true if converting FROM to TO is unsafe in a template.  */
    9456              : 
    9457              : static bool
    9458      1882859 : conv_unsafe_in_template_p (tree to, tree from)
    9459              : {
    9460              :   /* Converting classes involves TARGET_EXPR.  */
    9461      1882859 :   if (CLASS_TYPE_P (to) || CLASS_TYPE_P (from))
    9462              :     return true;
    9463              : 
    9464              :   /* Converting real to integer produces FIX_TRUNC_EXPR which tsubst
    9465              :      doesn't handle.  */
    9466      1468883 :   if (SCALAR_FLOAT_TYPE_P (from) && INTEGRAL_OR_ENUMERATION_TYPE_P (to))
    9467              :     return true;
    9468              : 
    9469              :   /* Converting integer to real isn't a trivial conversion, either.  */
    9470      1468880 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (from) && SCALAR_FLOAT_TYPE_P (to))
    9471            3 :     return true;
    9472              : 
    9473              :   return false;
    9474              : }
    9475              : 
    9476              : /* Wrapper for convert_like_internal that handles creating
    9477              :    IMPLICIT_CONV_EXPR.  */
    9478              : 
    9479              : static tree
    9480   1046595022 : convert_like (conversion *convs, tree expr, tree fn, int argnum,
    9481              :               bool issue_conversion_warnings, bool c_cast_p, bool nested_p,
    9482              :               tsubst_flags_t complain)
    9483              : {
    9484              :   /* Creating &TARGET_EXPR<> in a template breaks when substituting,
    9485              :      and creating a CALL_EXPR in a template breaks in finish_call_expr
    9486              :      so use an IMPLICIT_CONV_EXPR for this conversion.  We would have
    9487              :      created such codes e.g. when calling a user-defined conversion
    9488              :      function.  */
    9489   1046595022 :   tree conv_expr = NULL_TREE;
    9490   1046595022 :   if (processing_template_decl
    9491    106999577 :       && convs->kind != ck_identity
    9492   1048477881 :       && conv_unsafe_in_template_p (convs->type, TREE_TYPE (expr)))
    9493              :     {
    9494       413982 :       conv_expr = build1 (IMPLICIT_CONV_EXPR, convs->type, expr);
    9495       413982 :       if (convs->kind != ck_ref_bind)
    9496        45770 :         conv_expr = convert_from_reference (conv_expr);
    9497       413982 :       if (!convs->bad_p)
    9498              :         return conv_expr;
    9499              :       /* Do the normal processing to give the bad_p errors.  But we still
    9500              :          need to return the IMPLICIT_CONV_EXPR, unless we're returning
    9501              :          error_mark_node.  */
    9502              :     }
    9503   1046181049 :   expr = convert_like_internal (convs, expr, fn, argnum,
    9504              :                                 issue_conversion_warnings, c_cast_p,
    9505              :                                 nested_p, complain);
    9506   1046181049 :   if (expr == error_mark_node)
    9507              :     return error_mark_node;
    9508   1046130556 :   return conv_expr ? conv_expr : expr;
    9509              : }
    9510              : 
    9511              : /* Convenience wrapper for convert_like.  */
    9512              : 
    9513              : static inline tree
    9514    580813016 : convert_like (conversion *convs, tree expr, tsubst_flags_t complain)
    9515              : {
    9516    580813016 :   return convert_like (convs, expr, NULL_TREE, 0,
    9517              :                        /*issue_conversion_warnings=*/true,
    9518    580813016 :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9519              : }
    9520              : 
    9521              : /* Convenience wrapper for convert_like.  */
    9522              : 
    9523              : static inline tree
    9524    125513650 : convert_like_with_context (conversion *convs, tree expr, tree fn, int argnum,
    9525              :                            tsubst_flags_t complain)
    9526              : {
    9527            0 :   return convert_like (convs, expr, fn, argnum,
    9528              :                        /*issue_conversion_warnings=*/true,
    9529              :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9530              : }
    9531              : 
    9532              : /* ARG is being passed to a varargs function.  Perform any conversions
    9533              :    required.  Return the converted value.  */
    9534              : 
    9535              : tree
    9536      1345528 : convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
    9537              : {
    9538      1345528 :   tree arg_type = TREE_TYPE (arg);
    9539      1345528 :   location_t loc = cp_expr_loc_or_input_loc (arg);
    9540              : 
    9541              :   /* [expr.call]
    9542              : 
    9543              :      If the argument has integral or enumeration type that is subject
    9544              :      to the integral promotions (_conv.prom_), or a floating-point
    9545              :      type that is subject to the floating-point promotion
    9546              :      (_conv.fpprom_), the value of the argument is converted to the
    9547              :      promoted type before the call.  */
    9548      1345528 :   if (SCALAR_FLOAT_TYPE_P (arg_type)
    9549        47297 :       && (TYPE_PRECISION (arg_type)
    9550        47297 :           < TYPE_PRECISION (double_type_node))
    9551        11585 :       && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (arg_type))
    9552      1356435 :       && !extended_float_type_p (arg_type))
    9553              :     {
    9554        10901 :       if ((complain & tf_warning)
    9555        10898 :           && warn_double_promotion && !c_inhibit_evaluation_warnings)
    9556            3 :         warning_at (loc, OPT_Wdouble_promotion,
    9557              :                     "implicit conversion from %qH to %qI when passing "
    9558              :                     "argument to function",
    9559              :                     arg_type, double_type_node);
    9560        10901 :       if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    9561            3 :         arg = TREE_OPERAND (arg, 0);
    9562        10901 :       arg = mark_rvalue_use (arg);
    9563        10901 :       arg = convert_to_real_nofold (double_type_node, arg);
    9564              :     }
    9565      1334627 :   else if (NULLPTR_TYPE_P (arg_type))
    9566              :     {
    9567           80 :       arg = mark_rvalue_use (arg);
    9568           80 :       if (TREE_SIDE_EFFECTS (arg))
    9569              :         {
    9570            6 :           warning_sentinel w(warn_unused_result);
    9571            6 :           arg = cp_build_compound_expr (arg, null_pointer_node, complain);
    9572            6 :         }
    9573              :       else
    9574           74 :         arg = null_pointer_node;
    9575              :     }
    9576      1334547 :   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type))
    9577              :     {
    9578       880044 :       if (SCOPED_ENUM_P (arg_type))
    9579              :         {
    9580           60 :           tree prom = cp_convert (ENUM_UNDERLYING_TYPE (arg_type), arg,
    9581              :                                   complain);
    9582           60 :           prom = cp_perform_integral_promotions (prom, complain);
    9583          117 :           if (abi_version_crosses (6)
    9584           30 :               && TYPE_MODE (TREE_TYPE (prom)) != TYPE_MODE (arg_type)
    9585           90 :               && (complain & tf_warning))
    9586           60 :             warning_at (loc, OPT_Wabi, "scoped enum %qT passed through %<...%>"
    9587              :                         " as %qT before %<-fabi-version=6%>, %qT after",
    9588              :                         arg_type,
    9589           30 :                         TREE_TYPE (prom), ENUM_UNDERLYING_TYPE (arg_type));
    9590           60 :           if (!abi_version_at_least (6))
    9591      1345528 :             arg = prom;
    9592              :         }
    9593              :       else
    9594       879984 :         arg = cp_perform_integral_promotions (arg, complain);
    9595              :     }
    9596              :   else
    9597              :     /* [expr.call]
    9598              : 
    9599              :        The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
    9600              :        standard conversions are performed.  */
    9601       454503 :     arg = decay_conversion (arg, complain);
    9602              : 
    9603      1345528 :   arg = require_complete_type (arg, complain);
    9604      1345528 :   arg_type = TREE_TYPE (arg);
    9605              : 
    9606      1345528 :   if (arg != error_mark_node
    9607              :       /* In a template (or ill-formed code), we can have an incomplete type
    9608              :          even after require_complete_type, in which case we don't know
    9609              :          whether it has trivial copy or not.  */
    9610      1345516 :       && COMPLETE_TYPE_P (arg_type)
    9611      2691044 :       && !cp_unevaluated_operand)
    9612              :     {
    9613              :       /* [expr.call] 5.2.2/7:
    9614              :          Passing a potentially-evaluated argument of class type (Clause 9)
    9615              :          with a non-trivial copy constructor or a non-trivial destructor
    9616              :          with no corresponding parameter is conditionally-supported, with
    9617              :          implementation-defined semantics.
    9618              : 
    9619              :          We support it as pass-by-invisible-reference, just like a normal
    9620              :          value parameter.
    9621              : 
    9622              :          If the call appears in the context of a sizeof expression,
    9623              :          it is not potentially-evaluated.  */
    9624       641905 :       if (type_has_nontrivial_copy_init (arg_type)
    9625       641905 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))
    9626              :         {
    9627           37 :           arg = force_rvalue (arg, complain);
    9628           37 :           if (complain & tf_warning)
    9629           37 :             warning (OPT_Wconditionally_supported,
    9630              :                      "passing objects of non-trivially-copyable "
    9631              :                      "type %q#T through %<...%> is conditionally supported",
    9632              :                      arg_type);
    9633           37 :           return build1 (ADDR_EXPR, build_reference_type (arg_type), arg);
    9634              :         }
    9635              :       /* Build up a real lvalue-to-rvalue conversion in case the
    9636              :          copy constructor is trivial but not callable.  */
    9637       641868 :       else if (CLASS_TYPE_P (arg_type))
    9638        44150 :         force_rvalue (arg, complain);
    9639              : 
    9640              :     }
    9641              : 
    9642              :   return arg;
    9643              : }
    9644              : 
    9645              : /* va_arg (EXPR, TYPE) is a builtin. Make sure it is not abused.  */
    9646              : 
    9647              : tree
    9648        31298 : build_x_va_arg (location_t loc, tree expr, tree type)
    9649              : {
    9650        31298 :   if (processing_template_decl)
    9651              :     {
    9652           39 :       tree r = build_min (VA_ARG_EXPR, type, expr);
    9653           39 :       SET_EXPR_LOCATION (r, loc);
    9654           39 :       return r;
    9655              :     }
    9656              : 
    9657        31259 :   type = complete_type_or_else (type, NULL_TREE);
    9658              : 
    9659        31259 :   if (expr == error_mark_node || !type)
    9660              :     return error_mark_node;
    9661              : 
    9662        31238 :   expr = mark_lvalue_use (expr);
    9663              : 
    9664        31238 :   if (TYPE_REF_P (type))
    9665              :     {
    9666            6 :       error ("cannot receive reference type %qT through %<...%>", type);
    9667            6 :       return error_mark_node;
    9668              :     }
    9669              : 
    9670        31232 :   if (type_has_nontrivial_copy_init (type)
    9671        31232 :       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    9672              :     {
    9673              :       /* conditionally-supported behavior [expr.call] 5.2.2/7.  Let's treat
    9674              :          it as pass by invisible reference.  */
    9675           12 :       warning_at (loc, OPT_Wconditionally_supported,
    9676              :                  "receiving objects of non-trivially-copyable type %q#T "
    9677              :                  "through %<...%> is conditionally-supported", type);
    9678              : 
    9679           12 :       tree ref = cp_build_reference_type (type, false);
    9680           12 :       expr = build_va_arg (loc, expr, ref);
    9681           12 :       return convert_from_reference (expr);
    9682              :     }
    9683              : 
    9684        31220 :   tree ret = build_va_arg (loc, expr, type);
    9685        31220 :   if (CLASS_TYPE_P (type))
    9686              :     /* Wrap the VA_ARG_EXPR in a TARGET_EXPR now so other code doesn't need to
    9687              :        know how to handle it.  */
    9688        12094 :     ret = get_target_expr (ret);
    9689              :   return ret;
    9690              : }
    9691              : 
    9692              : /* TYPE has been given to va_arg.  Apply the default conversions which
    9693              :    would have happened when passed via ellipsis.  Return the promoted
    9694              :    type, or the passed type if there is no change.  */
    9695              : 
    9696              : tree
    9697      2561527 : cxx_type_promotes_to (tree type)
    9698              : {
    9699      2561527 :   tree promote;
    9700              : 
    9701              :   /* Perform the array-to-pointer and function-to-pointer
    9702              :      conversions.  */
    9703      2561527 :   type = type_decays_to (type);
    9704              : 
    9705      2561527 :   promote = type_promotes_to (type);
    9706      2561527 :   if (same_type_p (type, promote))
    9707      2561503 :     promote = type;
    9708              : 
    9709      2561527 :   return promote;
    9710              : }
    9711              : 
    9712              : /* ARG is a default argument expression being passed to a parameter of
    9713              :    the indicated TYPE, which is a parameter to FN.  PARMNUM is the
    9714              :    zero-based argument number.  Do any required conversions.  Return
    9715              :    the converted value.  */
    9716              : 
    9717              : static GTY(()) vec<tree, va_gc> *default_arg_context;
    9718              : void
    9719      7559036 : push_defarg_context (tree fn)
    9720      7559036 : { vec_safe_push (default_arg_context, fn); }
    9721              : 
    9722              : void
    9723      7559036 : pop_defarg_context (void)
    9724      7559036 : { default_arg_context->pop (); }
    9725              : 
    9726              : tree
    9727      1037216 : convert_default_arg (tree type, tree arg, tree fn, int parmnum,
    9728              :                      tsubst_flags_t complain)
    9729              : {
    9730      1037216 :   int i;
    9731      1037216 :   tree t;
    9732              : 
    9733              :   /* See through clones.  */
    9734      1037216 :   fn = DECL_ORIGIN (fn);
    9735              :   /* And inheriting ctors.  */
    9736      1037216 :   if (flag_new_inheriting_ctors)
    9737      1036576 :     fn = strip_inheriting_ctors (fn);
    9738              : 
    9739              :   /* Detect recursion.  */
    9740      1039955 :   FOR_EACH_VEC_SAFE_ELT (default_arg_context, i, t)
    9741         2745 :     if (t == fn)
    9742              :       {
    9743            6 :         if (complain & tf_error)
    9744            6 :           error ("recursive evaluation of default argument for %q#D", fn);
    9745            6 :         return error_mark_node;
    9746              :       }
    9747              : 
    9748              :   /* If the ARG is an unparsed default argument expression, the
    9749              :      conversion cannot be performed.  */
    9750      1037210 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
    9751              :     {
    9752           15 :       if (complain & tf_error)
    9753           15 :         error ("call to %qD uses the default argument for parameter %P, which "
    9754              :                "is not yet defined", fn, parmnum);
    9755           15 :       return error_mark_node;
    9756              :     }
    9757              : 
    9758      1037195 :   push_defarg_context (fn);
    9759              : 
    9760      1037195 :   if (fn && DECL_TEMPLATE_INFO (fn))
    9761       750467 :     arg = tsubst_default_argument (fn, parmnum, type, arg, complain);
    9762              : 
    9763              :   /* Due to:
    9764              : 
    9765              :        [dcl.fct.default]
    9766              : 
    9767              :        The names in the expression are bound, and the semantic
    9768              :        constraints are checked, at the point where the default
    9769              :        expressions appears.
    9770              : 
    9771              :      we must not perform access checks here.  */
    9772      1037195 :   push_deferring_access_checks (dk_no_check);
    9773              :   /* We must make a copy of ARG, in case subsequent processing
    9774              :      alters any part of it.  */
    9775      1037195 :   arg = break_out_target_exprs (arg, /*clear location*/true);
    9776              : 
    9777      1037195 :   arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT,
    9778              :                                     ICR_DEFAULT_ARGUMENT, fn, parmnum,
    9779              :                                     complain);
    9780      1037195 :   arg = convert_for_arg_passing (type, arg, complain);
    9781      1037195 :   pop_deferring_access_checks();
    9782              : 
    9783      1037195 :   pop_defarg_context ();
    9784              : 
    9785      1037195 :   return arg;
    9786              : }
    9787              : 
    9788              : /* Returns the type which will really be used for passing an argument of
    9789              :    type TYPE.  */
    9790              : 
    9791              : tree
    9792    638057220 : type_passed_as (tree type)
    9793              : {
    9794              :   /* Pass classes with copy ctors by invisible reference.  */
    9795    638057220 :   if (TREE_ADDRESSABLE (type))
    9796       591550 :     type = build_reference_type (type);
    9797              : 
    9798    638057220 :   return type;
    9799              : }
    9800              : 
    9801              : /* Actually perform the appropriate conversion.  */
    9802              : 
    9803              : tree
    9804    131159315 : convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain)
    9805              : {
    9806    131159315 :   tree bitfield_type;
    9807              : 
    9808              :   /* If VAL is a bitfield, then -- since it has already been converted
    9809              :      to TYPE -- it cannot have a precision greater than TYPE.
    9810              : 
    9811              :      If it has a smaller precision, we must widen it here.  For
    9812              :      example, passing "int f:3;" to a function expecting an "int" will
    9813              :      not result in any conversion before this point.
    9814              : 
    9815              :      If the precision is the same we must not risk widening.  For
    9816              :      example, the COMPONENT_REF for a 32-bit "long long" bitfield will
    9817              :      often have type "int", even though the C++ type for the field is
    9818              :      "long long".  If the value is being passed to a function
    9819              :      expecting an "int", then no conversions will be required.  But,
    9820              :      if we call convert_bitfield_to_declared_type, the bitfield will
    9821              :      be converted to "long long".  */
    9822    131159315 :   bitfield_type = is_bitfield_expr_with_lowered_type (val);
    9823    131159315 :   if (bitfield_type
    9824    131159315 :       && TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type))
    9825            0 :     val = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type), val);
    9826              : 
    9827    131159315 :   if (val == error_mark_node)
    9828              :     ;
    9829              :   /* Pass classes with copy ctors by invisible reference.  */
    9830    131156088 :   else if (TREE_ADDRESSABLE (type))
    9831       199179 :     val = build1 (ADDR_EXPR, build_reference_type (type), val);
    9832    131159315 :   if (complain & tf_warning)
    9833    122176207 :     maybe_warn_parm_abi (type, cp_expr_loc_or_input_loc (val));
    9834              : 
    9835     98286659 :   if (complain & tf_warning)
    9836     98286659 :     warn_for_address_of_packed_member (type, val);
    9837              : 
    9838              :   /* gimplify_arg elides TARGET_EXPRs that initialize a function argument,
    9839              :      unless the initializer is a CONSTRUCTOR.  In that case, we fail to
    9840              :      elide the copy anyway.  See that function for more information.  */
    9841      7117205 :   if (SIMPLE_TARGET_EXPR_P (val)
    9842    136972327 :       && TREE_CODE (TARGET_EXPR_INITIAL (val)) != CONSTRUCTOR)
    9843      3323089 :     set_target_expr_eliding (val);
    9844              : 
    9845    131159315 :   return val;
    9846              : }
    9847              : 
    9848              : /* Returns non-zero iff FN is a function with magic varargs, i.e. ones for
    9849              :    which just decay_conversion or no conversions at all should be done.
    9850              :    This is true for some builtins which don't act like normal functions.
    9851              :    Return 2 if just decay_conversion and removal of excess precision should
    9852              :    be done, 1 if just decay_conversion.  Return 3 for special treatment of
    9853              :    the 3rd argument for __builtin_*_overflow_p.  Return 4 for special
    9854              :    treatment of the 1st argument for
    9855              :    __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g.  */
    9856              : 
    9857              : int
    9858    158429862 : magic_varargs_p (tree fn)
    9859              : {
    9860    158429862 :   if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
    9861      5530128 :     switch (DECL_FUNCTION_CODE (fn))
    9862              :       {
    9863              :       case BUILT_IN_CLASSIFY_TYPE:
    9864              :       case BUILT_IN_CONSTANT_P:
    9865              :       case BUILT_IN_NEXT_ARG:
    9866              :       case BUILT_IN_VA_START:
    9867              :         return 1;
    9868              : 
    9869        20842 :       case BUILT_IN_ADD_OVERFLOW_P:
    9870        20842 :       case BUILT_IN_SUB_OVERFLOW_P:
    9871        20842 :       case BUILT_IN_MUL_OVERFLOW_P:
    9872        20842 :         return 3;
    9873              : 
    9874       180865 :       case BUILT_IN_ISFINITE:
    9875       180865 :       case BUILT_IN_ISINF:
    9876       180865 :       case BUILT_IN_ISINF_SIGN:
    9877       180865 :       case BUILT_IN_ISNAN:
    9878       180865 :       case BUILT_IN_ISNORMAL:
    9879       180865 :       case BUILT_IN_FPCLASSIFY:
    9880       180865 :         return 2;
    9881              : 
    9882        94439 :       case BUILT_IN_CLZG:
    9883        94439 :       case BUILT_IN_CTZG:
    9884        94439 :       case BUILT_IN_CLRSBG:
    9885        94439 :       case BUILT_IN_FFSG:
    9886        94439 :       case BUILT_IN_PARITYG:
    9887        94439 :       case BUILT_IN_POPCOUNTG:
    9888        94439 :         return 4;
    9889              : 
    9890      5039643 :       default:
    9891      5039643 :         return lookup_attribute ("type generic",
    9892     10079286 :                                  TYPE_ATTRIBUTES (TREE_TYPE (fn))) != 0;
    9893              :       }
    9894              : 
    9895              :   return 0;
    9896              : }
    9897              : 
    9898              : /* Returns the decl of the dispatcher function if FN is a function version.  */
    9899              : 
    9900              : tree
    9901          240 : get_function_version_dispatcher (tree fn)
    9902              : {
    9903          240 :   tree dispatcher_decl = NULL;
    9904              : 
    9905          240 :   if (DECL_LOCAL_DECL_P (fn))
    9906            9 :     fn = DECL_LOCAL_DECL_ALIAS (fn);
    9907              : 
    9908          240 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
    9909              :               && DECL_FUNCTION_VERSIONED (fn));
    9910              : 
    9911          240 :   gcc_assert (targetm.get_function_versions_dispatcher);
    9912          240 :   dispatcher_decl = targetm.get_function_versions_dispatcher (fn);
    9913              : 
    9914          240 :   if (dispatcher_decl == NULL)
    9915              :     {
    9916            9 :       error_at (input_location, "use of multiversioned function "
    9917              :                                 "without a default");
    9918            9 :       return NULL;
    9919              :     }
    9920              : 
    9921          231 :   retrofit_lang_decl (dispatcher_decl);
    9922          231 :   gcc_assert (dispatcher_decl != NULL);
    9923              :   return dispatcher_decl;
    9924              : }
    9925              : 
    9926              : /* fn is a function version dispatcher that is marked used. Mark all the
    9927              :    semantically identical function versions it will dispatch as used.  */
    9928              : 
    9929              : void
    9930          159 : mark_versions_used (tree fn)
    9931              : {
    9932          159 :   struct cgraph_node *node;
    9933          159 :   struct cgraph_function_version_info *node_v;
    9934          159 :   struct cgraph_function_version_info *it_v;
    9935              : 
    9936          159 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    9937              : 
    9938          159 :   node = cgraph_node::get (fn);
    9939          159 :   if (node == NULL)
    9940              :     return;
    9941              : 
    9942          159 :   gcc_assert (node->dispatcher_function);
    9943              : 
    9944          159 :   node_v = node->function_version ();
    9945          159 :   if (node_v == NULL)
    9946              :     return;
    9947              : 
    9948              :   /* All semantically identical versions are chained.  Traverse and mark each
    9949              :      one of them as used.  */
    9950          159 :   it_v = node_v->next;
    9951         1143 :   while (it_v != NULL)
    9952              :     {
    9953          984 :       mark_used (it_v->this_node->decl);
    9954          984 :       it_v = it_v->next;
    9955              :     }
    9956              : }
    9957              : 
    9958              : /* Build a call to "the copy constructor" for the type of A, even if it
    9959              :    wouldn't be selected by normal overload resolution.  Used for
    9960              :    diagnostics.  */
    9961              : 
    9962              : static tree
    9963            3 : call_copy_ctor (tree a, tsubst_flags_t complain)
    9964              : {
    9965            3 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (a));
    9966            3 :   tree binfo = TYPE_BINFO (ctype);
    9967            3 :   tree copy = get_copy_ctor (ctype, complain);
    9968            3 :   copy = build_baselink (binfo, binfo, copy, NULL_TREE);
    9969            3 :   tree ob = build_dummy_object (ctype);
    9970            3 :   releasing_vec args (make_tree_vector_single (a));
    9971            3 :   tree r = build_new_method_call (ob, copy, &args, NULL_TREE,
    9972              :                                   LOOKUP_NORMAL, NULL, complain);
    9973            3 :   return r;
    9974            3 : }
    9975              : 
    9976              : /* Return the base constructor corresponding to COMPLETE_CTOR or NULL_TREE.  */
    9977              : 
    9978              : static tree
    9979           42 : base_ctor_for (tree complete_ctor)
    9980              : {
    9981           42 :   tree clone;
    9982           42 :   FOR_EACH_CLONE (clone, DECL_CLONED_FUNCTION (complete_ctor))
    9983           42 :     if (DECL_BASE_CONSTRUCTOR_P (clone))
    9984              :       return clone;
    9985              :   return NULL_TREE;
    9986              : }
    9987              : 
    9988              : /* Try to make EXP suitable to be used as the initializer for a base subobject,
    9989              :    and return whether we were successful.  EXP must have already been cleared
    9990              :    by unsafe_copy_elision_p{,_opt}.  */
    9991              : 
    9992              : static bool
    9993          214 : make_base_init_ok (tree exp)
    9994              : {
    9995          214 :   if (TREE_CODE (exp) == TARGET_EXPR)
    9996          214 :     exp = TARGET_EXPR_INITIAL (exp);
    9997          217 :   while (TREE_CODE (exp) == COMPOUND_EXPR)
    9998            3 :     exp = TREE_OPERAND (exp, 1);
    9999          214 :   if (TREE_CODE (exp) == COND_EXPR)
   10000              :     {
   10001            3 :       bool ret = make_base_init_ok (TREE_OPERAND (exp, 2));
   10002            3 :       if (tree op1 = TREE_OPERAND (exp, 1))
   10003              :         {
   10004            3 :           bool r1 = make_base_init_ok (op1);
   10005              :           /* If unsafe_copy_elision_p was false, the arms should match.  */
   10006            3 :           gcc_assert (r1 == ret);
   10007              :         }
   10008            3 :       return ret;
   10009              :     }
   10010          211 :   if (TREE_CODE (exp) != AGGR_INIT_EXPR)
   10011              :     /* A trivial copy is OK.  */
   10012              :     return true;
   10013           60 :   if (!AGGR_INIT_VIA_CTOR_P (exp))
   10014              :     /* unsafe_copy_elision_p_opt must have said this is OK.  */
   10015              :     return true;
   10016           42 :   tree fn = cp_get_callee_fndecl_nofold (exp);
   10017           42 :   if (DECL_BASE_CONSTRUCTOR_P (fn))
   10018              :     return true;
   10019           42 :   gcc_assert (DECL_COMPLETE_CONSTRUCTOR_P (fn));
   10020           42 :   fn = base_ctor_for (fn);
   10021           42 :   if (!fn || DECL_HAS_VTT_PARM_P (fn))
   10022              :     /* The base constructor has more parameters, so we can't just change the
   10023              :        call target.  It would be possible to splice in the appropriate
   10024              :        arguments, but probably not worth the complexity.  */
   10025              :     return false;
   10026           33 :   mark_used (fn);
   10027           33 :   AGGR_INIT_EXPR_FN (exp) = build_address (fn);
   10028           33 :   return true;
   10029              : }
   10030              : 
   10031              : /* Return 2 if T refers to a base, 1 if a potentially-overlapping field,
   10032              :    neither of which can be used for return by invisible reference.  We avoid
   10033              :    doing C++17 mandatory copy elision for either of these cases.
   10034              : 
   10035              :    This returns non-zero even if the type of T has no tail padding that other
   10036              :    data could be allocated into, because that depends on the particular ABI.
   10037              :    unsafe_copy_elision_p_opt does consider whether there is padding.  */
   10038              : 
   10039              : int
   10040     39416950 : unsafe_return_slot_p (tree t)
   10041              : {
   10042              :   /* Check empty bases separately, they don't have fields.  */
   10043     39416950 :   if (is_empty_base_ref (t))
   10044              :     return 2;
   10045              : 
   10046              :   /* A delegating constructor might be used to initialize a base.  */
   10047     38959482 :   if (current_function_decl
   10048     52822176 :       && DECL_CONSTRUCTOR_P (current_function_decl)
   10049     42862561 :       && (t == current_class_ref
   10050      3739617 :           || tree_strip_nop_conversions (t) == current_class_ptr))
   10051       211706 :     return 2;
   10052              : 
   10053     38747776 :   STRIP_NOPS (t);
   10054     38747776 :   if (TREE_CODE (t) == ADDR_EXPR)
   10055        62128 :     t = TREE_OPERAND (t, 0);
   10056     38747776 :   if (TREE_CODE (t) == COMPONENT_REF)
   10057      3272117 :     t = TREE_OPERAND (t, 1);
   10058     38747776 :   if (TREE_CODE (t) != FIELD_DECL)
   10059              :     return false;
   10060      3313013 :   if (!CLASS_TYPE_P (TREE_TYPE (t)))
   10061              :     /* The middle-end will do the right thing for scalar types.  */
   10062              :     return false;
   10063      2881471 :   if (DECL_FIELD_IS_BASE (t))
   10064              :     return 2;
   10065      2105004 :   if (lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (t)))
   10066              :     return 1;
   10067              :   return 0;
   10068              : }
   10069              : 
   10070              : /* True IFF EXP is a prvalue that represents return by invisible reference.  */
   10071              : 
   10072              : static bool
   10073       268735 : init_by_return_slot_p (tree exp)
   10074              : {
   10075              :   /* Copy elision only happens with a TARGET_EXPR.  */
   10076       268738 :   if (TREE_CODE (exp) != TARGET_EXPR)
   10077              :     return false;
   10078        14143 :   tree init = TARGET_EXPR_INITIAL (exp);
   10079              :   /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR.  */
   10080        14149 :   while (TREE_CODE (init) == COMPOUND_EXPR)
   10081            6 :     init = TREE_OPERAND (init, 1);
   10082        14143 :   if (TREE_CODE (init) == COND_EXPR)
   10083              :     {
   10084              :       /* We'll end up copying from each of the arms of the COND_EXPR directly
   10085              :          into the target, so look at them.  */
   10086            6 :       if (tree op = TREE_OPERAND (init, 1))
   10087            6 :         if (init_by_return_slot_p (op))
   10088              :           return true;
   10089            3 :       return init_by_return_slot_p (TREE_OPERAND (init, 2));
   10090              :     }
   10091        14137 :   return (TREE_CODE (init) == AGGR_INIT_EXPR
   10092        14137 :           && !AGGR_INIT_VIA_CTOR_P (init));
   10093              : }
   10094              : 
   10095              : /* We can't elide a copy from a function returning by value to a
   10096              :    potentially-overlapping subobject, as the callee might clobber tail padding.
   10097              :    Return true iff this could be that case.
   10098              : 
   10099              :    Places that use this function (or _opt) to decide to elide a copy should
   10100              :    probably use make_safe_copy_elision instead.  */
   10101              : 
   10102              : bool
   10103      2159160 : unsafe_copy_elision_p (tree target, tree exp)
   10104              : {
   10105      2159160 :   return unsafe_return_slot_p (target) && init_by_return_slot_p (exp);
   10106              : }
   10107              : 
   10108              : /* As above, but for optimization allow more cases that are actually safe.  */
   10109              : 
   10110              : static bool
   10111      7515180 : unsafe_copy_elision_p_opt (tree target, tree exp)
   10112              : {
   10113      7515180 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
   10114              :   /* It's safe to elide the copy for a class with no tail padding.  */
   10115      7515180 :   if (!is_empty_class (type)
   10116      7515180 :       && tree_int_cst_equal (TYPE_SIZE (type), CLASSTYPE_SIZE (type)))
   10117              :     return false;
   10118      2118264 :   return unsafe_copy_elision_p (target, exp);
   10119              : }
   10120              : 
   10121              : /* Try to make EXP suitable to be used as the initializer for TARGET,
   10122              :    and return whether we were successful.  */
   10123              : 
   10124              : bool
   10125           23 : make_safe_copy_elision (tree target, tree exp)
   10126              : {
   10127           23 :   int uns = unsafe_return_slot_p (target);
   10128           23 :   if (!uns)
   10129              :     return true;
   10130           23 :   if (init_by_return_slot_p (exp))
   10131              :     return false;
   10132           23 :   if (uns == 1)
   10133              :     return true;
   10134           19 :   return make_base_init_ok (exp);
   10135              : }
   10136              : 
   10137              : /* True IFF the result of the conversion C is a prvalue.  */
   10138              : 
   10139              : static bool
   10140     13206124 : conv_is_prvalue (conversion *c)
   10141              : {
   10142     13206124 :   if (c->kind == ck_rvalue)
   10143              :     return true;
   10144     13206124 :   if (c->kind == ck_base && c->need_temporary_p)
   10145              :     return true;
   10146     13206124 :   if (c->kind == ck_user && !TYPE_REF_P (c->type))
   10147              :     return true;
   10148     13077469 :   if (c->kind == ck_identity && c->u.expr
   10149     12839712 :       && TREE_CODE (c->u.expr) == TARGET_EXPR)
   10150           57 :     return true;
   10151              : 
   10152              :   return false;
   10153              : }
   10154              : 
   10155              : /* True iff C is a conversion that binds a reference to a prvalue.  */
   10156              : 
   10157              : static bool
   10158     13207223 : conv_binds_ref_to_prvalue (conversion *c)
   10159              : {
   10160     13207223 :   if (c->kind != ck_ref_bind)
   10161              :     return false;
   10162     13207223 :   if (c->need_temporary_p)
   10163              :     return true;
   10164              : 
   10165     13206124 :   return conv_is_prvalue (next_conversion (c));
   10166              : }
   10167              : 
   10168              : /* True iff EXPR represents a (subobject of a) temporary.  */
   10169              : 
   10170              : static bool
   10171        14082 : expr_represents_temporary_p (tree expr)
   10172              : {
   10173        14186 :   while (handled_component_p (expr))
   10174          104 :     expr = TREE_OPERAND (expr, 0);
   10175        14082 :   return TREE_CODE (expr) == TARGET_EXPR;
   10176              : }
   10177              : 
   10178              : /* True iff C is a conversion that binds a reference to a temporary.
   10179              :    This is a superset of conv_binds_ref_to_prvalue: here we're also
   10180              :    interested in xvalues.  */
   10181              : 
   10182              : static bool
   10183        13381 : conv_binds_ref_to_temporary (conversion *c)
   10184              : {
   10185        13381 :   if (conv_binds_ref_to_prvalue (c))
   10186              :     return true;
   10187        12930 :   if (c->kind != ck_ref_bind)
   10188              :     return false;
   10189        12930 :   c = next_conversion (c);
   10190              :   /* This is the case for
   10191              :        struct Base {};
   10192              :        struct Derived : Base {};
   10193              :        const Base& b(Derived{});
   10194              :      where we bind 'b' to the Base subobject of a temporary object of type
   10195              :      Derived.  The subobject is an xvalue; the whole object is a prvalue.
   10196              : 
   10197              :      The ck_base doesn't have to be present for cases like X{}.m.  */
   10198        12930 :   if (c->kind == ck_base)
   10199            8 :     c = next_conversion (c);
   10200        12859 :   if (c->kind == ck_identity && c->u.expr
   10201        25789 :       && expr_represents_temporary_p (c->u.expr))
   10202              :     return true;
   10203              :   return false;
   10204              : }
   10205              : 
   10206              : /* Return tristate::TS_TRUE if converting EXPR to a reference type TYPE binds
   10207              :    the reference to a temporary.  Return tristate::TS_FALSE if converting
   10208              :    EXPR to a reference type TYPE doesn't bind the reference to a temporary.  If
   10209              :    the conversion is invalid or bad, return tristate::TS_UNKNOWN.  DIRECT_INIT_P
   10210              :    says whether the conversion should be done in direct- or copy-initialization
   10211              :    context.  */
   10212              : 
   10213              : tristate
   10214        13904 : ref_conv_binds_to_temporary (tree type, tree expr, bool direct_init_p/*=false*/)
   10215              : {
   10216        13904 :   gcc_assert (TYPE_REF_P (type));
   10217              : 
   10218        13904 :   conversion_obstack_sentinel cos;
   10219              : 
   10220        13904 :   const int flags = direct_init_p ? LOOKUP_NORMAL : LOOKUP_IMPLICIT;
   10221        13904 :   conversion *conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   10222              :                                           /*c_cast_p=*/false, flags, tf_none);
   10223        13904 :   if (!conv || conv->bad_p)
   10224          523 :     return tristate::unknown ();
   10225              : 
   10226        13381 :   if (conv_binds_ref_to_temporary (conv))
   10227              :     {
   10228              :       /* Actually perform the conversion to check access control.  */
   10229          457 :       if (convert_like (conv, expr, tf_none) != error_mark_node)
   10230          445 :         return tristate (true);
   10231              :       else
   10232           12 :         return tristate::unknown ();
   10233              :     }
   10234              : 
   10235        12924 :   return tristate (false);
   10236        13904 : }
   10237              : 
   10238              : /* Call the trivial destructor for INSTANCE, which can be either an lvalue of
   10239              :    class type or a pointer to class type.  If NO_PTR_DEREF is true and
   10240              :    INSTANCE has pointer type, clobber the pointer rather than what it points
   10241              :    to.  */
   10242              : 
   10243              : tree
   10244      3194037 : build_trivial_dtor_call (tree instance, bool no_ptr_deref)
   10245              : {
   10246      3194037 :   gcc_assert (!is_dummy_object (instance));
   10247              : 
   10248      3194037 :   if (!flag_lifetime_dse)
   10249              :     {
   10250           58 :     no_clobber:
   10251           77 :       return fold_convert (void_type_node, instance);
   10252              :     }
   10253              : 
   10254      3236845 :   if (INDIRECT_TYPE_P (TREE_TYPE (instance))
   10255      3193979 :       && (!no_ptr_deref || TYPE_REF_P (TREE_TYPE (instance))))
   10256              :     {
   10257      3040147 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
   10258           19 :         goto no_clobber;
   10259      3040128 :       instance = cp_build_fold_indirect_ref (instance);
   10260              :     }
   10261              : 
   10262              :   /* A trivial destructor should still clobber the object.  */
   10263      3193960 :   tree clobber = build_clobber (TREE_TYPE (instance), CLOBBER_OBJECT_END);
   10264      3193960 :   return build2 (MODIFY_EXPR, void_type_node,
   10265      3193960 :                  instance, clobber);
   10266              : }
   10267              : 
   10268              : /* Return true if in an immediate function context, or an unevaluated operand,
   10269              :    or a default argument/member initializer, or a subexpression of an immediate
   10270              :    invocation.  */
   10271              : 
   10272              : bool
   10273     13647980 : in_immediate_context ()
   10274              : {
   10275     13647980 :   return (cp_unevaluated_operand != 0
   10276     12109293 :           || (current_function_decl != NULL_TREE
   10277     19910858 :               && DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
   10278              :           /* DR 2631: default args and DMI aren't immediately evaluated.
   10279              :              Return true here so immediate_invocation_p returns false.  */
   10280     11811617 :           || current_binding_level->kind == sk_function_parms
   10281     11809382 :           || current_binding_level->kind == sk_template_parms
   10282     11745191 :           || parsing_nsdmi ()
   10283     25391327 :           || in_consteval_if_p);
   10284              : }
   10285              : 
   10286              : /* Return true if a call to FN with number of arguments NARGS
   10287              :    is an immediate invocation.  */
   10288              : 
   10289              : bool
   10290    198353022 : immediate_invocation_p (tree fn)
   10291              : {
   10292    198353022 :   return (TREE_CODE (fn) == FUNCTION_DECL
   10293    198353022 :           && DECL_IMMEDIATE_FUNCTION_P (fn)
   10294    201167299 :           && !in_immediate_context ());
   10295              : }
   10296              : 
   10297              : /* Subroutine of the various build_*_call functions.  Overload resolution
   10298              :    has chosen a winning candidate CAND; build up a CALL_EXPR accordingly.
   10299              :    ARGS is a TREE_LIST of the unconverted arguments to the call.  FLAGS is a
   10300              :    bitmask of various LOOKUP_* flags which apply to the call itself.  */
   10301              : 
   10302              : static tree
   10303    213244873 : build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
   10304              : {
   10305    213244873 :   tree fn = cand->fn;
   10306    213244873 :   const vec<tree, va_gc> *args = cand->args;
   10307    213244873 :   tree first_arg = cand->first_arg;
   10308    213244873 :   conversion **convs = cand->convs;
   10309    213244873 :   tree parm = TYPE_ARG_TYPES (TREE_TYPE (fn));
   10310    213244873 :   int parmlen;
   10311    213244873 :   tree val;
   10312    213244873 :   int nargs;
   10313    213244873 :   tree *argarray;
   10314    213244873 :   bool already_used = false;
   10315              : 
   10316              :   /* In a template, there is no need to perform all of the work that
   10317              :      is normally done.  We are only interested in the type of the call
   10318              :      expression, i.e., the return type of the function.  Any semantic
   10319              :      errors will be deferred until the template is instantiated.  */
   10320    213244873 :   if (processing_template_decl)
   10321              :     {
   10322     29303453 :       if (undeduced_auto_decl (fn))
   10323        11828 :         mark_used (fn, complain);
   10324              :       else
   10325              :         /* Otherwise set TREE_USED for the benefit of -Wunused-function.
   10326              :            See PR80598.  */
   10327     29291625 :         TREE_USED (fn) = 1;
   10328              : 
   10329     29303453 :       tree return_type = TREE_TYPE (TREE_TYPE (fn));
   10330     29303453 :       tree callee;
   10331     29303453 :       if (first_arg == NULL_TREE)
   10332              :         {
   10333     21434065 :           callee = build_addr_func (fn, complain);
   10334     21434065 :           if (callee == error_mark_node)
   10335              :             return error_mark_node;
   10336              :         }
   10337              :       else
   10338              :         {
   10339      7869388 :           callee = build_baselink (cand->conversion_path, cand->access_path,
   10340              :                                    fn, NULL_TREE);
   10341      7869388 :           callee = build_min (COMPONENT_REF, TREE_TYPE (fn),
   10342              :                               first_arg, callee, NULL_TREE);
   10343              :         }
   10344              : 
   10345     29303453 :       tree expr = build_call_vec (return_type, callee, args);
   10346     29303453 :       SET_EXPR_LOCATION (expr, input_location);
   10347     29303453 :       if (TREE_THIS_VOLATILE (fn) && cfun)
   10348      2484238 :         current_function_returns_abnormally = 1;
   10349     29303453 :       if (TREE_DEPRECATED (fn)
   10350     29303453 :           && warning_suppressed_at (input_location,
   10351              :                                     OPT_Wdeprecated_declarations))
   10352              :         /* Make the expr consistent with the location.  */
   10353        18995 :         TREE_NO_WARNING (expr) = true;
   10354     29303453 :       if (immediate_invocation_p (fn))
   10355              :         {
   10356       194105 :           tree obj_arg = NULL_TREE;
   10357       388210 :           if (DECL_CONSTRUCTOR_P (fn))
   10358            0 :             obj_arg = first_arg;
   10359              :           /* Look through *(const T *)&obj.  */
   10360            0 :           if (obj_arg && INDIRECT_REF_P (obj_arg))
   10361              :             {
   10362            0 :               tree addr = TREE_OPERAND (obj_arg, 0);
   10363            0 :               STRIP_NOPS (addr);
   10364            0 :               if (TREE_CODE (addr) == ADDR_EXPR)
   10365              :                 {
   10366            0 :                   tree typeo = TREE_TYPE (obj_arg);
   10367            0 :                   tree typei = TREE_TYPE (TREE_OPERAND (addr, 0));
   10368            0 :                   if (same_type_ignoring_top_level_qualifiers_p (typeo, typei))
   10369            0 :                     obj_arg = TREE_OPERAND (addr, 0);
   10370              :                 }
   10371              :             }
   10372       194105 :           fold_non_dependent_expr (expr, complain,
   10373              :                                    /*manifestly_const_eval=*/true,
   10374              :                                    obj_arg);
   10375              :         }
   10376     29303453 :       return convert_from_reference (expr);
   10377              :     }
   10378              : 
   10379              :   /* Give any warnings we noticed during overload resolution.  */
   10380    183941420 :   if (cand->warnings && (complain & tf_warning))
   10381              :     {
   10382              :       struct candidate_warning *w;
   10383           98 :       for (w = cand->warnings; w; w = w->next)
   10384           49 :         joust (cand, w->loser, 1, complain);
   10385              :     }
   10386              : 
   10387              :   /* Core issue 2327: P0135 doesn't say how to handle the case where the
   10388              :      argument to the copy constructor ends up being a prvalue after
   10389              :      conversion.  Let's do the normal processing, but pretend we aren't
   10390              :      actually using the copy constructor.  */
   10391    183941420 :   bool force_elide = false;
   10392    183941420 :   if (cxx_dialect >= cxx17
   10393    181962036 :       && cand->num_convs == 1
   10394    103407840 :       && DECL_COMPLETE_CONSTRUCTOR_P (fn)
   10395     36506498 :       && (DECL_COPY_CONSTRUCTOR_P (fn)
   10396     19983758 :           || DECL_MOVE_CONSTRUCTOR_P (fn))
   10397     13260484 :       && !unsafe_return_slot_p (first_arg)
   10398    197135203 :       && conv_binds_ref_to_prvalue (convs[0]))
   10399              :     {
   10400       129357 :       force_elide = true;
   10401       129357 :       goto not_really_used;
   10402              :     }
   10403              : 
   10404              :   /* OK, we're actually calling this inherited constructor; set its deletedness
   10405              :      appropriately.  We can get away with doing this here because calling is
   10406              :      the only way to refer to a constructor.  */
   10407    367624126 :   if (DECL_INHERITED_CTOR (fn)
   10408     27124245 :       && !deduce_inheriting_ctor (fn))
   10409              :     {
   10410            2 :       if (complain & tf_error)
   10411            2 :         mark_used (fn);
   10412            2 :       return error_mark_node;
   10413              :     }
   10414              : 
   10415              :   /* Make =delete work with SFINAE.  */
   10416    183812061 :   if (DECL_DELETED_FN (fn))
   10417              :     {
   10418       992011 :       if (complain & tf_error)
   10419              :         {
   10420         2268 :           mark_used (fn);
   10421         2268 :           if (cand->next)
   10422              :             {
   10423         2067 :               if (flag_diagnostics_all_candidates)
   10424            9 :                 print_z_candidates (input_location, cand, /*only_viable_p=*/false);
   10425              :               else
   10426         2058 :                 inform (input_location,
   10427              :                         "use %<-fdiagnostics-all-candidates%> to display "
   10428              :                         "considered candidates");
   10429              :             }
   10430              :         }
   10431       992011 :       return error_mark_node;
   10432              :     }
   10433              : 
   10434    182820050 :   if (DECL_FUNCTION_MEMBER_P (fn))
   10435              :     {
   10436     99473346 :       tree access_fn;
   10437              :       /* If FN is a template function, two cases must be considered.
   10438              :          For example:
   10439              : 
   10440              :            struct A {
   10441              :              protected:
   10442              :                template <class T> void f();
   10443              :            };
   10444              :            template <class T> struct B {
   10445              :              protected:
   10446              :                void g();
   10447              :            };
   10448              :            struct C : A, B<int> {
   10449              :              using A::f;        // #1
   10450              :              using B<int>::g;     // #2
   10451              :            };
   10452              : 
   10453              :          In case #1 where `A::f' is a member template, DECL_ACCESS is
   10454              :          recorded in the primary template but not in its specialization.
   10455              :          We check access of FN using its primary template.
   10456              : 
   10457              :          In case #2, where `B<int>::g' has a DECL_TEMPLATE_INFO simply
   10458              :          because it is a member of class template B, DECL_ACCESS is
   10459              :          recorded in the specialization `B<int>::g'.  We cannot use its
   10460              :          primary template because `B<T>::g' and `B<int>::g' may have
   10461              :          different access.  */
   10462     99473346 :       if (DECL_TEMPLATE_INFO (fn)
   10463     99473346 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   10464      7333856 :         access_fn = DECL_TI_TEMPLATE (fn);
   10465              :       else
   10466              :         access_fn = fn;
   10467     99473346 :       if (!perform_or_defer_access_check (cand->access_path, access_fn,
   10468              :                                           fn, complain))
   10469        20107 :         return error_mark_node;
   10470              :     }
   10471              : 
   10472              :   /* If we're checking for implicit delete, don't bother with argument
   10473              :      conversions.  */
   10474    182799943 :   if (flags & LOOKUP_SPECULATIVE)
   10475              :     {
   10476     24496628 :       if (cand->viable == 1)
   10477              :         return fn;
   10478          121 :       else if (!(complain & tf_error))
   10479              :         /* Reject bad conversions now.  */
   10480          106 :         return error_mark_node;
   10481              :       /* else continue to get conversion error.  */
   10482              :     }
   10483              : 
   10484    158303315 :  not_really_used:
   10485              : 
   10486              :   /* N3276 magic doesn't apply to nested calls.  */
   10487    158432687 :   tsubst_flags_t decltype_flag = (complain & tf_decltype);
   10488    158432687 :   complain &= ~tf_decltype;
   10489              :   /* No-Cleanup doesn't apply to nested calls either.  */
   10490    158432687 :   tsubst_flags_t no_cleanup_complain = complain;
   10491    158432687 :   complain &= ~tf_no_cleanup;
   10492              : 
   10493              :   /* Find maximum size of vector to hold converted arguments.  */
   10494    158432687 :   parmlen = list_length (parm);
   10495    297542926 :   nargs = vec_safe_length (args) + (first_arg != NULL_TREE ? 1 : 0);
   10496    158432687 :   if (parmlen > nargs)
   10497              :     nargs = parmlen;
   10498    158432687 :   argarray = XALLOCAVEC (tree, nargs);
   10499              : 
   10500    316865371 :   in_consteval_if_p_temp_override icip;
   10501              :   /* If the call is immediate function invocation, make sure
   10502              :      taking address of immediate functions is allowed in its arguments.  */
   10503    158432687 :   if (immediate_invocation_p (STRIP_TEMPLATE (fn)))
   10504      1434565 :     in_consteval_if_p = true;
   10505              : 
   10506    158432687 :   int argarray_size = 0;
   10507    158432687 :   unsigned int arg_index = 0;
   10508    158432687 :   int conv_index = 0;
   10509    158432687 :   int param_index = 0;
   10510    158432687 :   tree parmd = DECL_ARGUMENTS (fn);
   10511              : 
   10512    221236104 :   auto consume_object_arg = [&arg_index, &first_arg, args]()
   10513              :     {
   10514     62803417 :       if (!first_arg)
   10515            0 :         return (*args)[arg_index++];
   10516     62803417 :       tree object_arg = first_arg;
   10517     62803417 :       first_arg = NULL_TREE;
   10518     62803417 :       return object_arg;
   10519    158432687 :     };
   10520              : 
   10521              :   /* The implicit parameters to a constructor are not considered by overload
   10522              :      resolution, and must be of the proper type.  */
   10523    158432687 :   if (DECL_CONSTRUCTOR_P (fn))
   10524              :     {
   10525     19160725 :       tree object_arg = consume_object_arg ();
   10526     19160725 :       argarray[argarray_size++] = build_this (object_arg);
   10527     19160725 :       parm = TREE_CHAIN (parm);
   10528     19160725 :       if (parmd)
   10529     19160725 :         parmd = DECL_CHAIN (parmd);
   10530              :       /* We should never try to call the abstract constructor.  */
   10531     19160725 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (fn));
   10532              : 
   10533     19160725 :       if (DECL_HAS_VTT_PARM_P (fn))
   10534              :         {
   10535        17098 :           argarray[argarray_size++] = (*args)[arg_index];
   10536        17098 :           ++arg_index;
   10537        17098 :           parm = TREE_CHAIN (parm);
   10538        17098 :           if (parmd)
   10539        17098 :             parmd = DECL_CHAIN (parmd);
   10540              :         }
   10541              :     }
   10542              :   /* Bypass access control for 'this' parameter.  */
   10543    139271962 :   else if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
   10544              :     {
   10545     43634345 :       tree arg = build_this (consume_object_arg ());
   10546     43634345 :       tree argtype = TREE_TYPE (arg);
   10547              : 
   10548     43634345 :       if (arg == error_mark_node)
   10549              :         return error_mark_node;
   10550     43634342 :       if (convs[conv_index++]->bad_p)
   10551              :         {
   10552         1194 :           if (complain & tf_error)
   10553              :             {
   10554          105 :               auto_diagnostic_group d;
   10555          105 :               if (permerror (input_location, "passing %qT as %<this%> "
   10556              :                              "argument discards qualifiers",
   10557          105 :                              TREE_TYPE (argtype)))
   10558          102 :                 inform (DECL_SOURCE_LOCATION (fn), "  in call to %qD", fn);
   10559          105 :             }
   10560              :           else
   10561              :             return error_mark_node;
   10562              :         }
   10563              : 
   10564              :       /* The class where FN is defined.  */
   10565     43633253 :       tree ctx = DECL_CONTEXT (fn);
   10566              : 
   10567              :       /* See if the function member or the whole class type is declared
   10568              :          final and the call can be devirtualized.  */
   10569     43633253 :       if (DECL_FINAL_P (fn) || CLASSTYPE_FINAL (ctx))
   10570       125085 :         flags |= LOOKUP_NONVIRTUAL;
   10571              : 
   10572              :       /* [class.mfct.non-static]: If a non-static member function of a class
   10573              :          X is called for an object that is not of type X, or of a type
   10574              :          derived from X, the behavior is undefined.
   10575              : 
   10576              :          So we can assume that anything passed as 'this' is non-null, and
   10577              :          optimize accordingly.  */
   10578              :       /* Check that the base class is accessible.  */
   10579     43633253 :       if (!accessible_base_p (TREE_TYPE (argtype),
   10580     43633253 :                               BINFO_TYPE (cand->conversion_path), true))
   10581              :         {
   10582           33 :           if (complain & tf_error)
   10583           30 :             error ("%qT is not an accessible base of %qT",
   10584           30 :                    BINFO_TYPE (cand->conversion_path),
   10585           30 :                    TREE_TYPE (argtype));
   10586              :           else
   10587            3 :             return error_mark_node;
   10588              :         }
   10589              :       /* If fn was found by a using declaration, the conversion path
   10590              :          will be to the derived class, not the base declaring fn. We
   10591              :          must convert to the base.  */
   10592     43633250 :       tree base_binfo = cand->conversion_path;
   10593     43633250 :       if (BINFO_TYPE (base_binfo) != ctx)
   10594              :         {
   10595       114635 :           base_binfo = lookup_base (base_binfo, ctx, ba_unique, NULL, complain);
   10596       114635 :           if (base_binfo == error_mark_node)
   10597              :             return error_mark_node;
   10598              :         }
   10599              : 
   10600              :       /* If we know the dynamic type of the object, look up the final overrider
   10601              :          in the BINFO.  */
   10602     44494561 :       if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
   10603     44104512 :           && resolves_to_fixed_type_p (arg))
   10604              :         {
   10605         1101 :           tree ov = lookup_vfn_in_binfo (DECL_VINDEX (fn), base_binfo);
   10606              : 
   10607              :           /* And unwind base_binfo to match.  If we don't find the type we're
   10608              :              looking for in BINFO_INHERITANCE_CHAIN, we're looking at diamond
   10609              :              inheritance; for now do a normal virtual call in that case.  */
   10610         1101 :           tree octx = DECL_CONTEXT (ov);
   10611         1101 :           tree obinfo = base_binfo;
   10612         2289 :           while (obinfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (obinfo), octx))
   10613           45 :             obinfo = BINFO_INHERITANCE_CHAIN (obinfo);
   10614         1101 :           if (obinfo)
   10615              :             {
   10616         1098 :               fn = ov;
   10617         1098 :               base_binfo = obinfo;
   10618         1098 :               flags |= LOOKUP_NONVIRTUAL;
   10619              :             }
   10620              :         }
   10621              : 
   10622     43633244 :       tree converted_arg = build_base_path (PLUS_EXPR, arg,
   10623              :                                             base_binfo, 1, complain);
   10624              : 
   10625     43633244 :       argarray[argarray_size++] = converted_arg;
   10626     43633244 :       parm = TREE_CHAIN (parm);
   10627     43633244 :       if (parmd)
   10628     43633244 :         parmd = DECL_CHAIN (parmd);
   10629              :     }
   10630              : 
   10631    283945236 :   auto handle_arg = [fn, flags](tree type,
   10632              :                                 tree arg,
   10633              :                                 int const param_index,
   10634              :                                 conversion *conv,
   10635              :                                 tsubst_flags_t const arg_complain)
   10636              :     {
   10637              :       /* Set user_conv_p on the argument conversions, so rvalue/base handling
   10638              :          knows not to allow any more UDCs.  This needs to happen after we
   10639              :          process cand->warnings.  */
   10640    125513650 :       if (flags & LOOKUP_NO_CONVERSION)
   10641      3463625 :         conv->user_conv_p = true;
   10642              : 
   10643    125513650 :       if (arg_complain & tf_warning)
   10644     93040737 :         maybe_warn_pessimizing_move (arg, type, /*return_p=*/false);
   10645              : 
   10646    125513650 :       tree val = convert_like_with_context (conv, arg, fn,
   10647              :                                             param_index, arg_complain);
   10648    125513650 :       val = convert_for_arg_passing (type, val, arg_complain);
   10649    125513650 :       return val;
   10650    158431586 :     };
   10651              : 
   10652    284980711 :   auto handle_indeterminate_arg = [](tree parmd, tree val)
   10653              :     {
   10654    126549125 :       if (parmd
   10655    126549125 :           && lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (parmd)))
   10656              :         {
   10657           48 :           STRIP_NOPS (val);
   10658           48 :           if (TREE_CODE (val) == ADDR_EXPR
   10659           48 :               && TREE_CODE (TREE_OPERAND (val, 0)) == TARGET_EXPR)
   10660              :             {
   10661           48 :               val = TARGET_EXPR_SLOT (TREE_OPERAND (val, 0));
   10662           48 :               if (auto_var_p (val) && DECL_ARTIFICIAL (val))
   10663              :                 {
   10664           48 :                   tree id = get_identifier ("indeterminate");
   10665           48 :                   DECL_ATTRIBUTES (val)
   10666           96 :                     = tree_cons (build_tree_list (NULL_TREE, id), NULL_TREE,
   10667           48 :                                  DECL_ATTRIBUTES (val));
   10668              :                 }
   10669              :             }
   10670              :         }
   10671    126549125 :     };
   10672              : 
   10673    158431586 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   10674              :     {
   10675         8347 :       gcc_assert (cand->num_convs > 0);
   10676         8347 :       tree object_arg = consume_object_arg ();
   10677         8347 :       val = handle_arg (TREE_VALUE (parm),
   10678              :                         object_arg,
   10679              :                         param_index++,
   10680         8347 :                         convs[conv_index++],
   10681              :                         complain);
   10682              : 
   10683         8347 :       if (val == error_mark_node)
   10684              :         return error_mark_node;
   10685              :       else
   10686              :         {
   10687         8179 :           argarray[argarray_size++] = val;
   10688         8179 :           handle_indeterminate_arg (parmd, val);
   10689              :         }
   10690         8179 :       parm = TREE_CHAIN (parm);
   10691         8179 :       if (parmd)
   10692         8179 :         parmd = DECL_CHAIN (parmd);
   10693              :     }
   10694              : 
   10695    158431418 :   gcc_assert (first_arg == NULL_TREE);
   10696    283935264 :   for (; arg_index < vec_safe_length (args) && parm;
   10697    125503846 :        parm = TREE_CHAIN (parm), ++arg_index, ++param_index, ++conv_index)
   10698              :     {
   10699    125505303 :       tree current_arg = (*args)[arg_index];
   10700              : 
   10701              :       /* If the argument is NULL and used to (implicitly) instantiate a
   10702              :          template function (and bind one of the template arguments to
   10703              :          the type of 'long int'), we don't want to warn about passing NULL
   10704              :          to non-pointer argument.
   10705              :          For example, if we have this template function:
   10706              : 
   10707              :            template<typename T> void func(T x) {}
   10708              : 
   10709              :          we want to warn (when -Wconversion is enabled) in this case:
   10710              : 
   10711              :            void foo() {
   10712              :              func<int>(NULL);
   10713              :            }
   10714              : 
   10715              :          but not in this case:
   10716              : 
   10717              :            void foo() {
   10718              :              func(NULL);
   10719              :            }
   10720              :       */
   10721    125505303 :       bool conversion_warning = !(null_node_p (current_arg)
   10722        45288 :                                   && DECL_TEMPLATE_INFO (fn)
   10723           61 :                                   && cand->template_decl
   10724           30 :                                   && !cand->explicit_targs);
   10725              : 
   10726              :       /* Also don't warn about (x <=> y) < 0 (c++/100903).  */
   10727    125505288 :       if (conversion_warning
   10728    125505288 :           && integer_zerop (current_arg)
   10729      9861553 :           && warn_zero_as_null_pointer_constant
   10730          195 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (fn),
   10731          195 :                                   OPT_Wzero_as_null_pointer_constant))
   10732              :         conversion_warning = false;
   10733              : 
   10734          135 :       tsubst_flags_t const arg_complain
   10735    125505183 :         = conversion_warning ? complain : complain & ~tf_warning;
   10736              : 
   10737    125505303 :       val = handle_arg (TREE_VALUE (parm),
   10738              :                         current_arg,
   10739              :                         param_index,
   10740    125505303 :                         convs[conv_index],
   10741              :                         arg_complain);
   10742              : 
   10743    125505303 :       if (val == error_mark_node)
   10744              :         return error_mark_node;
   10745              :       else
   10746              :         {
   10747    125503846 :           argarray[argarray_size++] = val;
   10748    125503846 :           handle_indeterminate_arg (parmd, val);
   10749              :         }
   10750    125503846 :       if (parmd)
   10751    114920867 :         parmd = DECL_CHAIN (parmd);
   10752              :     }
   10753              : 
   10754              :   /* Default arguments */
   10755    159467061 :   for (; parm && parm != void_list_node;
   10756      1037100 :        parm = TREE_CHAIN (parm), param_index++)
   10757              :     {
   10758      1037220 :       if (TREE_VALUE (parm) == error_mark_node)
   10759              :         return error_mark_node;
   10760      2074416 :       val = convert_default_arg (TREE_VALUE (parm),
   10761      1037208 :                                  TREE_PURPOSE (parm),
   10762              :                                  fn, param_index,
   10763              :                                  complain);
   10764      1037208 :       if (val == error_mark_node)
   10765              :         return error_mark_node;
   10766      1037100 :       argarray[argarray_size++] = val;
   10767      1037100 :       handle_indeterminate_arg (parmd, val);
   10768      1037100 :       if (parmd)
   10769      1037100 :         parmd = DECL_CHAIN (parmd);
   10770              :     }
   10771              : 
   10772              :   /* Ellipsis */
   10773    158429841 :   int magic = magic_varargs_p (fn);
   10774    161162828 :   for (; arg_index < vec_safe_length (args); ++arg_index)
   10775              :     {
   10776      2733008 :       tree a = (*args)[arg_index];
   10777      2733008 :       if ((magic == 3 && arg_index == 2) || (magic == 4 && arg_index == 0))
   10778              :         {
   10779              :           /* Do no conversions for certain magic varargs.  */
   10780       115245 :           a = mark_type_use (a);
   10781       115245 :           if (TREE_CODE (a) == FUNCTION_DECL && reject_gcc_builtin (a))
   10782            0 :             return error_mark_node;
   10783              :         }
   10784      2617763 :       else if (magic != 0)
   10785              :         {
   10786              :           /* Don't truncate excess precision to the semantic type.  */
   10787      1272678 :           if (magic == 1 && TREE_CODE (a) == EXCESS_PRECISION_EXPR)
   10788           84 :             a = TREE_OPERAND (a, 0);
   10789              :           /* For other magic varargs only do decay_conversion.  */
   10790      1272678 :           a = decay_conversion (a, complain);
   10791              :         }
   10792      1345085 :       else if (DECL_CONSTRUCTOR_P (fn)
   10793          384 :                && vec_safe_length (args) == 1
   10794      1345283 :                && same_type_ignoring_top_level_qualifiers_p (DECL_CONTEXT (fn),
   10795          198 :                                                              TREE_TYPE (a)))
   10796              :         {
   10797              :           /* Avoid infinite recursion trying to call A(...).  */
   10798            3 :           if (complain & tf_error)
   10799              :             /* Try to call the actual copy constructor for a good error.  */
   10800            3 :             call_copy_ctor (a, complain);
   10801            3 :           return error_mark_node;
   10802              :         }
   10803              :       else
   10804      1345082 :         a = convert_arg_to_ellipsis (a, complain);
   10805      2733005 :       if (a == error_mark_node)
   10806              :         return error_mark_node;
   10807      2732987 :       argarray[argarray_size++] = a;
   10808              :     }
   10809              : 
   10810    158429820 :   gcc_assert (argarray_size <= nargs);
   10811    158429820 :   nargs = argarray_size;
   10812    158429820 :   icip.reset ();
   10813              : 
   10814              :   /* Avoid performing argument transformation if warnings are disabled.
   10815              :      When tf_warning is set and at least one of the warnings is active
   10816              :      the check_function_arguments function might warn about something.  */
   10817              : 
   10818    158429820 :   bool warned_p = false;
   10819    158429820 :   if ((complain & tf_warning)
   10820    105748320 :       && (warn_nonnull
   10821    103793616 :           || warn_format
   10822    103793613 :           || warn_suggest_attribute_format
   10823    103793517 :           || warn_restrict))
   10824              :     {
   10825      1957050 :       tree *fargs = (!nargs ? argarray
   10826      1615906 :                             : (tree *) alloca (nargs * sizeof (tree)));
   10827      5953934 :       for (int j = 0; j < nargs; j++)
   10828              :         {
   10829              :           /* For -Wformat undo the implicit passing by hidden reference
   10830              :              done by convert_arg_to_ellipsis.  */
   10831      3996884 :           if (TREE_CODE (argarray[j]) == ADDR_EXPR
   10832      3996884 :               && TYPE_REF_P (TREE_TYPE (argarray[j])))
   10833         1488 :             fargs[j] = TREE_OPERAND (argarray[j], 0);
   10834              :           else
   10835      3995396 :             fargs[j] = argarray[j];
   10836              :         }
   10837              : 
   10838      1957050 :       warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn),
   10839              :                                            nargs, fargs, NULL,
   10840              :                                            cp_comp_parm_types);
   10841              :     }
   10842              : 
   10843    316859640 :   if (DECL_INHERITED_CTOR (fn))
   10844              :     {
   10845              :       /* Check for passing ellipsis arguments to an inherited constructor.  We
   10846              :          could handle this by open-coding the inherited constructor rather than
   10847              :          defining it, but let's not bother now.  */
   10848        60894 :       if (!cp_unevaluated_operand
   10849        60609 :           && cand->num_convs
   10850        60609 :           && cand->convs[cand->num_convs-1]->ellipsis_p)
   10851              :         {
   10852           15 :           if (complain & tf_error)
   10853              :             {
   10854           15 :               auto_diagnostic_group d;
   10855           15 :               sorry ("passing arguments to ellipsis of inherited constructor "
   10856              :                      "%qD", cand->fn);
   10857           15 :               inform (DECL_SOURCE_LOCATION (cand->fn), "declared here");
   10858           15 :             }
   10859           15 :           return error_mark_node;
   10860              :         }
   10861              : 
   10862              :       /* A base constructor inheriting from a virtual base doesn't get the
   10863              :          inherited arguments, just this and __vtt.  */
   10864        60879 :       if (ctor_omit_inherited_parms (fn))
   10865    158429805 :         nargs = 2;
   10866              :     }
   10867              : 
   10868              :   /* Avoid actually calling copy constructors and copy assignment operators,
   10869              :      if possible.  */
   10870              : 
   10871    158429805 :   if (!force_elide
   10872    158300716 :       && (!flag_elide_constructors
   10873              :           /* It's unsafe to elide the operation when handling
   10874              :              a noexcept-expression, it may evaluate to the wrong
   10875              :              value (c++/53025, c++/96090).  */
   10876    158300512 :           || cp_noexcept_operand != 0))
   10877              :     /* Do things the hard way.  */;
   10878    155886323 :   else if (cand->num_convs == 1
   10879    238253120 :            && (DECL_COPY_CONSTRUCTOR_P (fn)
   10880    155040446 :                || DECL_MOVE_CONSTRUCTOR_P (fn)))
   10881              :     {
   10882      7515180 :       tree targ;
   10883      7515180 :       tree arg = argarray[num_artificial_parms_for (fn)];
   10884      7515180 :       tree fa = argarray[0];
   10885      7515180 :       bool trivial = trivial_fn_p (fn);
   10886              : 
   10887              :       /* Pull out the real argument, disregarding const-correctness.  */
   10888      7515180 :       targ = arg;
   10889              :       /* Strip the reference binding for the constructor parameter.  */
   10890            0 :       if (CONVERT_EXPR_P (targ)
   10891      7515180 :           && TYPE_REF_P (TREE_TYPE (targ)))
   10892      7515180 :         targ = TREE_OPERAND (targ, 0);
   10893              :       /* But don't strip any other reference bindings; binding a temporary to a
   10894              :          reference prevents copy elision.  */
   10895     12490033 :       while ((CONVERT_EXPR_P (targ)
   10896     10534709 :               && !TYPE_REF_P (TREE_TYPE (targ)))
   10897     26231762 :              || TREE_CODE (targ) == NON_LVALUE_EXPR)
   10898      9456803 :         targ = TREE_OPERAND (targ, 0);
   10899      7515180 :       if (TREE_CODE (targ) == ADDR_EXPR)
   10900              :         {
   10901      2222037 :           targ = TREE_OPERAND (targ, 0);
   10902      2222037 :           if (!same_type_ignoring_top_level_qualifiers_p
   10903      2222037 :               (TREE_TYPE (TREE_TYPE (arg)), TREE_TYPE (targ)))
   10904              :             targ = NULL_TREE;
   10905              :         }
   10906              :       else
   10907              :         targ = NULL_TREE;
   10908              : 
   10909      2221585 :       if (targ)
   10910              :         arg = targ;
   10911              :       else
   10912      5293595 :         arg = cp_build_fold_indirect_ref (arg);
   10913              : 
   10914              :       /* In C++17 we shouldn't be copying a TARGET_EXPR except into a
   10915              :          potentially-overlapping subobject.  */
   10916      7515180 :       if (CHECKING_P && cxx_dialect >= cxx17)
   10917      7439367 :         gcc_assert (TREE_CODE (arg) != TARGET_EXPR
   10918              :                     || force_elide
   10919              :                     /* It's from binding the ref parm to a packed field. */
   10920              :                     || convs[0]->need_temporary_p
   10921              :                     || seen_error ()
   10922              :                     /* See unsafe_copy_elision_p.  */
   10923              :                     || unsafe_return_slot_p (fa));
   10924              : 
   10925      7515180 :       bool unsafe = unsafe_copy_elision_p_opt (fa, arg);
   10926      7515180 :       bool eliding_temp = (TREE_CODE (arg) == TARGET_EXPR && !unsafe);
   10927              : 
   10928              :       /* [class.copy]: the copy constructor is implicitly defined even if the
   10929              :          implementation elided its use.  But don't warn about deprecation when
   10930              :          eliding a temporary, as then no copy is actually performed.  */
   10931      7515180 :       warning_sentinel s (warn_deprecated_copy, eliding_temp);
   10932      7515180 :       if (force_elide)
   10933              :         /* The language says this isn't called.  */;
   10934      7386091 :       else if (!trivial)
   10935              :         {
   10936      1279516 :           if (!mark_used (fn, complain) && !(complain & tf_error))
   10937            0 :             return error_mark_node;
   10938              :           already_used = true;
   10939              :         }
   10940              :       else
   10941      6106575 :         cp_handle_deprecated_or_unavailable (fn, complain);
   10942              : 
   10943       188193 :       if (eliding_temp && DECL_BASE_CONSTRUCTOR_P (fn)
   10944      7515369 :           && !make_base_init_ok (arg))
   10945              :         unsafe = true;
   10946              : 
   10947              :       /* If we're creating a temp and we already have one, don't create a
   10948              :          new one.  If we're not creating a temp but we get one, use
   10949              :          INIT_EXPR to collapse the temp into our target.  Otherwise, if the
   10950              :          ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
   10951              :          temp or an INIT_EXPR otherwise.  */
   10952      7515180 :       if (is_dummy_object (fa))
   10953              :         {
   10954      5498867 :           if (TREE_CODE (arg) == TARGET_EXPR)
   10955              :             return arg;
   10956      5340569 :           else if (trivial)
   10957      4806092 :             return force_target_expr (DECL_CONTEXT (fn), arg, complain);
   10958              :         }
   10959      2016313 :       else if ((trivial || TREE_CODE (arg) == TARGET_EXPR)
   10960      1277526 :                && !unsafe)
   10961              :         {
   10962      1277438 :           tree to = cp_build_fold_indirect_ref (fa);
   10963      1277438 :           val = cp_build_init_expr (to, arg);
   10964      1277438 :           return val;
   10965              :         }
   10966      7515180 :     }
   10967    148371143 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
   10968      3010881 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR)
   10969    150414423 :            && trivial_fn_p (fn))
   10970              :     {
   10971      1356355 :       tree to = cp_build_fold_indirect_ref (argarray[0]);
   10972      1356355 :       tree type = TREE_TYPE (to);
   10973      1356355 :       tree as_base = CLASSTYPE_AS_BASE (type);
   10974      1356355 :       tree arg = argarray[1];
   10975      1356355 :       location_t loc = cp_expr_loc_or_input_loc (arg);
   10976              : 
   10977      1356355 :       if (is_really_empty_class (type, /*ignore_vptr*/true))
   10978              :         {
   10979              :           /* Avoid copying empty classes, but ensure op= returns an lvalue even
   10980              :              if the object argument isn't one.  */
   10981       226791 :           to = force_lvalue (to, complain);
   10982       226791 :           val = build2 (COMPOUND_EXPR, type, arg, to);
   10983       226791 :           suppress_warning (val, OPT_Wunused);
   10984              :         }
   10985      1129564 :       else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
   10986              :         {
   10987       862711 :           if (is_std_init_list (type)
   10988       862711 :               && conv_binds_ref_to_prvalue (convs[1]))
   10989            3 :             warning_at (loc, OPT_Winit_list_lifetime,
   10990              :                         "assignment from temporary %<initializer_list%> does "
   10991              :                         "not extend the lifetime of the underlying array");
   10992       862711 :           arg = cp_build_fold_indirect_ref (arg);
   10993       862711 :           val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
   10994              :         }
   10995              :       else
   10996              :         {
   10997              :           /* We must only copy the non-tail padding parts.  */
   10998       266853 :           tree arg0, arg2, t;
   10999       266853 :           tree array_type, alias_set;
   11000              : 
   11001       266853 :           arg2 = TYPE_SIZE_UNIT (as_base);
   11002              :           /* Ensure op= returns an lvalue even if the object argument isn't
   11003              :              one.  */
   11004       266853 :           to = force_lvalue (to, complain);
   11005       266853 :           to = cp_stabilize_reference (to);
   11006       266853 :           arg0 = cp_build_addr_expr (to, complain);
   11007              : 
   11008       266853 :           array_type = build_array_type (unsigned_char_type_node,
   11009              :                                          build_index_type
   11010              :                                            (size_binop (MINUS_EXPR,
   11011              :                                                         arg2, size_int (1))));
   11012       266853 :           alias_set = build_int_cst (build_pointer_type (type), 0);
   11013       266853 :           t = build2 (MODIFY_EXPR, void_type_node,
   11014              :                       build2 (MEM_REF, array_type, arg0, alias_set),
   11015              :                       build2 (MEM_REF, array_type, arg, alias_set));
   11016       266853 :           val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to);
   11017       266853 :           suppress_warning (val, OPT_Wunused);
   11018              :         }
   11019              : 
   11020      1356355 :       cp_handle_deprecated_or_unavailable (fn, complain);
   11021              : 
   11022      1356355 :       return val;
   11023              :     }
   11024    147014788 :   else if (trivial_fn_p (fn))
   11025              :     {
   11026      7465930 :       if (DECL_DESTRUCTOR_P (fn))
   11027      3024428 :         return build_trivial_dtor_call (argarray[0]);
   11028       708537 :       else if (default_ctor_p (fn))
   11029              :         {
   11030       708537 :           if (is_dummy_object (argarray[0]))
   11031       266095 :             return force_target_expr (DECL_CONTEXT (fn), void_node,
   11032       266095 :                                       no_cleanup_complain);
   11033              :           else
   11034       442442 :             return cp_build_fold_indirect_ref (argarray[0]);
   11035              :         }
   11036              :     }
   11037              : 
   11038    147098657 :   gcc_assert (!force_elide);
   11039              : 
   11040    147098657 :   if (!already_used
   11041    147098657 :       && !mark_used (fn, complain))
   11042          794 :     return error_mark_node;
   11043              : 
   11044              :   /* Warn if the built-in writes to an object of a non-trivial type.  */
   11045    147097860 :   if (warn_class_memaccess
   11046      1998512 :       && vec_safe_length (args) >= 2
   11047    148058492 :       && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
   11048        69369 :     maybe_warn_class_memaccess (input_location, fn, args);
   11049              : 
   11050    147097860 :   if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
   11051              :     {
   11052       470170 :       tree t;
   11053       470170 :       tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (argarray[0])),
   11054       470170 :                                 DECL_CONTEXT (fn),
   11055              :                                 ba_any, NULL, complain);
   11056       470170 :       gcc_assert (binfo && binfo != error_mark_node);
   11057              : 
   11058       470170 :       argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1,
   11059              :                                      complain);
   11060       470170 :       if (TREE_SIDE_EFFECTS (argarray[0]))
   11061        44804 :         argarray[0] = save_expr (argarray[0]);
   11062       470170 :       t = build_pointer_type (TREE_TYPE (fn));
   11063       470170 :       fn = build_vfn_ref (argarray[0], DECL_VINDEX (fn));
   11064       470170 :       TREE_TYPE (fn) = t;
   11065              :     }
   11066              :   else
   11067              :     {
   11068              :       /* If FN is marked deprecated or unavailable, then we've already
   11069              :          issued a diagnostic from mark_used above, so avoid redundantly
   11070              :          issuing another one from build_addr_func.  */
   11071    146627690 :       auto w = make_temp_override (deprecated_state,
   11072    146627690 :                                    UNAVAILABLE_DEPRECATED_SUPPRESS);
   11073              : 
   11074    146627690 :       fn = build_addr_func (fn, complain);
   11075    146627690 :       if (fn == error_mark_node)
   11076            0 :         return error_mark_node;
   11077              : 
   11078              :       /* We're actually invoking the function.  (Immediate functions get an
   11079              :          & when invoking it even though the user didn't use &.)  */
   11080    146627690 :       ADDR_EXPR_DENOTES_CALL_P (fn) = true;
   11081    146627690 :     }
   11082              : 
   11083    147097860 :   tree call = build_cxx_call (fn, nargs, argarray, complain|decltype_flag);
   11084    147097860 :   if (call == error_mark_node)
   11085              :     return call;
   11086    147096889 :   if (cand->flags & LOOKUP_LIST_INIT_CTOR)
   11087              :     {
   11088      1933444 :       tree c = extract_call_expr (call);
   11089              :       /* build_new_op will clear this when appropriate.  */
   11090      1933444 :       CALL_EXPR_ORDERED_ARGS (c) = true;
   11091              :     }
   11092    147096889 :   if (warned_p)
   11093              :     {
   11094          253 :       tree c = extract_call_expr (call);
   11095          253 :       if (TREE_CODE (c) == CALL_EXPR)
   11096          253 :         suppress_warning (c /* Suppress all warnings.  */);
   11097              :     }
   11098    147096636 :   else if (TREE_DEPRECATED (fn)
   11099    147096636 :            && warning_suppressed_at (input_location,
   11100              :                                      OPT_Wdeprecated_declarations))
   11101              :     {
   11102            0 :       tree c = extract_call_expr (call);
   11103            0 :       if (TREE_CODE (c) == CALL_EXPR)
   11104            0 :         TREE_NO_WARNING (c) = true;
   11105              :     }
   11106              : 
   11107              :   return call;
   11108              : }
   11109              : 
   11110              : namespace
   11111              : {
   11112              : 
   11113              : /* Return the DECL of the first non-static subobject of class TYPE
   11114              :    that satisfies the predicate PRED or null if none can be found.  */
   11115              : 
   11116              : template <class Predicate>
   11117              : tree
   11118         3556 : first_non_static_field (tree type, Predicate pred)
   11119              : {
   11120         3556 :   if (!type || !CLASS_TYPE_P (type))
   11121              :     return NULL_TREE;
   11122              : 
   11123        71398 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   11124              :     {
   11125        68436 :       if (TREE_CODE (field) != FIELD_DECL)
   11126        43330 :         continue;
   11127        25106 :       if (TREE_STATIC (field))
   11128            0 :         continue;
   11129        25106 :       if (pred (field))
   11130              :         return field;
   11131              :     }
   11132              : 
   11133         2962 :   int i = 0;
   11134              : 
   11135         3082 :   for (tree base_binfo, binfo = TYPE_BINFO (type);
   11136         3082 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   11137              :     {
   11138          126 :       tree base = TREE_TYPE (base_binfo);
   11139          126 :       if (pred (base))
   11140              :         return base;
   11141          120 :       if (tree field = first_non_static_field (base, pred))
   11142              :         return field;
   11143              :     }
   11144              : 
   11145              :   return NULL_TREE;
   11146              : }
   11147              : 
   11148              : struct NonPublicField
   11149              : {
   11150        24356 :   bool operator() (const_tree t) const
   11151              :   {
   11152        24356 :     return DECL_P (t) && (TREE_PRIVATE (t) || TREE_PROTECTED (t));
   11153              :   }
   11154              : };
   11155              : 
   11156              : /* Return the DECL of the first non-public subobject of class TYPE
   11157              :    or null if none can be found.  */
   11158              : 
   11159              : static inline tree
   11160         3262 : first_non_public_field (tree type)
   11161              : {
   11162         3262 :   return first_non_static_field (type, NonPublicField ());
   11163              : }
   11164              : 
   11165              : struct NonTrivialField
   11166              : {
   11167          876 :   bool operator() (const_tree t) const
   11168              :   {
   11169          876 :     return !trivial_type_p (DECL_P (t) ? TREE_TYPE (t) : t);
   11170              :   }
   11171              : };
   11172              : 
   11173              : /* Return the DECL of the first non-trivial subobject of class TYPE
   11174              :    or null if none can be found.  */
   11175              : 
   11176              : static inline tree
   11177          174 : first_non_trivial_field (tree type)
   11178              : {
   11179          174 :   return first_non_static_field (type, NonTrivialField ());
   11180              : }
   11181              : 
   11182              : }   /* unnamed namespace */
   11183              : 
   11184              : /* Return true if all copy and move assignment operator overloads for
   11185              :    class TYPE are trivial and at least one of them is not deleted and,
   11186              :    when ACCESS is set, accessible.  Return false otherwise.  Set
   11187              :    HASASSIGN to true when the TYPE has a (not necessarily trivial)
   11188              :    copy or move assignment.  */
   11189              : 
   11190              : static bool
   11191         5021 : has_trivial_copy_assign_p (tree type, bool access, bool *hasassign)
   11192              : {
   11193         5021 :   tree fns = get_class_binding (type, assign_op_identifier);
   11194         5021 :   bool all_trivial = true;
   11195              : 
   11196              :   /* Iterate over overloads of the assignment operator, checking
   11197              :      accessible copy assignments for triviality.  */
   11198              : 
   11199        16515 :   for (tree f : ovl_range (fns))
   11200              :     {
   11201              :       /* Skip operators that aren't copy assignments.  */
   11202         8571 :       if (!copy_fn_p (f))
   11203         3046 :         continue;
   11204              : 
   11205         5525 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11206         5813 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11207              : 
   11208              :       /* Skip template assignment operators and deleted functions.  */
   11209         5525 :       if (TREE_CODE (f) != FUNCTION_DECL || DECL_DELETED_FN (f))
   11210          694 :         continue;
   11211              : 
   11212         4831 :       if (accessible)
   11213         4579 :         *hasassign = true;
   11214              : 
   11215         4579 :       if (!accessible || !trivial_fn_p (f))
   11216              :         all_trivial = false;
   11217              : 
   11218              :       /* Break early when both properties have been determined.  */
   11219         4831 :       if (*hasassign && !all_trivial)
   11220              :         break;
   11221              :     }
   11222              : 
   11223              :   /* Return true if they're all trivial and one of the expressions
   11224              :      TYPE() = TYPE() or TYPE() = (TYPE&)() is valid.  */
   11225         5021 :   tree ref = cp_build_reference_type (type, false);
   11226         5021 :   return (all_trivial
   11227         5021 :           && (is_trivially_xible (MODIFY_EXPR, type, type)
   11228          333 :               || is_trivially_xible (MODIFY_EXPR, type, ref)));
   11229              : }
   11230              : 
   11231              : /* Return true if all copy and move ctor overloads for class TYPE are
   11232              :    trivial and at least one of them is not deleted and, when ACCESS is
   11233              :    set, accessible.  Return false otherwise.  Set each element of HASCTOR[]
   11234              :    to true when the TYPE has a (not necessarily trivial) default and copy
   11235              :    (or move) ctor, respectively.  */
   11236              : 
   11237              : static bool
   11238         5021 : has_trivial_copy_p (tree type, bool access, bool hasctor[2])
   11239              : {
   11240         5021 :   tree fns = get_class_binding (type, complete_ctor_identifier);
   11241         5021 :   bool all_trivial = true;
   11242              : 
   11243        25141 :   for (tree f : ovl_range (fns))
   11244              :     {
   11245              :       /* Skip template constructors.  */
   11246        12602 :       if (TREE_CODE (f) != FUNCTION_DECL)
   11247          105 :         continue;
   11248              : 
   11249        12497 :       bool cpy_or_move_ctor_p = copy_fn_p (f);
   11250              : 
   11251              :       /* Skip ctors other than default, copy, and move.  */
   11252        12497 :       if (!cpy_or_move_ctor_p && !default_ctor_p (f))
   11253         2757 :         continue;
   11254              : 
   11255         9740 :       if (DECL_DELETED_FN (f))
   11256          306 :         continue;
   11257              : 
   11258         9434 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11259         9626 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11260              : 
   11261         9314 :       if (accessible)
   11262         9314 :         hasctor[cpy_or_move_ctor_p] = true;
   11263              : 
   11264         9434 :       if (cpy_or_move_ctor_p && (!accessible || !trivial_fn_p (f)))
   11265              :         all_trivial = false;
   11266              : 
   11267              :       /* Break early when both properties have been determined.  */
   11268         9434 :       if (hasctor[0] && hasctor[1] && !all_trivial)
   11269              :         break;
   11270              :     }
   11271              : 
   11272         5021 :   return all_trivial;
   11273              : }
   11274              : 
   11275              : /* Issue a warning on a call to the built-in function FNDECL if it is
   11276              :    a raw memory write whose destination is not an object of (something
   11277              :    like) trivial or standard layout type with a non-deleted assignment
   11278              :    and copy ctor.  Detects const correctness violations, corrupting
   11279              :    references, virtual table pointers, and bypassing non-trivial
   11280              :    assignments.  */
   11281              : 
   11282              : static void
   11283        69369 : maybe_warn_class_memaccess (location_t loc, tree fndecl,
   11284              :                             const vec<tree, va_gc> *args)
   11285              : {
   11286              :   /* Except for bcopy where it's second, the destination pointer is
   11287              :      the first argument for all functions handled here.  Compute
   11288              :      the index of the destination and source arguments.  */
   11289        69369 :   unsigned dstidx = DECL_FUNCTION_CODE (fndecl) == BUILT_IN_BCOPY;
   11290        69369 :   unsigned srcidx = !dstidx;
   11291              : 
   11292        69369 :   tree dest = (*args)[dstidx];
   11293        69369 :   if (!TREE_TYPE (dest)
   11294        69369 :       || (TREE_CODE (TREE_TYPE (dest)) != ARRAY_TYPE
   11295        68204 :           && !INDIRECT_TYPE_P (TREE_TYPE (dest))))
   11296        65994 :     return;
   11297              : 
   11298        22193 :   tree srctype = NULL_TREE;
   11299              : 
   11300              :   /* Determine the type of the pointed-to object and whether it's
   11301              :      a complete class type.  */
   11302        22193 :   tree desttype = TREE_TYPE (TREE_TYPE (dest));
   11303              : 
   11304        22193 :   if (!desttype || !COMPLETE_TYPE_P (desttype) || !CLASS_TYPE_P (desttype))
   11305              :     return;
   11306              : 
   11307              :   /* Check to see if the raw memory call is made by a non-static member
   11308              :      function with THIS as the destination argument for the destination
   11309              :      type.  If so, and if the class has no non-trivial bases or members,
   11310              :      be more permissive.  */
   11311         5123 :   if (current_function_decl
   11312         5123 :       && DECL_OBJECT_MEMBER_FUNCTION_P (current_function_decl)
   11313         5390 :       && is_object_parameter (tree_strip_nop_conversions (dest)))
   11314              :     {
   11315          204 :       tree ctx = DECL_CONTEXT (current_function_decl);
   11316          204 :       bool special = same_type_ignoring_top_level_qualifiers_p (ctx, desttype);
   11317          204 :       tree binfo = TYPE_BINFO (ctx);
   11318              : 
   11319          204 :       if (special
   11320          204 :           && !BINFO_VTABLE (binfo)
   11321          378 :           && !first_non_trivial_field (desttype))
   11322              :         return;
   11323              :     }
   11324              : 
   11325              :   /* True if the class is trivial.  */
   11326         5021 :   bool trivial = trivial_type_p (desttype);
   11327              : 
   11328              :   /* Set to true if DESTYPE has an accessible copy assignment.  */
   11329         5021 :   bool hasassign = false;
   11330              :   /* True if all of the class' overloaded copy assignment operators
   11331              :      are all trivial (and not deleted) and at least one of them is
   11332              :      accessible.  */
   11333         5021 :   bool trivassign = has_trivial_copy_assign_p (desttype, true, &hasassign);
   11334              : 
   11335              :   /* Set to true if DESTTYPE has an accessible default and copy ctor,
   11336              :      respectively.  */
   11337         5021 :   bool hasctors[2] = { false, false };
   11338              : 
   11339              :   /* True if all of the class' overloaded copy constructors are all
   11340              :      trivial (and not deleted) and at least one of them is accessible.  */
   11341         5021 :   bool trivcopy = has_trivial_copy_p (desttype, true, hasctors);
   11342              : 
   11343              :   /* Set FLD to the first private/protected member of the class.  */
   11344         5021 :   tree fld = trivial ? first_non_public_field (desttype) : NULL_TREE;
   11345              : 
   11346              :   /* The warning format string.  */
   11347         5021 :   const char *warnfmt = NULL;
   11348              :   /* A suggested alternative to offer instead of the raw memory call.
   11349              :      Empty string when none can be come up with.  */
   11350         5021 :   const char *suggest = "";
   11351         5021 :   bool warned = false;
   11352              : 
   11353         5021 :   auto_diagnostic_group d;
   11354         5021 :   switch (DECL_FUNCTION_CODE (fndecl))
   11355              :     {
   11356          560 :     case BUILT_IN_MEMSET:
   11357          560 :       if (!integer_zerop (maybe_constant_value ((*args)[1])))
   11358              :         {
   11359              :           /* Diagnose setting non-copy-assignable or non-trivial types,
   11360              :              or types with a private member, to (potentially) non-zero
   11361              :              bytes.  Since the value of the bytes being written is unknown,
   11362              :              suggest using assignment instead (if one exists).  Also warn
   11363              :              for writes into objects for which zero-initialization doesn't
   11364              :              mean all bits clear (pointer-to-member data, where null is all
   11365              :              bits set).  Since the value being written is (most likely)
   11366              :              non-zero, simply suggest assignment (but not copy assignment).  */
   11367          196 :           suggest = "; use assignment instead";
   11368          196 :           if (!trivassign)
   11369              :             warnfmt = G_("%qD writing to an object of type %#qT with "
   11370              :                          "no trivial copy-assignment");
   11371          125 :           else if (!trivial)
   11372              :             warnfmt = G_("%qD writing to an object of non-trivial type %#qT%s");
   11373           85 :           else if (fld)
   11374              :             {
   11375           24 :               const char *access = TREE_PRIVATE (fld) ? "private" : "protected";
   11376           24 :               warned = warning_at (loc, OPT_Wclass_memaccess,
   11377              :                                    "%qD writing to an object of type %#qT with "
   11378              :                                    "%qs member %qD",
   11379              :                                    fndecl, desttype, access, fld);
   11380              :             }
   11381           61 :           else if (!zero_init_p (desttype))
   11382              :             warnfmt = G_("%qD writing to an object of type %#qT containing "
   11383              :                          "a pointer to data member%s");
   11384              : 
   11385              :           break;
   11386              :         }
   11387              :       /* Fall through.  */
   11388              : 
   11389          481 :     case BUILT_IN_BZERO:
   11390              :       /* Similarly to the above, diagnose clearing non-trivial or non-
   11391              :          standard layout objects, or objects of types with no assignmenmt.
   11392              :          Since the value being written is known to be zero, suggest either
   11393              :          copy assignment, copy ctor, or default ctor as an alternative,
   11394              :          depending on what's available.  */
   11395              : 
   11396          481 :       if (hasassign && hasctors[0])
   11397              :         suggest = G_("; use assignment or value-initialization instead");
   11398           49 :       else if (hasassign)
   11399              :         suggest = G_("; use assignment instead");
   11400           31 :       else if (hasctors[0])
   11401           16 :         suggest = G_("; use value-initialization instead");
   11402              : 
   11403          481 :       if (!trivassign)
   11404              :         warnfmt = G_("%qD clearing an object of type %#qT with "
   11405              :                      "no trivial copy-assignment%s");
   11406          374 :       else if (!trivial)
   11407              :         warnfmt =  G_("%qD clearing an object of non-trivial type %#qT%s");
   11408          304 :       else if (!zero_init_p (desttype))
   11409              :         warnfmt = G_("%qD clearing an object of type %#qT containing "
   11410              :                      "a pointer-to-member%s");
   11411              :       break;
   11412              : 
   11413         2437 :     case BUILT_IN_BCOPY:
   11414         2437 :     case BUILT_IN_MEMCPY:
   11415         2437 :     case BUILT_IN_MEMMOVE:
   11416         2437 :     case BUILT_IN_MEMPCPY:
   11417              :       /* Determine the type of the source object.  */
   11418         2437 :       srctype = TREE_TYPE ((*args)[srcidx]);
   11419         2437 :       if (!srctype || !INDIRECT_TYPE_P (srctype))
   11420            0 :         srctype = void_type_node;
   11421              :       else
   11422         2437 :         srctype = TREE_TYPE (srctype);
   11423              : 
   11424              :       /* Since it's impossible to determine whether the byte copy is
   11425              :          being used in place of assignment to an existing object or
   11426              :          as a substitute for initialization, assume it's the former.
   11427              :          Determine the best alternative to use instead depending on
   11428              :          what's not deleted.  */
   11429         2437 :       if (hasassign && hasctors[1])
   11430              :         suggest = G_("; use copy-assignment or copy-initialization instead");
   11431          488 :       else if (hasassign)
   11432              :         suggest = G_("; use copy-assignment instead");
   11433          341 :       else if (hasctors[1])
   11434          290 :         suggest = G_("; use copy-initialization instead");
   11435              : 
   11436         2437 :       if (!trivassign)
   11437              :         warnfmt = G_("%qD writing to an object of type %#qT with no trivial "
   11438              :                      "copy-assignment%s");
   11439         1639 :       else if (!trivially_copyable_p (desttype))
   11440              :         warnfmt = G_("%qD writing to an object of non-trivially copyable "
   11441              :                      "type %#qT%s");
   11442         1315 :       else if (!trivcopy)
   11443              :         warnfmt = G_("%qD writing to an object with a deleted copy constructor");
   11444              : 
   11445         1315 :       else if (!trivial
   11446          211 :                && !VOID_TYPE_P (srctype)
   11447          160 :                && !is_byte_access_type (srctype)
   11448         1412 :                && !same_type_ignoring_top_level_qualifiers_p (desttype,
   11449              :                                                               srctype))
   11450              :         {
   11451              :           /* Warn when copying into a non-trivial object from an object
   11452              :              of a different type other than void or char.  */
   11453           54 :           warned = warning_at (loc, OPT_Wclass_memaccess,
   11454              :                                "%qD copying an object of non-trivial type "
   11455              :                                "%#qT from an array of %#qT",
   11456              :                                fndecl, desttype, srctype);
   11457              :         }
   11458         1261 :       else if (fld
   11459          432 :                && !VOID_TYPE_P (srctype)
   11460          384 :                && !is_byte_access_type (srctype)
   11461         1549 :                && !same_type_ignoring_top_level_qualifiers_p (desttype,
   11462              :                                                               srctype))
   11463              :         {
   11464          216 :           const char *access = TREE_PRIVATE (fld) ? "private" : "protected";
   11465          216 :           warned = warning_at (loc, OPT_Wclass_memaccess,
   11466              :                                "%qD copying an object of type %#qT with "
   11467              :                                "%qs member %qD from an array of %#qT; use "
   11468              :                                "assignment or copy-initialization instead",
   11469              :                                fndecl, desttype, access, fld, srctype);
   11470              :         }
   11471         1045 :       else if (!trivial && vec_safe_length (args) > 2)
   11472              :         {
   11473          157 :           tree sz = maybe_constant_value ((*args)[2]);
   11474          157 :           if (!tree_fits_uhwi_p (sz))
   11475              :             break;
   11476              : 
   11477              :           /* Finally, warn on partial copies.  */
   11478           99 :           unsigned HOST_WIDE_INT typesize
   11479           99 :             = tree_to_uhwi (TYPE_SIZE_UNIT (desttype));
   11480           99 :           if (typesize == 0)
   11481              :             break;
   11482           96 :           if (unsigned HOST_WIDE_INT partial = tree_to_uhwi (sz) % typesize)
   11483           12 :             warned = warning_at (loc, OPT_Wclass_memaccess,
   11484              :                                  (typesize - partial > 1
   11485              :                                   ? G_("%qD writing to an object of "
   11486              :                                        "a non-trivial type %#qT leaves %wu "
   11487              :                                        "bytes unchanged")
   11488              :                                   : G_("%qD writing to an object of "
   11489              :                                        "a non-trivial type %#qT leaves %wu "
   11490              :                                        "byte unchanged")),
   11491              :                                  fndecl, desttype, typesize - partial);
   11492              :         }
   11493              :       break;
   11494              : 
   11495          261 :     case BUILT_IN_REALLOC:
   11496              : 
   11497          261 :       if (!trivially_copyable_p (desttype))
   11498              :         warnfmt = G_("%qD moving an object of non-trivially copyable type "
   11499              :                      "%#qT; use %<new%> and %<delete%> instead");
   11500          138 :       else if (!trivcopy)
   11501              :         warnfmt = G_("%qD moving an object of type %#qT with deleted copy "
   11502              :                      "constructor; use %<new%> and %<delete%> instead");
   11503          135 :       else if (!get_dtor (desttype, tf_none))
   11504              :         warnfmt = G_("%qD moving an object of type %#qT with deleted "
   11505              :                      "destructor");
   11506          126 :       else if (!trivial)
   11507              :         {
   11508           33 :           tree sz = maybe_constant_value ((*args)[1]);
   11509           33 :           if (TREE_CODE (sz) == INTEGER_CST
   11510           33 :               && tree_int_cst_lt (sz, TYPE_SIZE_UNIT (desttype)))
   11511              :             /* Finally, warn on reallocation into insufficient space.  */
   11512            7 :             warned = warning_at (loc, OPT_Wclass_memaccess,
   11513              :                                  "%qD moving an object of non-trivial type "
   11514              :                                  "%#qT and size %E into a region of size %E",
   11515            7 :                                  fndecl, desttype, TYPE_SIZE_UNIT (desttype),
   11516              :                                  sz);
   11517              :         }
   11518              :       break;
   11519              : 
   11520         1646 :     default:
   11521         1646 :       return;
   11522              :     }
   11523              : 
   11524          310 :   if (warnfmt)
   11525              :     {
   11526         1569 :       if (suggest)
   11527         1569 :         warned = warning_at (loc, OPT_Wclass_memaccess,
   11528              :                              warnfmt, fndecl, desttype, suggest);
   11529              :       else
   11530              :         warned = warning_at (loc, OPT_Wclass_memaccess,
   11531              :                              warnfmt, fndecl, desttype);
   11532              :     }
   11533              : 
   11534         3375 :   if (warned)
   11535         1879 :     inform (location_of (desttype), "%#qT declared here", desttype);
   11536         5021 : }
   11537              : 
   11538              : /* Build and return a call to FN, using NARGS arguments in ARGARRAY.
   11539              :    If FN is the result of resolving an overloaded target built-in,
   11540              :    ORIG_FNDECL is the original function decl, otherwise it is null.
   11541              :    This function performs no overload resolution, conversion, or other
   11542              :    high-level operations.  */
   11543              : 
   11544              : tree
   11545    155417477 : build_cxx_call (tree fn, int nargs, tree *argarray,
   11546              :                 tsubst_flags_t complain, tree orig_fndecl)
   11547              : {
   11548    155417477 :   tree fndecl;
   11549              : 
   11550              :   /* Remember roughly where this call is.  */
   11551    155417477 :   location_t loc = cp_expr_loc_or_input_loc (fn);
   11552    155417477 :   fn = build_call_a (fn, nargs, argarray);
   11553    155417477 :   SET_EXPR_LOCATION (fn, loc);
   11554              : 
   11555    155417477 :   fndecl = get_callee_fndecl (fn);
   11556    155417477 :   if (!orig_fndecl)
   11557    155417477 :     orig_fndecl = fndecl;
   11558              : 
   11559              :   /* Check that arguments to builtin functions match the expectations.  */
   11560    155417477 :   if (fndecl
   11561    149193899 :       && !processing_template_decl
   11562    304559682 :       && fndecl_built_in_p (fndecl))
   11563              :     {
   11564              :       int i;
   11565              : 
   11566              :       /* We need to take care that values to BUILT_IN_NORMAL
   11567              :          are reduced.  */
   11568     20936436 :       for (i = 0; i < nargs; i++)
   11569     13768851 :         argarray[i] = maybe_constant_value (argarray[i]);
   11570              : 
   11571      7167585 :       if (!check_builtin_function_arguments (EXPR_LOCATION (fn), vNULL, fndecl,
   11572              :                                              orig_fndecl, nargs, argarray,
   11573              :                                              complain & tf_error))
   11574          924 :         return error_mark_node;
   11575      7166661 :       else if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING))
   11576              :         {
   11577        12865 :           tree arg0 = argarray[0];
   11578        12865 :           STRIP_NOPS (arg0);
   11579        12865 :           if (TREE_CODE (arg0) == ADDR_EXPR
   11580          264 :               && DECL_P (TREE_OPERAND (arg0, 0))
   11581        13108 :               && same_type_ignoring_top_level_qualifiers_p
   11582          243 :                         (TREE_TYPE (TREE_TYPE (argarray[0])),
   11583          243 :                          TREE_TYPE (TREE_TYPE (arg0))))
   11584              :             /* For __builtin_clear_padding (&var) we know the type
   11585              :                is for a complete object, so there is no risk in clearing
   11586              :                padding that is reused in some derived class member.  */;
   11587        12629 :           else if (!trivially_copyable_p (TREE_TYPE (TREE_TYPE (argarray[0]))))
   11588              :             {
   11589           18 :               error_at (EXPR_LOC_OR_LOC (argarray[0], input_location),
   11590              :                         "argument %u in call to function %qE "
   11591              :                         "has pointer to a non-trivially-copyable type (%qT)",
   11592           18 :                         1, fndecl, TREE_TYPE (argarray[0]));
   11593           18 :               return error_mark_node;
   11594              :             }
   11595              :         }
   11596              :     }
   11597              : 
   11598    155416535 :   if (VOID_TYPE_P (TREE_TYPE (fn)))
   11599     35398265 :     return maybe_contract_wrap_call (fndecl, fn);
   11600              : 
   11601              :   /* 5.2.2/11: If a function call is a prvalue of object type: if the
   11602              :      function call is either the operand of a decltype-specifier or the
   11603              :      right operand of a comma operator that is the operand of a
   11604              :      decltype-specifier, a temporary object is not introduced for the
   11605              :      prvalue. The type of the prvalue may be incomplete.  */
   11606    120018270 :   if (!(complain & tf_decltype))
   11607              :     {
   11608    100568608 :       fn = require_complete_type (fn, complain);
   11609    100568608 :       if (fn == error_mark_node)
   11610              :         return error_mark_node;
   11611    100568582 :       fn = maybe_contract_wrap_call (fndecl, fn);
   11612              : 
   11613    100568582 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (fn)))
   11614              :         {
   11615     11466378 :           fn = build_cplus_new (TREE_TYPE (fn), fn, complain);
   11616     11466378 :           maybe_warn_parm_abi (TREE_TYPE (fn), loc);
   11617              :         }
   11618              :     }
   11619              :   else
   11620     19449662 :     fn = maybe_contract_wrap_call (fndecl, fn);
   11621    120018244 :   return convert_from_reference (fn);
   11622              : }
   11623              : 
   11624              : /* Returns the value to use for the in-charge parameter when making a
   11625              :    call to a function with the indicated NAME.
   11626              : 
   11627              :    FIXME:Can't we find a neater way to do this mapping?  */
   11628              : 
   11629              : tree
   11630        33146 : in_charge_arg_for_name (tree name)
   11631              : {
   11632        33146 :   if (IDENTIFIER_CTOR_P (name))
   11633              :     {
   11634        19228 :       if (name == complete_ctor_identifier)
   11635         9614 :         return integer_one_node;
   11636         9614 :       gcc_checking_assert (name == base_ctor_identifier);
   11637              :     }
   11638              :   else
   11639              :     {
   11640        13918 :       if (name == complete_dtor_identifier)
   11641         6959 :         return integer_two_node;
   11642         6959 :       else if (name == deleting_dtor_identifier)
   11643              :         /* The deleting dtor should now be handled by
   11644              :            build_delete_destructor_body.  */
   11645            0 :         gcc_unreachable ();
   11646         6959 :       gcc_checking_assert (name == base_dtor_identifier);
   11647              :     }
   11648              : 
   11649        16573 :   return integer_zero_node;
   11650              : }
   11651              : 
   11652              : /* We've built up a constructor call RET.  Complain if it delegates to the
   11653              :    constructor we're currently compiling.  */
   11654              : 
   11655              : static void
   11656       347650 : check_self_delegation (tree ret)
   11657              : {
   11658       347650 :   if (TREE_CODE (ret) == TARGET_EXPR)
   11659            0 :     ret = TARGET_EXPR_INITIAL (ret);
   11660       347650 :   tree fn = cp_get_callee_fndecl_nofold (ret);
   11661       347650 :   if (fn && DECL_ABSTRACT_ORIGIN (fn) == current_function_decl)
   11662           46 :     error ("constructor delegates to itself");
   11663       347650 : }
   11664              : 
   11665              : /* Build a call to a constructor, destructor, or an assignment
   11666              :    operator for INSTANCE, an expression with class type.  NAME
   11667              :    indicates the special member function to call; *ARGS are the
   11668              :    arguments.  ARGS may be NULL.  This may change ARGS.  BINFO
   11669              :    indicates the base of INSTANCE that is to be passed as the `this'
   11670              :    parameter to the member function called.
   11671              : 
   11672              :    FLAGS are the LOOKUP_* flags to use when processing the call.
   11673              : 
   11674              :    If NAME indicates a complete object constructor, INSTANCE may be
   11675              :    NULL_TREE.  In this case, the caller will call build_cplus_new to
   11676              :    store the newly constructed object into a VAR_DECL.  */
   11677              : 
   11678              : tree
   11679     37342468 : build_special_member_call (tree instance, tree name, vec<tree, va_gc> **args,
   11680              :                            tree binfo, int flags, tsubst_flags_t complain)
   11681              : {
   11682     37342468 :   tree fns;
   11683              :   /* The type of the subobject to be constructed or destroyed.  */
   11684     37342468 :   tree class_type;
   11685     37342468 :   vec<tree, va_gc> *allocated = NULL;
   11686     37342468 :   tree ret;
   11687              : 
   11688     37342468 :   gcc_assert (IDENTIFIER_CDTOR_P (name) || name == assign_op_identifier);
   11689              : 
   11690     37342468 :   if (error_operand_p (instance))
   11691            0 :     return error_mark_node;
   11692              : 
   11693     37342468 :   if (IDENTIFIER_DTOR_P (name))
   11694              :     {
   11695     10380991 :       gcc_assert (args == NULL || vec_safe_is_empty (*args));
   11696     10380991 :       if (!type_build_dtor_call (TREE_TYPE (instance)))
   11697              :         /* Shortcut to avoid lazy destructor declaration.  */
   11698         1423 :         return build_trivial_dtor_call (instance);
   11699              :     }
   11700              : 
   11701     37341045 :   if (TYPE_P (binfo))
   11702              :     {
   11703              :       /* Resolve the name.  */
   11704     29786213 :       if (!complete_type_or_maybe_complain (binfo, NULL_TREE, complain))
   11705           24 :         return error_mark_node;
   11706              : 
   11707     29786189 :       binfo = TYPE_BINFO (binfo);
   11708              :     }
   11709              : 
   11710     29786189 :   gcc_assert (binfo != NULL_TREE);
   11711              : 
   11712     37341021 :   class_type = BINFO_TYPE (binfo);
   11713              : 
   11714              :   /* Handle the special case where INSTANCE is NULL_TREE.  */
   11715     37341021 :   if (name == complete_ctor_identifier && !instance)
   11716     19582899 :     instance = build_dummy_object (class_type);
   11717              :   else
   11718              :     {
   11719              :       /* Convert to the base class, if necessary.  */
   11720     17758122 :       if (!same_type_ignoring_top_level_qualifiers_p
   11721     17758122 :           (TREE_TYPE (instance), BINFO_TYPE (binfo)))
   11722              :         {
   11723      1568760 :           if (IDENTIFIER_CDTOR_P (name))
   11724              :             /* For constructors and destructors, either the base is
   11725              :                non-virtual, or it is virtual but we are doing the
   11726              :                conversion from a constructor or destructor for the
   11727              :                complete object.  In either case, we can convert
   11728              :                statically.  */
   11729      1549657 :             instance = convert_to_base_statically (instance, binfo);
   11730              :           else
   11731              :             {
   11732              :               /* However, for assignment operators, we must convert
   11733              :                  dynamically if the base is virtual.  */
   11734        19103 :               gcc_checking_assert (name == assign_op_identifier);
   11735        19103 :               instance = build_base_path (PLUS_EXPR, instance,
   11736              :                                           binfo, /*nonnull=*/1, complain);
   11737              :             }
   11738              :         }
   11739              :     }
   11740              : 
   11741     37341021 :   gcc_assert (instance != NULL_TREE);
   11742              : 
   11743              :   /* In C++17, "If the initializer expression is a prvalue and the
   11744              :      cv-unqualified version of the source type is the same class as the class
   11745              :      of the destination, the initializer expression is used to initialize the
   11746              :      destination object."  Handle that here to avoid doing overload
   11747              :      resolution.  */
   11748     37341021 :   if (cxx_dialect >= cxx17
   11749     37150846 :       && args && vec_safe_length (*args) == 1
   11750     59454589 :       && !unsafe_return_slot_p (instance))
   11751              :     {
   11752     20882959 :       tree arg = (**args)[0];
   11753              : 
   11754      1637264 :       if (BRACE_ENCLOSED_INITIALIZER_P (arg)
   11755      1636872 :           && !TYPE_HAS_LIST_CTOR (class_type)
   11756      1563907 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (arg)
   11757     22446852 :           && CONSTRUCTOR_NELTS (arg) == 1)
   11758      1114922 :         arg = CONSTRUCTOR_ELT (arg, 0)->value;
   11759              : 
   11760     20882959 :       if ((TREE_CODE (arg) == TARGET_EXPR
   11761     10100334 :            || TREE_CODE (arg) == CONSTRUCTOR)
   11762     32188000 :           && (same_type_ignoring_top_level_qualifiers_p
   11763     11305041 :               (class_type, TREE_TYPE (arg))))
   11764              :         {
   11765     10196023 :           if (is_dummy_object (instance))
   11766              :             return arg;
   11767       219051 :           else if (TREE_CODE (arg) == TARGET_EXPR)
   11768       219051 :             TARGET_EXPR_DIRECT_INIT_P (arg) = true;
   11769              : 
   11770       219051 :           if ((complain & tf_error)
   11771       219049 :               && (flags & LOOKUP_DELEGATING_CONS))
   11772            0 :             check_self_delegation (arg);
   11773              :           /* Avoid change of behavior on Wunused-var-2.C.  */
   11774       219051 :           instance = mark_lvalue_use (instance);
   11775       219051 :           return cp_build_init_expr (instance, arg);
   11776              :         }
   11777              :     }
   11778              : 
   11779     27144998 :   fns = lookup_fnfields (binfo, name, 1, complain);
   11780              : 
   11781              :   /* When making a call to a constructor or destructor for a subobject
   11782              :      that uses virtual base classes, pass down a pointer to a VTT for
   11783              :      the subobject.  */
   11784     27144998 :   if ((name == base_ctor_identifier
   11785     24876042 :        || name == base_dtor_identifier)
   11786     28694721 :       && CLASSTYPE_VBASECLASSES (class_type))
   11787              :     {
   11788        46718 :       tree vtt;
   11789        46718 :       tree sub_vtt;
   11790              : 
   11791              :       /* If the current function is a complete object constructor
   11792              :          or destructor, then we fetch the VTT directly.
   11793              :          Otherwise, we look it up using the VTT we were given.  */
   11794        46718 :       vtt = DECL_CHAIN (CLASSTYPE_VTABLES (current_class_type));
   11795        46718 :       vtt = decay_conversion (vtt, complain);
   11796        46718 :       if (vtt == error_mark_node)
   11797            0 :         return error_mark_node;
   11798        46718 :       vtt = build_if_in_charge (vtt, current_vtt_parm);
   11799        46718 :       if (BINFO_SUBVTT_INDEX (binfo))
   11800        46566 :         sub_vtt = fold_build_pointer_plus (vtt, BINFO_SUBVTT_INDEX (binfo));
   11801              :       else
   11802          152 :         sub_vtt = vtt;
   11803              : 
   11804        46718 :       if (args == NULL)
   11805              :         {
   11806        29616 :           allocated = make_tree_vector ();
   11807        29616 :           args = &allocated;
   11808              :         }
   11809              : 
   11810        46718 :       vec_safe_insert (*args, 0, sub_vtt);
   11811              :     }
   11812              : 
   11813     54289996 :   ret = build_new_method_call (instance, fns, args,
   11814     27144998 :                                TYPE_BINFO (BINFO_TYPE (binfo)),
   11815              :                                flags, /*fn=*/NULL,
   11816              :                                complain);
   11817              : 
   11818     27144998 :   if (allocated != NULL)
   11819        29616 :     release_tree_vector (allocated);
   11820              : 
   11821     27144998 :   if ((complain & tf_error)
   11822     24323514 :       && (flags & LOOKUP_DELEGATING_CONS)
   11823       347736 :       && name == complete_ctor_identifier)
   11824       347650 :     check_self_delegation (ret);
   11825              : 
   11826              :   return ret;
   11827              : }
   11828              : 
   11829              : /* Return the NAME, as a C string.  The NAME indicates a function that
   11830              :    is a member of TYPE.  *FREE_P is set to true if the caller must
   11831              :    free the memory returned.
   11832              : 
   11833              :    Rather than go through all of this, we should simply set the names
   11834              :    of constructors and destructors appropriately, and dispense with
   11835              :    ctor_identifier, dtor_identifier, etc.  */
   11836              : 
   11837              : static char *
   11838           93 : name_as_c_string (tree name, tree type, bool *free_p)
   11839              : {
   11840           93 :   const char *pretty_name;
   11841              : 
   11842              :   /* Assume that we will not allocate memory.  */
   11843           93 :   *free_p = false;
   11844              :   /* Constructors and destructors are special.  */
   11845           93 :   if (IDENTIFIER_CDTOR_P (name))
   11846              :     {
   11847           42 :       pretty_name
   11848           42 :         = identifier_to_locale (IDENTIFIER_POINTER (constructor_name (type)));
   11849              :       /* For a destructor, add the '~'.  */
   11850           42 :       if (IDENTIFIER_DTOR_P (name))
   11851              :         {
   11852            0 :           pretty_name = concat ("~", pretty_name, NULL);
   11853              :           /* Remember that we need to free the memory allocated.  */
   11854            0 :           *free_p = true;
   11855              :         }
   11856              :     }
   11857           51 :   else if (IDENTIFIER_CONV_OP_P (name))
   11858              :     {
   11859            0 :       pretty_name = concat ("operator ",
   11860            0 :                             type_as_string_translate (TREE_TYPE (name),
   11861              :                                                       TFF_PLAIN_IDENTIFIER),
   11862              :                             NULL);
   11863              :       /* Remember that we need to free the memory allocated.  */
   11864            0 :       *free_p = true;
   11865              :     }
   11866              :   else
   11867           51 :     pretty_name = identifier_to_locale (IDENTIFIER_POINTER (name));
   11868              : 
   11869           93 :   return const_cast<char *> (pretty_name);
   11870              : }
   11871              : 
   11872              : /* If CANDIDATES contains exactly one candidate, return it, otherwise
   11873              :    return NULL.  */
   11874              : 
   11875              : static z_candidate *
   11876          680 : single_z_candidate (z_candidate *candidates)
   11877              : {
   11878            0 :   if (candidates == NULL)
   11879              :     return NULL;
   11880              : 
   11881          668 :   if (candidates->next)
   11882            0 :     return NULL;
   11883              : 
   11884              :   return candidates;
   11885              : }
   11886              : 
   11887              : /* If CANDIDATE is invalid due to a bad argument type, return the
   11888              :    pertinent conversion_info.
   11889              : 
   11890              :    Otherwise, return NULL.  */
   11891              : 
   11892              : static const conversion_info *
   11893          339 : maybe_get_bad_conversion_for_unmatched_call (const z_candidate *candidate)
   11894              : {
   11895              :   /* Must be an rr_arg_conversion or rr_bad_arg_conversion.  */
   11896          339 :   rejection_reason *r = candidate->reason;
   11897              : 
   11898          339 :   if (r == NULL)
   11899              :     return NULL;
   11900              : 
   11901          339 :   switch (r->code)
   11902              :     {
   11903              :     default:
   11904              :       return NULL;
   11905              : 
   11906           52 :     case rr_arg_conversion:
   11907           52 :       return &r->u.conversion;
   11908              : 
   11909            6 :     case rr_bad_arg_conversion:
   11910            6 :       return &r->u.bad_conversion;
   11911              :     }
   11912              : }
   11913              : 
   11914              : /* Issue an error and note complaining about a bad argument type at a
   11915              :    callsite with a single candidate FNDECL.
   11916              : 
   11917              :    ARG_LOC is the location of the argument (or UNKNOWN_LOCATION, in which
   11918              :    case input_location is used).
   11919              :    FROM_TYPE is the type of the actual argument; TO_TYPE is the type of
   11920              :    the formal parameter.  */
   11921              : 
   11922              : void
   11923          150 : complain_about_bad_argument (location_t arg_loc,
   11924              :                              tree from_type, tree to_type,
   11925              :                              tree fndecl, int parmnum)
   11926              : {
   11927          150 :   auto_diagnostic_group d;
   11928          150 :   range_label_for_type_mismatch rhs_label (from_type, to_type);
   11929          150 :   range_label *label = &rhs_label;
   11930          150 :   if (arg_loc == UNKNOWN_LOCATION)
   11931              :     {
   11932            6 :       arg_loc = input_location;
   11933            6 :       label = NULL;
   11934              :     }
   11935          150 :   gcc_rich_location richloc (arg_loc, label, highlight_colors::percent_h);
   11936          150 :   error_at (&richloc,
   11937              :             "cannot convert %qH to %qI",
   11938              :             from_type, to_type);
   11939          150 :   maybe_inform_about_fndecl_for_bogus_argument_init
   11940          150 :     (fndecl,
   11941              :      parmnum,
   11942              :      highlight_colors::percent_i);
   11943          150 : }
   11944              : 
   11945              : /* Subroutine of build_new_method_call_1, for where there are no viable
   11946              :    candidates for the call.  */
   11947              : 
   11948              : static void
   11949          686 : complain_about_no_candidates_for_method_call (tree instance,
   11950              :                                               z_candidate *candidates,
   11951              :                                               tree explicit_targs,
   11952              :                                               tree basetype,
   11953              :                                               tree optype, tree name,
   11954              :                                               bool skip_first_for_error,
   11955              :                                               vec<tree, va_gc> *user_args)
   11956              : {
   11957          686 :   auto_diagnostic_group d;
   11958          686 :   if (!COMPLETE_OR_OPEN_TYPE_P (basetype))
   11959            0 :     cxx_incomplete_type_error (instance, basetype);
   11960          686 :   else if (optype)
   11961            6 :     error ("no matching function for call to %<%T::operator %T(%A)%#V%>",
   11962              :            basetype, optype, build_tree_list_vec (user_args),
   11963            6 :            TREE_TYPE (instance));
   11964              :   else
   11965              :     {
   11966              :       /* Special-case for when there's a single candidate that's failing
   11967              :          due to a bad argument type.  */
   11968          680 :       if (z_candidate *candidate = single_z_candidate (candidates))
   11969          339 :           if (const conversion_info *conv
   11970          339 :                 = maybe_get_bad_conversion_for_unmatched_call (candidate))
   11971              :             {
   11972           58 :               tree from_type = conv->from;
   11973           58 :               if (!TYPE_P (conv->from))
   11974            6 :                 from_type = lvalue_type (conv->from);
   11975           58 :               complain_about_bad_argument (conv->loc,
   11976           58 :                                            from_type, conv->to_type,
   11977           58 :                                            candidate->fn, conv->n_arg);
   11978           58 :               return;
   11979              :             }
   11980              : 
   11981          622 :       tree arglist = build_tree_list_vec (user_args);
   11982          622 :       tree errname = name;
   11983          622 :       bool twiddle = false;
   11984          622 :       if (IDENTIFIER_CDTOR_P (errname))
   11985              :         {
   11986          319 :           twiddle = IDENTIFIER_DTOR_P (errname);
   11987          319 :           errname = constructor_name (basetype);
   11988              :         }
   11989          622 :       if (explicit_targs)
   11990           48 :         errname = lookup_template_function (errname, explicit_targs);
   11991          622 :       if (skip_first_for_error)
   11992            3 :         arglist = TREE_CHAIN (arglist);
   11993         1244 :       error ("no matching function for call to %<%T::%s%E(%A)%#V%>",
   11994          622 :              basetype, &"~"[!twiddle], errname, arglist,
   11995          622 :              TREE_TYPE (instance));
   11996              :     }
   11997          628 :   print_z_candidates (location_of (name), candidates);
   11998          686 : }
   11999              : 
   12000              : /* Build a call to "INSTANCE.FN (ARGS)".  If FN_P is non-NULL, it will
   12001              :    be set, upon return, to the function called.  ARGS may be NULL.
   12002              :    This may change ARGS.  */
   12003              : 
   12004              : tree
   12005     95422819 : build_new_method_call (tree instance, tree fns, vec<tree, va_gc> **args,
   12006              :                        tree conversion_path, int flags,
   12007              :                        tree *fn_p, tsubst_flags_t complain)
   12008              : {
   12009     95422819 :   struct z_candidate *candidates = 0, *cand;
   12010     95422819 :   tree explicit_targs = NULL_TREE;
   12011     95422819 :   tree basetype = NULL_TREE;
   12012     95422819 :   tree access_binfo;
   12013     95422819 :   tree optype;
   12014     95422819 :   tree first_mem_arg = NULL_TREE;
   12015     95422819 :   tree name;
   12016     95422819 :   bool skip_first_for_error;
   12017     95422819 :   vec<tree, va_gc> *user_args;
   12018     95422819 :   tree call;
   12019     95422819 :   tree fn;
   12020     95422819 :   int template_only = 0;
   12021     95422819 :   bool any_viable_p;
   12022     95422819 :   tree orig_instance;
   12023     95422819 :   tree orig_fns;
   12024     95422819 :   vec<tree, va_gc> *orig_args = NULL;
   12025              : 
   12026     95422819 :   auto_cond_timevar tv (TV_OVERLOAD);
   12027              : 
   12028     95422819 :   gcc_assert (instance != NULL_TREE);
   12029              : 
   12030              :   /* We don't know what function we're going to call, yet.  */
   12031     95422819 :   if (fn_p)
   12032     26865268 :     *fn_p = NULL_TREE;
   12033              : 
   12034     95422819 :   if (error_operand_p (instance)
   12035     95422819 :       || !fns || error_operand_p (fns))
   12036      1392060 :     return error_mark_node;
   12037              : 
   12038     94030759 :   if (!BASELINK_P (fns))
   12039              :     {
   12040            0 :       if (complain & tf_error)
   12041            0 :         error ("call to non-function %qD", fns);
   12042            0 :       return error_mark_node;
   12043              :     }
   12044              : 
   12045     94030759 :   orig_instance = instance;
   12046     94030759 :   orig_fns = fns;
   12047              : 
   12048              :   /* Dismantle the baselink to collect all the information we need.  */
   12049     94030759 :   if (!conversion_path)
   12050     41426625 :     conversion_path = BASELINK_BINFO (fns);
   12051     94030759 :   access_binfo = BASELINK_ACCESS_BINFO (fns);
   12052     94030759 :   optype = BASELINK_OPTYPE (fns);
   12053     94030759 :   fns = BASELINK_FUNCTIONS (fns);
   12054     94030759 :   if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
   12055              :     {
   12056      2555602 :       explicit_targs = TREE_OPERAND (fns, 1);
   12057      2555602 :       fns = TREE_OPERAND (fns, 0);
   12058      2555602 :       template_only = 1;
   12059              :     }
   12060     94030759 :   gcc_assert (OVL_P (fns));
   12061     94030759 :   fn = OVL_FIRST (fns);
   12062     94030759 :   name = DECL_NAME (fn);
   12063              : 
   12064     94030759 :   basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
   12065     94030759 :   gcc_assert (CLASS_TYPE_P (basetype));
   12066              : 
   12067     94030759 :   user_args = args == NULL ? NULL : *args;
   12068              :   /* Under DR 147 A::A() is an invalid constructor call,
   12069              :      not a functional cast.  */
   12070     94030759 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
   12071              :     {
   12072           54 :       if (! (complain & tf_error))
   12073            0 :         return error_mark_node;
   12074              : 
   12075           54 :       basetype = DECL_CONTEXT (fn);
   12076           54 :       name = constructor_name (basetype);
   12077           54 :       auto_diagnostic_group d;
   12078           54 :       if (permerror (input_location,
   12079              :                      "cannot call constructor %<%T::%D%> directly",
   12080              :                      basetype, name))
   12081           54 :         inform (input_location, "for a function-style cast, remove the "
   12082              :                 "redundant %<::%D%>", name);
   12083           54 :       call = build_functional_cast (input_location, basetype,
   12084              :                                     build_tree_list_vec (user_args),
   12085              :                                     complain);
   12086           54 :       return call;
   12087           54 :     }
   12088              : 
   12089     94030705 :   if (processing_template_decl)
   12090      7400312 :     orig_args = args == NULL ? NULL : make_tree_vector_copy (*args);
   12091              : 
   12092              :   /* Process the argument list.  */
   12093     93894727 :   if (args != NULL && *args != NULL)
   12094              :     {
   12095     80070932 :       *args = resolve_args (*args, complain);
   12096     80070932 :       if (*args == NULL)
   12097          189 :         return error_mark_node;
   12098              :       user_args = *args;
   12099              :     }
   12100              : 
   12101              :   /* Consider the object argument to be used even if we end up selecting a
   12102              :      static member function.  */
   12103     94030516 :   instance = mark_type_use (instance);
   12104              : 
   12105              :   /* Figure out whether to skip the first argument for the error
   12106              :      message we will display to users if an error occurs.  We don't
   12107              :      want to display any compiler-generated arguments.  The "this"
   12108              :      pointer hasn't been added yet.  However, we must remove the VTT
   12109              :      pointer if this is a call to a base-class constructor or
   12110              :      destructor.  */
   12111     94030516 :   skip_first_for_error = false;
   12112     94030516 :   if (IDENTIFIER_CDTOR_P (name))
   12113              :     {
   12114              :       /* Callers should explicitly indicate whether they want to ctor
   12115              :          the complete object or just the part without virtual bases.  */
   12116     49994622 :       gcc_assert (name != ctor_identifier);
   12117              : 
   12118              :       /* Remove the VTT pointer, if present.  */
   12119     47725672 :       if ((name == base_ctor_identifier || name == base_dtor_identifier)
   12120     51544345 :           && CLASSTYPE_VBASECLASSES (basetype))
   12121              :         skip_first_for_error = true;
   12122              : 
   12123              :       /* It's OK to call destructors and constructors on cv-qualified
   12124              :          objects.  Therefore, convert the INSTANCE to the unqualified
   12125              :          type, if necessary.  */
   12126     49994622 :       if (!same_type_p (basetype, TREE_TYPE (instance)))
   12127              :         {
   12128       664244 :           instance = build_this (instance);
   12129       664244 :           instance = build_nop (build_pointer_type (basetype), instance);
   12130       664244 :           instance = build_fold_indirect_ref (instance);
   12131              :         }
   12132              :     }
   12133              :   else
   12134     88071788 :     gcc_assert (!DECL_DESTRUCTOR_P (fn) && !DECL_CONSTRUCTOR_P (fn));
   12135              : 
   12136              :   /* For the overload resolution we need to find the actual `this`
   12137              :      that would be captured if the call turns out to be to a
   12138              :      non-static member function.  Do not actually capture it at this
   12139              :      point.  */
   12140    188061032 :   if (DECL_CONSTRUCTOR_P (fn))
   12141              :     /* Constructors don't use the enclosing 'this'.  */
   12142              :     first_mem_arg = instance;
   12143              :   else
   12144     69181345 :     first_mem_arg = maybe_resolve_dummy (instance, false);
   12145              : 
   12146     94030516 :   conversion_obstack_sentinel cos;
   12147              : 
   12148              :   /* The number of arguments artificial parms in ARGS; we subtract one because
   12149              :      there's no 'this' in ARGS.  */
   12150     94030516 :   unsigned skip = num_artificial_parms_for (fn) - 1;
   12151              : 
   12152              :   /* If CONSTRUCTOR_IS_DIRECT_INIT is set, this was a T{ } form
   12153              :      initializer, not T({ }).  */
   12154     94030516 :   if (DECL_CONSTRUCTOR_P (fn)
   12155     21260012 :       && vec_safe_length (user_args) > skip
   12156    113151560 :       && DIRECT_LIST_INIT_P ((*user_args)[skip]))
   12157              :     {
   12158      1639130 :       tree init_list = (*user_args)[skip];
   12159      1639130 :       tree init = NULL_TREE;
   12160              : 
   12161      1639130 :       gcc_assert (user_args->length () == skip + 1
   12162              :                   && !(flags & LOOKUP_ONLYCONVERTING));
   12163              : 
   12164              :       /* If the initializer list has no elements and T is a class type with
   12165              :          a default constructor, the object is value-initialized.  Handle
   12166              :          this here so we don't need to handle it wherever we use
   12167              :          build_special_member_call.  */
   12168      1639130 :       if (CONSTRUCTOR_NELTS (init_list) == 0
   12169       179752 :           && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
   12170              :           /* For a user-provided default constructor, use the normal
   12171              :              mechanisms so that protected access works.  */
   12172       179752 :           && type_has_non_user_provided_default_constructor (basetype)
   12173      1572308 :           && !processing_template_decl)
   12174       112927 :         init = build_value_init (basetype, complain);
   12175              : 
   12176              :       /* If BASETYPE is an aggregate, we need to do aggregate
   12177              :          initialization.  */
   12178      1526203 :       else if (CP_AGGREGATE_TYPE_P (basetype))
   12179              :         {
   12180           41 :           init = reshape_init (basetype, init_list, complain);
   12181           41 :           init = digest_init (basetype, init, complain);
   12182              :         }
   12183              : 
   12184       112968 :       if (init)
   12185              :         {
   12186       112968 :           if (is_dummy_object (instance))
   12187        31839 :             return get_target_expr (init, complain);
   12188        81129 :           return cp_build_init_expr (instance, init);
   12189              :         }
   12190              : 
   12191              :       /* Otherwise go ahead with overload resolution.  */
   12192      1526162 :       add_list_candidates (fns, first_mem_arg, user_args,
   12193              :                            basetype, explicit_targs, template_only,
   12194              :                            conversion_path, access_binfo, flags,
   12195              :                            &candidates, complain);
   12196              :     }
   12197              :   else
   12198     92391386 :     add_candidates (fns, first_mem_arg, user_args, optype,
   12199              :                     explicit_targs, template_only, conversion_path,
   12200              :                     access_binfo, flags, &candidates, complain);
   12201              : 
   12202     93917548 :   any_viable_p = false;
   12203     93917548 :   candidates = splice_viable (candidates, false, &any_viable_p);
   12204              : 
   12205     93917548 :   if (!any_viable_p)
   12206              :     {
   12207              :       /* [dcl.init], 17.6.2.2:
   12208              : 
   12209              :          Otherwise, if no constructor is viable, the destination type is
   12210              :          a (possibly cv-qualified) aggregate class A, and the initializer
   12211              :          is a parenthesized expression-list, the object is initialized as
   12212              :          follows...
   12213              : 
   12214              :          We achieve this by building up a CONSTRUCTOR, as for list-init,
   12215              :          and setting CONSTRUCTOR_IS_PAREN_INIT to distinguish between
   12216              :          the two.  */
   12217        24280 :       if (DECL_CONSTRUCTOR_P (fn)
   12218        18193 :           && !(flags & LOOKUP_ONLYCONVERTING)
   12219        18169 :           && cxx_dialect >= cxx20
   12220        17555 :           && CP_AGGREGATE_TYPE_P (basetype)
   12221        24280 :           && !vec_safe_is_empty (user_args))
   12222              :         {
   12223              :           /* Create a CONSTRUCTOR from ARGS, e.g. {1, 2} from <1, 2>.  */
   12224          967 :           tree ctor = build_constructor_from_vec (init_list_type_node,
   12225              :                                                   user_args);
   12226          967 :           CONSTRUCTOR_IS_DIRECT_INIT (ctor) = true;
   12227          967 :           CONSTRUCTOR_IS_PAREN_INIT (ctor) = true;
   12228          967 :           if (is_dummy_object (instance))
   12229              :             return ctor;
   12230              :           else
   12231              :             {
   12232          647 :               ctor = digest_init (basetype, ctor, complain);
   12233          647 :               if (ctor == error_mark_node)
   12234              :                 return error_mark_node;
   12235          427 :               return cp_build_init_expr (instance, ctor);
   12236              :             }
   12237              :         }
   12238        23313 :       if (complain & tf_error)
   12239          686 :         complain_about_no_candidates_for_method_call (instance, candidates,
   12240              :                                                       explicit_targs, basetype,
   12241              :                                                       optype, name,
   12242              :                                                       skip_first_for_error,
   12243              :                                                       user_args);
   12244        23313 :       call = error_mark_node;
   12245              :     }
   12246              :   else
   12247              :     {
   12248     93893268 :       cand = tourney (candidates, complain);
   12249     93893268 :       if (cand == 0)
   12250              :         {
   12251          193 :           char *pretty_name;
   12252          193 :           bool free_p;
   12253          193 :           tree arglist;
   12254              : 
   12255          193 :           if (complain & tf_error)
   12256              :             {
   12257           93 :               pretty_name = name_as_c_string (name, basetype, &free_p);
   12258           93 :               arglist = build_tree_list_vec (user_args);
   12259           93 :               if (skip_first_for_error)
   12260            0 :                 arglist = TREE_CHAIN (arglist);
   12261           93 :               auto_diagnostic_group d;
   12262          186 :               if (!any_strictly_viable (candidates))
   12263           13 :                 error ("no matching function for call to %<%s(%A)%>",
   12264              :                        pretty_name, arglist);
   12265              :               else
   12266           80 :                 error ("call of overloaded %<%s(%A)%> is ambiguous",
   12267              :                        pretty_name, arglist);
   12268           93 :               print_z_candidates (location_of (name), candidates);
   12269           93 :               if (free_p)
   12270            0 :                 free (pretty_name);
   12271           93 :             }
   12272          193 :           call = error_mark_node;
   12273          193 :           if (fn_p)
   12274           84 :             *fn_p = error_mark_node;
   12275              :         }
   12276              :       else
   12277              :         {
   12278     93893075 :           fn = cand->fn;
   12279     93893075 :           call = NULL_TREE;
   12280              : 
   12281     93893075 :           if (!(flags & LOOKUP_NONVIRTUAL)
   12282     71888314 :               && DECL_PURE_VIRTUAL_P (fn)
   12283       198445 :               && instance == current_class_ref
   12284     94048847 :               && (complain & tf_warning))
   12285              :             {
   12286              :               /* This is not an error, it is runtime undefined
   12287              :                  behavior.  */
   12288       155772 :               if (!current_function_decl)
   12289            3 :                 warning (0, "pure virtual %q#D called from "
   12290              :                          "non-static data member initializer", fn);
   12291       155769 :               else if (DECL_CONSTRUCTOR_P (current_function_decl)
   12292       155769 :                        || DECL_DESTRUCTOR_P (current_function_decl))
   12293            9 :                 warning (0, (DECL_CONSTRUCTOR_P (current_function_decl)
   12294              :                              ? G_("pure virtual %q#D called from constructor")
   12295              :                              : G_("pure virtual %q#D called from destructor")),
   12296              :                          fn);
   12297              :             }
   12298              : 
   12299    107848557 :           if (DECL_OBJECT_MEMBER_FUNCTION_P (fn)
   12300    159877894 :               && !DECL_CONSTRUCTOR_P (fn)
   12301    149114152 :               && is_dummy_object (instance))
   12302              :             {
   12303        49287 :               instance = maybe_resolve_dummy (instance, true);
   12304        49287 :               if (instance == error_mark_node)
   12305              :                 call = error_mark_node;
   12306        49287 :               else if (!is_dummy_object (instance))
   12307              :                 {
   12308              :                   /* We captured 'this' in the current lambda now that
   12309              :                      we know we really need it.  */
   12310        48882 :                   cand->first_arg = instance;
   12311              :                 }
   12312          405 :               else if (current_class_ptr && any_dependent_bases_p ())
   12313              :                 /* We can't tell until instantiation time whether we can use
   12314              :                    *this as the implicit object argument.  */;
   12315              :               else
   12316              :                 {
   12317          366 :                   if (complain & tf_error)
   12318           69 :                     error ("cannot call member function %qD without object",
   12319              :                            fn);
   12320          366 :                   call = error_mark_node;
   12321              :                 }
   12322              :             }
   12323              : 
   12324     93893075 :           if (call != error_mark_node)
   12325              :             {
   12326              :               /* Now we know what function is being called.  */
   12327     93892709 :               if (fn_p)
   12328     25460217 :                 *fn_p = fn;
   12329              :               /* Build the actual CALL_EXPR.  */
   12330     93892709 :               call = build_over_call (cand, flags, complain);
   12331              : 
   12332              :               /* Suppress warnings for if (my_struct.operator= (x)) where
   12333              :                  my_struct is implicitly converted to bool. */
   12334     93892709 :               if (TREE_CODE (call) == MODIFY_EXPR)
   12335      3042749 :                 suppress_warning (call, OPT_Wparentheses);
   12336              : 
   12337              :               /* In an expression of the form `a->f()' where `f' turns
   12338              :                  out to be a static member function, `a' is
   12339              :                  none-the-less evaluated.  */
   12340     93892709 :               if (!is_dummy_object (instance))
   12341     72892213 :                 call = keep_unused_object_arg (call, instance, fn);
   12342     93892709 :               if (call != error_mark_node
   12343    185880576 :                   && DECL_DESTRUCTOR_P (cand->fn)
   12344    119037301 :                   && !VOID_TYPE_P (TREE_TYPE (call)))
   12345              :                 /* An explicit call of the form "x->~X()" has type
   12346              :                    "void".  However, on platforms where destructors
   12347              :                    return "this" (i.e., those where
   12348              :                    targetm.cxx.cdtor_returns_this is true), such calls
   12349              :                    will appear to have a return value of pointer type
   12350              :                    to the low-level call machinery.  We do not want to
   12351              :                    change the low-level machinery, since we want to be
   12352              :                    able to optimize "delete f()" on such platforms as
   12353              :                    "operator delete(~X(f()))" (rather than generating
   12354              :                    "t = f(), ~X(t), operator delete (t)").  */
   12355     14561287 :                 call = build_nop (void_type_node, call);
   12356              :             }
   12357              :         }
   12358              :     }
   12359              : 
   12360     93916581 :   if (processing_template_decl && call != error_mark_node)
   12361              :     {
   12362      7400258 :       bool cast_to_void = false;
   12363              : 
   12364      7400258 :       if (TREE_CODE (call) == COMPOUND_EXPR)
   12365            8 :         call = TREE_OPERAND (call, 1);
   12366      7400250 :       else if (TREE_CODE (call) == NOP_EXPR)
   12367              :         {
   12368            0 :           cast_to_void = true;
   12369            0 :           call = TREE_OPERAND (call, 0);
   12370              :         }
   12371      7400258 :       if (INDIRECT_REF_P (call))
   12372       573714 :         call = TREE_OPERAND (call, 0);
   12373              : 
   12374              :       /* Prune all but the selected function from the original overload
   12375              :          set so that we can avoid some duplicate work at instantiation time.  */
   12376      7400258 :       if (really_overloaded_fn (fns))
   12377              :         {
   12378      1765154 :           if (DECL_TEMPLATE_INFO (fn)
   12379      1765154 :               && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   12380              :             {
   12381              :               /* Use the selected template, not the specialization, so that
   12382              :                  this looks like an actual lookup result for sake of
   12383              :                  filter_memfn_lookup.  */
   12384              : 
   12385       265955 :               if (OVL_SINGLE_P (fns))
   12386              :                 /* If the original overload set consists of a single function
   12387              :                    template, this isn't beneficial.  */
   12388       227821 :                 goto skip_prune;
   12389              : 
   12390        38134 :               fn = ovl_make (DECL_TI_TEMPLATE (fn));
   12391        38134 :               if (template_only)
   12392        28844 :                 fn = lookup_template_function (fn, explicit_targs);
   12393              :             }
   12394      1537333 :           orig_fns = copy_node (orig_fns);
   12395      1537333 :           BASELINK_FUNCTIONS (orig_fns) = fn;
   12396      1537333 :           BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (orig_fns) = true;
   12397              :         }
   12398              : 
   12399      5635104 : skip_prune:
   12400      7400258 :       call = (build_min_non_dep_call_vec
   12401      7400258 :               (call,
   12402      7400258 :                build_min (COMPONENT_REF, TREE_TYPE (CALL_EXPR_FN (call)),
   12403              :                           orig_instance, orig_fns, NULL_TREE),
   12404              :                orig_args));
   12405      7400258 :       SET_EXPR_LOCATION (call, input_location);
   12406      7400258 :       call = convert_from_reference (call);
   12407      7400258 :       if (cast_to_void)
   12408            0 :         call = build_nop (void_type_node, call);
   12409              :     }
   12410              : 
   12411     93916581 :   if (orig_args != NULL)
   12412      7264328 :     release_tree_vector (orig_args);
   12413              : 
   12414              :   return call;
   12415     95422819 : }
   12416              : 
   12417              : /* Returns true iff standard conversion sequence ICS1 is a proper
   12418              :    subsequence of ICS2.  */
   12419              : 
   12420              : static bool
   12421     72402492 : is_subseq (conversion *ics1, conversion *ics2)
   12422              : {
   12423              :   /* We can assume that a conversion of the same code
   12424              :      between the same types indicates a subsequence since we only get
   12425              :      here if the types we are converting from are the same.  */
   12426              : 
   12427     72402492 :   while (ics1->kind == ck_rvalue
   12428     84748069 :          || ics1->kind == ck_lvalue)
   12429     12345577 :     ics1 = next_conversion (ics1);
   12430              : 
   12431              :   while (1)
   12432              :     {
   12433     96035911 :       while (ics2->kind == ck_rvalue
   12434     96035911 :              || ics2->kind == ck_lvalue)
   12435     12345577 :         ics2 = next_conversion (ics2);
   12436              : 
   12437     83690334 :       if (ics2->kind == ck_user
   12438     83690334 :           || !has_next (ics2->kind))
   12439              :         /* At this point, ICS1 cannot be a proper subsequence of
   12440              :            ICS2.  We can get a USER_CONV when we are comparing the
   12441              :            second standard conversion sequence of two user conversion
   12442              :            sequences.  */
   12443              :         return false;
   12444              : 
   12445     11292306 :       ics2 = next_conversion (ics2);
   12446              : 
   12447     11292306 :       while (ics2->kind == ck_rvalue
   12448     17788186 :              || ics2->kind == ck_lvalue)
   12449      6495880 :         ics2 = next_conversion (ics2);
   12450              : 
   12451     11292306 :       if (ics2->kind == ics1->kind
   12452         4509 :           && same_type_p (ics2->type, ics1->type)
   12453     11296770 :           && (ics1->kind == ck_identity
   12454         4464 :               || same_type_p (next_conversion (ics2)->type,
   12455              :                               next_conversion (ics1)->type)))
   12456         4464 :         return true;
   12457              :     }
   12458              : }
   12459              : 
   12460              : /* Returns nonzero iff DERIVED is derived from BASE.  The inputs may
   12461              :    be any _TYPE nodes.  */
   12462              : 
   12463              : bool
   12464    360719304 : is_properly_derived_from (tree derived, tree base)
   12465              : {
   12466    360719304 :   if (!CLASS_TYPE_P (derived) || !CLASS_TYPE_P (base))
   12467              :     return false;
   12468              : 
   12469              :   /* We only allow proper derivation here.  The DERIVED_FROM_P macro
   12470              :      considers every class derived from itself.  */
   12471    341602102 :   return (!same_type_ignoring_top_level_qualifiers_p (derived, base)
   12472    341602102 :           && DERIVED_FROM_P (base, derived));
   12473              : }
   12474              : 
   12475              : /* We build the ICS for an implicit object parameter as a pointer
   12476              :    conversion sequence.  However, such a sequence should be compared
   12477              :    as if it were a reference conversion sequence.  If ICS is the
   12478              :    implicit conversion sequence for an implicit object parameter,
   12479              :    modify it accordingly.  */
   12480              : 
   12481              : static void
   12482    153598804 : maybe_handle_implicit_object (conversion **ics)
   12483              : {
   12484    153598804 :   if ((*ics)->this_p)
   12485              :     {
   12486              :       /* [over.match.funcs]
   12487              : 
   12488              :          For non-static member functions, the type of the
   12489              :          implicit object parameter is "reference to cv X"
   12490              :          where X is the class of which the function is a
   12491              :          member and cv is the cv-qualification on the member
   12492              :          function declaration.  */
   12493     12755842 :       conversion *t = *ics;
   12494     12755842 :       tree reference_type;
   12495              : 
   12496              :       /* The `this' parameter is a pointer to a class type.  Make the
   12497              :          implicit conversion talk about a reference to that same class
   12498              :          type.  */
   12499     12755842 :       reference_type = TREE_TYPE (t->type);
   12500     12755842 :       reference_type = build_reference_type (reference_type);
   12501              : 
   12502     12755842 :       if (t->kind == ck_qual)
   12503      3212606 :         t = next_conversion (t);
   12504     12755842 :       if (t->kind == ck_ptr)
   12505       581892 :         t = next_conversion (t);
   12506     12755842 :       t = build_identity_conv (TREE_TYPE (t->type), NULL_TREE);
   12507     12755842 :       t = direct_reference_binding (reference_type, t);
   12508     12755842 :       t->this_p = 1;
   12509     12755842 :       t->rvaluedness_matches_p = 0;
   12510     12755842 :       *ics = t;
   12511              :     }
   12512    153598804 : }
   12513              : 
   12514              : /* If *ICS is a REF_BIND set *ICS to the remainder of the conversion,
   12515              :    and return the initial reference binding conversion. Otherwise,
   12516              :    leave *ICS unchanged and return NULL.  */
   12517              : 
   12518              : static conversion *
   12519    153598804 : maybe_handle_ref_bind (conversion **ics)
   12520              : {
   12521    153598804 :   if ((*ics)->kind == ck_ref_bind)
   12522              :     {
   12523     57579307 :       conversion *old_ics = *ics;
   12524     57579307 :       *ics = next_conversion (old_ics);
   12525     57579307 :       (*ics)->user_conv_p = old_ics->user_conv_p;
   12526     57579307 :       return old_ics;
   12527              :     }
   12528              : 
   12529              :   return NULL;
   12530              : }
   12531              : 
   12532              : /* Get the expression at the beginning of the conversion chain C.  */
   12533              : 
   12534              : static tree
   12535           51 : conv_get_original_expr (conversion *c)
   12536              : {
   12537           60 :   for (; c; c = next_conversion (c))
   12538           60 :     if (c->kind == ck_identity || c->kind == ck_ambig || c->kind == ck_aggr)
   12539           51 :       return c->u.expr;
   12540              :   return NULL_TREE;
   12541              : }
   12542              : 
   12543              : /* Return a tree representing the number of elements initialized by the
   12544              :    list-initialization C.  The caller must check that C converts to an
   12545              :    array type.  */
   12546              : 
   12547              : static tree
   12548          126 : nelts_initialized_by_list_init (conversion *c)
   12549              : {
   12550              :   /* If the array we're converting to has a dimension, we'll use that.  */
   12551          126 :   if (TYPE_DOMAIN (c->type))
   12552           84 :     return array_type_nelts_top (c->type);
   12553              :   else
   12554              :     {
   12555              :       /* Otherwise, we look at how many elements the constructor we're
   12556              :          initializing from has.  */
   12557           42 :       tree ctor = conv_get_original_expr (c);
   12558           72 :       return size_int (CONSTRUCTOR_NELTS (ctor));
   12559              :     }
   12560              : }
   12561              : 
   12562              : /* True iff C is a conversion that binds a reference or a pointer to
   12563              :    an array of unknown bound.  */
   12564              : 
   12565              : static inline bool
   12566     28681116 : conv_binds_to_array_of_unknown_bound (conversion *c)
   12567              : {
   12568              :   /* ck_ref_bind won't have the reference stripped.  */
   12569     28681116 :   tree type = non_reference (c->type);
   12570              :   /* ck_qual won't have the pointer stripped.  */
   12571     28681116 :   type = strip_pointer_operator (type);
   12572     28681116 :   return (TREE_CODE (type) == ARRAY_TYPE
   12573     28681116 :           && TYPE_DOMAIN (type) == NULL_TREE);
   12574              : }
   12575              : 
   12576              : /* Compare two implicit conversion sequences according to the rules set out in
   12577              :    [over.ics.rank].  Return values:
   12578              : 
   12579              :       1: ics1 is better than ics2
   12580              :      -1: ics2 is better than ics1
   12581              :       0: ics1 and ics2 are indistinguishable */
   12582              : 
   12583              : static int
   12584     76799443 : compare_ics (conversion *ics1, conversion *ics2)
   12585              : {
   12586     76799443 :   tree from_type1;
   12587     76799443 :   tree from_type2;
   12588     76799443 :   tree to_type1;
   12589     76799443 :   tree to_type2;
   12590     76799443 :   tree deref_from_type1 = NULL_TREE;
   12591     76799443 :   tree deref_from_type2 = NULL_TREE;
   12592     76799443 :   tree deref_to_type1 = NULL_TREE;
   12593     76799443 :   tree deref_to_type2 = NULL_TREE;
   12594     76799443 :   conversion_rank rank1, rank2;
   12595              : 
   12596              :   /* REF_BINDING is nonzero if the result of the conversion sequence
   12597              :      is a reference type.   In that case REF_CONV is the reference
   12598              :      binding conversion. */
   12599     76799443 :   conversion *ref_conv1;
   12600     76799443 :   conversion *ref_conv2;
   12601              : 
   12602              :   /* Compare badness before stripping the reference conversion.  */
   12603     76799443 :   if (ics1->bad_p > ics2->bad_p)
   12604              :     return -1;
   12605     76799429 :   else if (ics1->bad_p < ics2->bad_p)
   12606              :     return 1;
   12607              : 
   12608              :   /* Handle implicit object parameters.  */
   12609     76799402 :   maybe_handle_implicit_object (&ics1);
   12610     76799402 :   maybe_handle_implicit_object (&ics2);
   12611              : 
   12612              :   /* Handle reference parameters.  */
   12613     76799402 :   ref_conv1 = maybe_handle_ref_bind (&ics1);
   12614     76799402 :   ref_conv2 = maybe_handle_ref_bind (&ics2);
   12615              : 
   12616              :   /* List-initialization sequence L1 is a better conversion sequence than
   12617              :      list-initialization sequence L2 if L1 converts to
   12618              :      std::initializer_list<X> for some X and L2 does not.  */
   12619     76799402 :   if (ics1->kind == ck_list && ics2->kind != ck_list)
   12620              :     return 1;
   12621     76798613 :   if (ics2->kind == ck_list && ics1->kind != ck_list)
   12622              :     return -1;
   12623              : 
   12624              :   /* [over.ics.rank]
   12625              : 
   12626              :      When  comparing  the  basic forms of implicit conversion sequences (as
   12627              :      defined in _over.best.ics_)
   12628              : 
   12629              :      --a standard conversion sequence (_over.ics.scs_) is a better
   12630              :        conversion sequence than a user-defined conversion sequence
   12631              :        or an ellipsis conversion sequence, and
   12632              : 
   12633              :      --a user-defined conversion sequence (_over.ics.user_) is a
   12634              :        better conversion sequence than an ellipsis conversion sequence
   12635              :        (_over.ics.ellipsis_).  */
   12636              :   /* Use BAD_CONVERSION_RANK because we already checked for a badness
   12637              :      mismatch.  If both ICS are bad, we try to make a decision based on
   12638              :      what would have happened if they'd been good.  This is not an
   12639              :      extension, we'll still give an error when we build up the call; this
   12640              :      just helps us give a more helpful error message.  */
   12641     76798367 :   rank1 = BAD_CONVERSION_RANK (ics1);
   12642     76798367 :   rank2 = BAD_CONVERSION_RANK (ics2);
   12643              : 
   12644     76798367 :   if (rank1 > rank2)
   12645              :     return -1;
   12646     66383749 :   else if (rank1 < rank2)
   12647              :     return 1;
   12648              : 
   12649     36607509 :   if (ics1->ellipsis_p)
   12650              :     /* Both conversions are ellipsis conversions.  */
   12651              :     return 0;
   12652              : 
   12653              :   /* User-defined  conversion sequence U1 is a better conversion sequence
   12654              :      than another user-defined conversion sequence U2 if they contain the
   12655              :      same user-defined conversion operator or constructor and if the sec-
   12656              :      ond standard conversion sequence of U1 is  better  than  the  second
   12657              :      standard conversion sequence of U2.  */
   12658              : 
   12659              :   /* Handle list-conversion with the same code even though it isn't always
   12660              :      ranked as a user-defined conversion and it doesn't have a second
   12661              :      standard conversion sequence; it will still have the desired effect.
   12662              :      Specifically, we need to do the reference binding comparison at the
   12663              :      end of this function.  */
   12664              : 
   12665     36607463 :   if (ics1->user_conv_p || ics1->kind == ck_list
   12666     35941101 :       || ics1->kind == ck_aggr || ics2->kind == ck_aggr)
   12667              :     {
   12668       666431 :       conversion *t1 = strip_standard_conversion (ics1);
   12669       666431 :       conversion *t2 = strip_standard_conversion (ics2);
   12670              : 
   12671       666431 :       if (!t1 || !t2 || t1->kind != t2->kind)
   12672              :         return 0;
   12673       666412 :       else if (t1->kind == ck_user)
   12674              :         {
   12675       652185 :           tree f1 = t1->cand ? t1->cand->fn : t1->type;
   12676       652185 :           tree f2 = t2->cand ? t2->cand->fn : t2->type;
   12677       652185 :           if (f1 != f2)
   12678              :             return 0;
   12679              :         }
   12680              :       /* List-initialization sequence L1 is a better conversion sequence than
   12681              :          list-initialization sequence L2 if
   12682              : 
   12683              :          -- L1 and L2 convert to arrays of the same element type, and either
   12684              :          the number of elements n1 initialized by L1 is less than the number
   12685              :          of elements n2 initialized by L2, or n1=n2 and L2 converts to an array
   12686              :          of unknown bound and L1 does not.  (Added in CWG 1307 and extended by
   12687              :          P0388R4.)  */
   12688        14227 :       else if (t1->kind == ck_aggr
   12689        13394 :                && TREE_CODE (t1->type) == ARRAY_TYPE
   12690           66 :                && TREE_CODE (t2->type) == ARRAY_TYPE
   12691        14293 :                && same_type_p (TREE_TYPE (t1->type), TREE_TYPE (t2->type)))
   12692              :         {
   12693           63 :           tree n1 = nelts_initialized_by_list_init (t1);
   12694           63 :           tree n2 = nelts_initialized_by_list_init (t2);
   12695           63 :           if (tree_int_cst_lt (n1, n2))
   12696              :             return 1;
   12697           24 :           else if (tree_int_cst_lt (n2, n1))
   12698              :             return -1;
   12699              :           /* The n1 == n2 case.  */
   12700           24 :           bool c1 = conv_binds_to_array_of_unknown_bound (t1);
   12701           24 :           bool c2 = conv_binds_to_array_of_unknown_bound (t2);
   12702           24 :           if (c1 && !c2)
   12703              :             return -1;
   12704            6 :           else if (!c1 && c2)
   12705              :             return 1;
   12706              :           else
   12707              :             return 0;
   12708              :         }
   12709              :       else
   12710              :         {
   12711              :           /* For ambiguous or aggregate conversions, use the target type as
   12712              :              a proxy for the conversion function.  */
   12713        14164 :           if (!same_type_ignoring_top_level_qualifiers_p (t1->type, t2->type))
   12714              :             return 0;
   12715              :         }
   12716              : 
   12717              :       /* We can just fall through here, after setting up
   12718              :          FROM_TYPE1 and FROM_TYPE2.  */
   12719       663682 :       from_type1 = t1->type;
   12720       663682 :       from_type2 = t2->type;
   12721       663682 :     }
   12722              :   else
   12723              :     {
   12724              :       conversion *t1;
   12725              :       conversion *t2;
   12726              : 
   12727              :       /* We're dealing with two standard conversion sequences.
   12728              : 
   12729              :          [over.ics.rank]
   12730              : 
   12731              :          Standard conversion sequence S1 is a better conversion
   12732              :          sequence than standard conversion sequence S2 if
   12733              : 
   12734              :          --S1 is a proper subsequence of S2 (comparing the conversion
   12735              :            sequences in the canonical form defined by _over.ics.scs_,
   12736              :            excluding any Lvalue Transformation; the identity
   12737              :            conversion sequence is considered to be a subsequence of
   12738              :            any non-identity conversion sequence */
   12739              : 
   12740              :       t1 = ics1;
   12741     51095690 :       while (t1->kind != ck_identity)
   12742     15154658 :         t1 = next_conversion (t1);
   12743     35941032 :       from_type1 = t1->type;
   12744              : 
   12745     35941032 :       t2 = ics2;
   12746     50993549 :       while (t2->kind != ck_identity)
   12747     15052517 :         t2 = next_conversion (t2);
   12748     35941032 :       from_type2 = t2->type;
   12749              :     }
   12750              : 
   12751              :   /* One sequence can only be a subsequence of the other if they start with
   12752              :      the same type.  They can start with different types when comparing the
   12753              :      second standard conversion sequence in two user-defined conversion
   12754              :      sequences.  */
   12755     36604714 :   if (same_type_p (from_type1, from_type2))
   12756              :     {
   12757     36203449 :       if (is_subseq (ics1, ics2))
   12758              :         return 1;
   12759     36199043 :       if (is_subseq (ics2, ics1))
   12760              :         return -1;
   12761              :     }
   12762              : 
   12763              :   /* [over.ics.rank]
   12764              : 
   12765              :      Or, if not that,
   12766              : 
   12767              :      --the rank of S1 is better than the rank of S2 (by the rules
   12768              :        defined below):
   12769              : 
   12770              :     Standard conversion sequences are ordered by their ranks: an Exact
   12771              :     Match is a better conversion than a Promotion, which is a better
   12772              :     conversion than a Conversion.
   12773              : 
   12774              :     Two conversion sequences with the same rank are indistinguishable
   12775              :     unless one of the following rules applies:
   12776              : 
   12777              :     --A conversion that does not a convert a pointer, pointer to member,
   12778              :       or std::nullptr_t to bool is better than one that does.
   12779              : 
   12780              :     The ICS_STD_RANK automatically handles the pointer-to-bool rule,
   12781              :     so that we do not have to check it explicitly.  */
   12782     36600250 :   if (ics1->rank < ics2->rank)
   12783              :     return 1;
   12784     36600170 :   else if (ics2->rank < ics1->rank)
   12785              :     return -1;
   12786              : 
   12787     36600170 :   to_type1 = ics1->type;
   12788     36600170 :   to_type2 = ics2->type;
   12789              : 
   12790              :   /* A conversion from scalar arithmetic type to complex is worse than a
   12791              :      conversion between scalar arithmetic types.  */
   12792     36600170 :   if (same_type_p (from_type1, from_type2)
   12793     36198905 :       && ARITHMETIC_TYPE_P (from_type1)
   12794      7388172 :       && ARITHMETIC_TYPE_P (to_type1)
   12795      7387999 :       && ARITHMETIC_TYPE_P (to_type2)
   12796     36600170 :       && ((TREE_CODE (to_type1) == COMPLEX_TYPE)
   12797      7387957 :           != (TREE_CODE (to_type2) == COMPLEX_TYPE)))
   12798              :     {
   12799          106 :       if (TREE_CODE (to_type1) == COMPLEX_TYPE)
   12800              :         return -1;
   12801              :       else
   12802              :         return 1;
   12803              :     }
   12804              : 
   12805     36600064 :   {
   12806              :     /* A conversion in either direction between floating-point type FP1 and
   12807              :        floating-point type FP2 is better than a conversion in the same
   12808              :        direction between FP1 and arithmetic type T3 if
   12809              :        - the floating-point conversion rank of FP1 is equal to the rank of
   12810              :          FP2, and
   12811              :        - T3 is not a floating-point type, or T3 is a floating-point type
   12812              :          whose rank is not equal to the rank of FP1, or the floating-point
   12813              :          conversion subrank of FP2 is greater than the subrank of T3.  */
   12814     36600064 :     tree fp1 = from_type1;
   12815     36600064 :     tree fp2 = to_type1;
   12816     36600064 :     tree fp3 = from_type2;
   12817     36600064 :     tree t3 = to_type2;
   12818     36600064 :     int ret = 1;
   12819     36600064 :     if (TYPE_MAIN_VARIANT (fp2) == TYPE_MAIN_VARIANT (t3))
   12820              :       {
   12821     31969612 :         std::swap (fp1, fp2);
   12822     31969612 :         std::swap (fp3, t3);
   12823              :       }
   12824     36600064 :     if (TYPE_MAIN_VARIANT (fp1) == TYPE_MAIN_VARIANT (fp3)
   12825     36599979 :         && SCALAR_FLOAT_TYPE_P (fp1)
   12826              :         /* Only apply this rule if at least one of the 3 types is
   12827              :            extended floating-point type, otherwise keep them as
   12828              :            before for compatibility reasons with types like __float128.
   12829              :            float, double and long double alone have different conversion
   12830              :            ranks and so when just those 3 types are involved, this
   12831              :            rule doesn't trigger.  */
   12832     40746281 :         && (extended_float_type_p (fp1)
   12833      4090701 :             || (SCALAR_FLOAT_TYPE_P (fp2) && extended_float_type_p (fp2))
   12834      4020320 :             || (SCALAR_FLOAT_TYPE_P (t3) && extended_float_type_p (t3))))
   12835              :       {
   12836       125897 :         if (TREE_CODE (fp2) != REAL_TYPE)
   12837              :           {
   12838        24811 :             ret = -ret;
   12839        24811 :             std::swap (fp2, t3);
   12840              :           }
   12841       125897 :         if (SCALAR_FLOAT_TYPE_P (fp2))
   12842              :           {
   12843              :             /* cp_compare_floating_point_conversion_ranks returns -1, 0 or 1
   12844              :                if the conversion rank is equal (-1 or 1 if the subrank is
   12845              :                different).  */
   12846       112338 :             if (IN_RANGE (cp_compare_floating_point_conversion_ranks (fp1,
   12847              :                                                                       fp2),
   12848              :                           -1, 1))
   12849              :               {
   12850              :                 /* Conversion ranks of FP1 and FP2 are equal.  */
   12851        73133 :                 if (TREE_CODE (t3) != REAL_TYPE
   12852        73133 :                     || !IN_RANGE (cp_compare_floating_point_conversion_ranks
   12853              :                                                                 (fp1, t3),
   12854              :                                   -1, 1))
   12855              :                   /* FP1 <-> FP2 conversion is better.  */
   12856        72663 :                   return ret;
   12857          470 :                 int c = cp_compare_floating_point_conversion_ranks (fp2, t3);
   12858          470 :                 gcc_assert (IN_RANGE (c, -1, 1));
   12859          470 :                 if (c == 1)
   12860              :                   /* Conversion subrank of FP2 is greater than subrank of T3.
   12861              :                      FP1 <-> FP2 conversion is better.  */
   12862              :                   return ret;
   12863          470 :                 else if (c == -1)
   12864              :                   /* Conversion subrank of FP2 is less than subrank of T3.
   12865              :                      FP1 <-> T3 conversion is better.  */
   12866            0 :                   return -ret;
   12867              :               }
   12868        39205 :             else if (SCALAR_FLOAT_TYPE_P (t3)
   12869        39205 :                      && IN_RANGE (cp_compare_floating_point_conversion_ranks
   12870              :                                                                 (fp1, t3),
   12871              :                                   -1, 1))
   12872              :               /* Conversion ranks of FP1 and FP2 are not equal, conversion
   12873              :                  ranks of FP1 and T3 are equal.
   12874              :                  FP1 <-> T3 conversion is better.  */
   12875         7913 :               return -ret;
   12876              :           }
   12877              :       }
   12878              :   }
   12879              : 
   12880     36519488 :   if (TYPE_PTR_P (from_type1)
   12881      4047947 :       && TYPE_PTR_P (from_type2)
   12882      4047931 :       && TYPE_PTR_P (to_type1)
   12883      4047907 :       && TYPE_PTR_P (to_type2))
   12884              :     {
   12885      4047907 :       deref_from_type1 = TREE_TYPE (from_type1);
   12886      4047907 :       deref_from_type2 = TREE_TYPE (from_type2);
   12887      4047907 :       deref_to_type1 = TREE_TYPE (to_type1);
   12888      4047907 :       deref_to_type2 = TREE_TYPE (to_type2);
   12889              :     }
   12890              :   /* The rules for pointers to members A::* are just like the rules
   12891              :      for pointers A*, except opposite: if B is derived from A then
   12892              :      A::* converts to B::*, not vice versa.  For that reason, we
   12893              :      switch the from_ and to_ variables here.  */
   12894           58 :   else if ((TYPE_PTRDATAMEM_P (from_type1) && TYPE_PTRDATAMEM_P (from_type2)
   12895           58 :             && TYPE_PTRDATAMEM_P (to_type1) && TYPE_PTRDATAMEM_P (to_type2))
   12896     32471581 :            || (TYPE_PTRMEMFUNC_P (from_type1)
   12897          437 :                && TYPE_PTRMEMFUNC_P (from_type2)
   12898          437 :                && TYPE_PTRMEMFUNC_P (to_type1)
   12899          437 :                && TYPE_PTRMEMFUNC_P (to_type2)))
   12900              :     {
   12901          495 :       deref_to_type1 = TYPE_PTRMEM_CLASS_TYPE (from_type1);
   12902          495 :       deref_to_type2 = TYPE_PTRMEM_CLASS_TYPE (from_type2);
   12903          495 :       deref_from_type1 = TYPE_PTRMEM_CLASS_TYPE (to_type1);
   12904          495 :       deref_from_type2 = TYPE_PTRMEM_CLASS_TYPE (to_type2);
   12905              :     }
   12906              : 
   12907      4048402 :   if (deref_from_type1 != NULL_TREE
   12908      4048402 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type1))
   12909       291531 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type2)))
   12910              :     {
   12911              :       /* This was one of the pointer or pointer-like conversions.
   12912              : 
   12913              :          [over.ics.rank]
   12914              : 
   12915              :          --If class B is derived directly or indirectly from class A,
   12916              :            conversion of B* to A* is better than conversion of B* to
   12917              :            void*, and conversion of A* to void* is better than
   12918              :            conversion of B* to void*.  */
   12919       291531 :       if (VOID_TYPE_P (deref_to_type1)
   12920           57 :           && VOID_TYPE_P (deref_to_type2))
   12921              :         {
   12922           14 :           if (is_properly_derived_from (deref_from_type1,
   12923              :                                         deref_from_type2))
   12924              :             return -1;
   12925           14 :           else if (is_properly_derived_from (deref_from_type2,
   12926              :                                              deref_from_type1))
   12927              :             return 1;
   12928              :         }
   12929       291517 :       else if (VOID_TYPE_P (deref_to_type1)
   12930       291474 :                || VOID_TYPE_P (deref_to_type2))
   12931              :         {
   12932           47 :           if (same_type_p (deref_from_type1, deref_from_type2))
   12933              :             {
   12934           47 :               if (VOID_TYPE_P (deref_to_type2))
   12935              :                 {
   12936            4 :                   if (is_properly_derived_from (deref_from_type1,
   12937              :                                                 deref_to_type1))
   12938              :                     return 1;
   12939              :                 }
   12940              :               /* We know that DEREF_TO_TYPE1 is `void' here.  */
   12941           43 :               else if (is_properly_derived_from (deref_from_type1,
   12942              :                                                  deref_to_type2))
   12943              :                 return -1;
   12944              :             }
   12945              :         }
   12946       291470 :       else if (RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type1))
   12947       291470 :                && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type2)))
   12948              :         {
   12949              :           /* [over.ics.rank]
   12950              : 
   12951              :              --If class B is derived directly or indirectly from class A
   12952              :                and class C is derived directly or indirectly from B,
   12953              : 
   12954              :              --conversion of C* to B* is better than conversion of C* to
   12955              :                A*,
   12956              : 
   12957              :              --conversion of B* to A* is better than conversion of C* to
   12958              :                A*  */
   12959       291470 :           if (same_type_p (deref_from_type1, deref_from_type2))
   12960              :             {
   12961       291464 :               if (is_properly_derived_from (deref_to_type1,
   12962              :                                             deref_to_type2))
   12963              :                 return 1;
   12964       291464 :               else if (is_properly_derived_from (deref_to_type2,
   12965              :                                                  deref_to_type1))
   12966              :                 return -1;
   12967              :             }
   12968            6 :           else if (same_type_p (deref_to_type1, deref_to_type2))
   12969              :             {
   12970            6 :               if (is_properly_derived_from (deref_from_type2,
   12971              :                                             deref_from_type1))
   12972              :                 return 1;
   12973            0 :               else if (is_properly_derived_from (deref_from_type1,
   12974              :                                                  deref_from_type2))
   12975              :                 return -1;
   12976              :             }
   12977              :         }
   12978              :     }
   12979     72455914 :   else if (CLASS_TYPE_P (non_reference (from_type1))
   12980     59179917 :            && same_type_p (from_type1, from_type2))
   12981              :     {
   12982     22609106 :       tree from = non_reference (from_type1);
   12983              : 
   12984              :       /* [over.ics.rank]
   12985              : 
   12986              :          --binding of an expression of type C to a reference of type
   12987              :            B& is better than binding an expression of type C to a
   12988              :            reference of type A&
   12989              : 
   12990              :          --conversion of C to B is better than conversion of C to A,  */
   12991     22609106 :       if (is_properly_derived_from (from, to_type1)
   12992     22609106 :           && is_properly_derived_from (from, to_type2))
   12993              :         {
   12994       911525 :           if (is_properly_derived_from (to_type1, to_type2))
   12995              :             return 1;
   12996       907910 :           else if (is_properly_derived_from (to_type2, to_type1))
   12997              :             return -1;
   12998              :         }
   12999              :     }
   13000     27237702 :   else if (CLASS_TYPE_P (non_reference (to_type1))
   13001     13961705 :            && same_type_p (to_type1, to_type2))
   13002              :     {
   13003            6 :       tree to = non_reference (to_type1);
   13004              : 
   13005              :       /* [over.ics.rank]
   13006              : 
   13007              :          --binding of an expression of type B to a reference of type
   13008              :            A& is better than binding an expression of type C to a
   13009              :            reference of type A&,
   13010              : 
   13011              :          --conversion of B to A is better than conversion of C to A  */
   13012            6 :       if (is_properly_derived_from (from_type1, to)
   13013            6 :           && is_properly_derived_from (from_type2, to))
   13014              :         {
   13015            3 :           if (is_properly_derived_from (from_type2, from_type1))
   13016              :             return 1;
   13017            3 :           else if (is_properly_derived_from (from_type1, from_type2))
   13018              :             return -1;
   13019              :         }
   13020              :     }
   13021              : 
   13022              :   /* [over.ics.rank]
   13023              : 
   13024              :      --S1 and S2 differ only in their qualification conversion and  yield
   13025              :        similar  types  T1 and T2 (_conv.qual_), respectively, and the cv-
   13026              :        qualification signature of type T1 is a proper subset of  the  cv-
   13027              :        qualification signature of type T2  */
   13028     36434926 :   if (ics1->kind == ck_qual
   13029          351 :       && ics2->kind == ck_qual
   13030     36435277 :       && same_type_p (from_type1, from_type2))
   13031              :     {
   13032          351 :       int result = comp_cv_qual_signature (to_type1, to_type2);
   13033          351 :       if (result != 0)
   13034              :         return result;
   13035              :     }
   13036              : 
   13037              :   /* [over.ics.rank]
   13038              : 
   13039              :      --S1 and S2 are reference bindings (_dcl.init.ref_) and neither refers
   13040              :      to an implicit object parameter of a non-static member function
   13041              :      declared without a ref-qualifier, and either S1 binds an lvalue
   13042              :      reference to an lvalue and S2 binds an rvalue reference or S1 binds an
   13043              :      rvalue reference to an rvalue and S2 binds an lvalue reference (C++0x
   13044              :      draft standard, 13.3.3.2)
   13045              : 
   13046              :      --S1 and S2 are reference bindings (_dcl.init.ref_), and the
   13047              :      types to which the references refer are the same type except for
   13048              :      top-level cv-qualifiers, and the type to which the reference
   13049              :      initialized by S2 refers is more cv-qualified than the type to
   13050              :      which the reference initialized by S1 refers.
   13051              : 
   13052              :      DR 1328 [over.match.best]: the context is an initialization by
   13053              :      conversion function for direct reference binding (13.3.1.6) of a
   13054              :      reference to function type, the return type of F1 is the same kind of
   13055              :      reference (i.e. lvalue or rvalue) as the reference being initialized,
   13056              :      and the return type of F2 is not.  */
   13057              : 
   13058     36434840 :   if (ref_conv1 && ref_conv2)
   13059              :     {
   13060     17135927 :       if (!ref_conv1->this_p && !ref_conv2->this_p
   13061     16912490 :           && (ref_conv1->rvaluedness_matches_p
   13062     16912490 :               != ref_conv2->rvaluedness_matches_p)
   13063     32557200 :           && (same_type_p (ref_conv1->type, ref_conv2->type)
   13064      9108370 :               || (TYPE_REF_IS_RVALUE (ref_conv1->type)
   13065      9108370 :                   != TYPE_REF_IS_RVALUE (ref_conv2->type))))
   13066              :         {
   13067      9108098 :           if (ref_conv1->bad_p
   13068      9108098 :               && !same_type_p (TREE_TYPE (ref_conv1->type),
   13069              :                                TREE_TYPE (ref_conv2->type)))
   13070              :             /* Don't prefer a bad conversion that drops cv-quals to a bad
   13071              :                conversion with the wrong rvalueness.  */
   13072              :             return 0;
   13073      9106635 :           return (ref_conv1->rvaluedness_matches_p
   13074      9106635 :                   - ref_conv2->rvaluedness_matches_p);
   13075              :         }
   13076              : 
   13077     14340729 :       if (same_type_ignoring_top_level_qualifiers_p (to_type1, to_type2))
   13078              :         {
   13079              :           /* Per P0388R4:
   13080              : 
   13081              :             void f (int(&)[]),     // (1)
   13082              :                  f (int(&)[1]),    // (2)
   13083              :                  f (int*);         // (3)
   13084              : 
   13085              :             (2) is better than (1), but (3) should be equal to (1) and to
   13086              :             (2).  For that reason we don't use ck_qual for (1) which would
   13087              :             give it the cr_exact rank while (3) remains ck_identity.
   13088              :             Therefore we compare (1) and (2) here.  For (1) we'll have
   13089              : 
   13090              :               ck_ref_bind <- ck_identity
   13091              :                 int[] &            int[1]
   13092              : 
   13093              :             so to handle this we must look at ref_conv.  */
   13094     14340298 :           bool c1 = conv_binds_to_array_of_unknown_bound (ref_conv1);
   13095     14340298 :           bool c2 = conv_binds_to_array_of_unknown_bound (ref_conv2);
   13096     14340298 :           if (c1 && !c2)
   13097              :             return -1;
   13098     14340292 :           else if (!c1 && c2)
   13099              :             return 1;
   13100              : 
   13101     14340292 :           int q1 = cp_type_quals (TREE_TYPE (ref_conv1->type));
   13102     14340292 :           int q2 = cp_type_quals (TREE_TYPE (ref_conv2->type));
   13103     14340292 :           if (ref_conv1->bad_p)
   13104              :             {
   13105              :               /* Prefer the one that drops fewer cv-quals.  */
   13106         1606 :               tree ftype = next_conversion (ref_conv1)->type;
   13107         1606 :               int fquals = cp_type_quals (ftype);
   13108         1606 :               q1 ^= fquals;
   13109         1606 :               q2 ^= fquals;
   13110              :             }
   13111     14340292 :           return comp_cv_qualification (q2, q1);
   13112              :         }
   13113              :     }
   13114              : 
   13115              :   /* [over.ics.rank]
   13116              : 
   13117              :      Per CWG 1601:
   13118              :      -- A conversion that promotes an enumeration whose underlying type
   13119              :      is fixed to its underlying type is better than one that promotes to
   13120              :      the promoted underlying type, if the two are different.  */
   13121     12986444 :   if (ics1->rank == cr_promotion
   13122          146 :       && ics2->rank == cr_promotion
   13123          146 :       && UNSCOPED_ENUM_P (from_type1)
   13124           27 :       && ENUM_FIXED_UNDERLYING_TYPE_P (from_type1)
   13125     12986468 :       && same_type_p (from_type1, from_type2))
   13126              :     {
   13127           24 :       tree utype = ENUM_UNDERLYING_TYPE (from_type1);
   13128           24 :       tree prom = type_promotes_to (from_type1);
   13129           24 :       if (!same_type_p (utype, prom))
   13130              :         {
   13131           12 :           if (same_type_p (to_type1, utype)
   13132           12 :               && same_type_p (to_type2, prom))
   13133              :             return 1;
   13134            6 :           else if (same_type_p (to_type2, utype)
   13135            6 :                    && same_type_p (to_type1, prom))
   13136              :             return -1;
   13137              :         }
   13138              :     }
   13139              : 
   13140              :   /* Neither conversion sequence is better than the other.  */
   13141              :   return 0;
   13142              : }
   13143              : 
   13144              : /* The source type for this standard conversion sequence.  */
   13145              : 
   13146              : static tree
   13147            9 : source_type (conversion *t)
   13148              : {
   13149            9 :   return strip_standard_conversion (t)->type;
   13150              : }
   13151              : 
   13152              : /* Note a warning about preferring WINNER to LOSER.  We do this by storing
   13153              :    a pointer to LOSER and re-running joust to produce the warning if WINNER
   13154              :    is actually used.  */
   13155              : 
   13156              : static void
   13157          446 : add_warning (struct z_candidate *winner, struct z_candidate *loser)
   13158              : {
   13159          446 :   candidate_warning *cw = (candidate_warning *)
   13160            0 :     conversion_obstack_alloc (sizeof (candidate_warning));
   13161          446 :   cw->loser = loser;
   13162          446 :   cw->next = winner->warnings;
   13163          446 :   winner->warnings = cw;
   13164          446 : }
   13165              : 
   13166              : /* CAND is a constructor candidate in joust in C++17 and up.  If it copies a
   13167              :    prvalue returned from a conversion function, return true.  Otherwise, return
   13168              :    false.  */
   13169              : 
   13170              : static bool
   13171       798858 : joust_maybe_elide_copy (z_candidate *cand)
   13172              : {
   13173       798858 :   tree fn = cand->fn;
   13174      2005279 :   if (!DECL_COPY_CONSTRUCTOR_P (fn) && !DECL_MOVE_CONSTRUCTOR_P (fn))
   13175       407478 :     return false;
   13176       391380 :   conversion *conv = cand->convs[0];
   13177       391380 :   if (conv->kind == ck_ambig)
   13178              :     return false;
   13179       391378 :   gcc_checking_assert (conv->kind == ck_ref_bind);
   13180       391378 :   conv = next_conversion (conv);
   13181       391378 :   if (conv->kind == ck_user && !TYPE_REF_P (conv->type))
   13182              :     {
   13183          126 :       gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p
   13184              :                            (conv->type, DECL_CONTEXT (fn)));
   13185          126 :       z_candidate *uc = conv->cand;
   13186          126 :       if (DECL_CONV_FN_P (uc->fn))
   13187              :         return true;
   13188              :     }
   13189              :   return false;
   13190              : }
   13191              : 
   13192              : /* Return the class that CAND's implicit object parameter refers to.  */
   13193              : 
   13194              : static tree
   13195       281729 : class_of_implicit_object (z_candidate *cand)
   13196              : {
   13197       281729 :   if (!DECL_IOBJ_MEMBER_FUNCTION_P (cand->fn))
   13198              :     return NULL_TREE;
   13199              : 
   13200              :   /* "For conversion functions that are implicit object member functions,
   13201              :      the function is considered to be a member of the class of the implied
   13202              :      object argument for the purpose of defining the type of the implicit
   13203              :      object parameter."  */
   13204       281729 :   if (DECL_CONV_FN_P (cand->fn))
   13205            0 :     return TYPE_MAIN_VARIANT (TREE_TYPE (cand->first_arg));
   13206              : 
   13207              :   /* "For non-conversion functions that are implicit object member
   13208              :      functions nominated by a using-declaration in a derived class, the
   13209              :      function is considered to be a member of the derived class for the
   13210              :      purpose of defining the type of the implicit object parameter."
   13211              : 
   13212              :      That derived class is reflected in the conversion_path binfo.  */
   13213       281729 :   return BINFO_TYPE (cand->conversion_path);
   13214              : }
   13215              : 
   13216              : /* Return whether the first parameter of C1 matches the second parameter
   13217              :    of C2.  */
   13218              : 
   13219              : static bool
   13220       535285 : reversed_match (z_candidate *c1, z_candidate *c2)
   13221              : {
   13222       535285 :   tree fn1 = c1->fn;
   13223       535285 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (c2->fn));
   13224       535285 :   tree parm2 = TREE_VALUE (TREE_CHAIN (parms2));
   13225       535285 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn1))
   13226              :     {
   13227       281729 :       tree ctx = class_of_implicit_object (c1);
   13228       281729 :       return iobj_parm_corresponds_to (fn1, parm2, ctx);
   13229              :     }
   13230              :   else
   13231              :     {
   13232       253556 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13233       253556 :       tree parm1 = TREE_VALUE (parms1);
   13234       253556 :       return same_type_p (parm1, parm2);
   13235              :     }
   13236              : }
   13237              : 
   13238              : /* True if the defining declarations of the two candidates have equivalent
   13239              :    parameters.  MATCH_KIND controls whether we're trying to compare the
   13240              :    original declarations (for a warning) or the actual candidates.  */
   13241              : 
   13242              : enum class pmatch { original, current };
   13243              : 
   13244              : static bool
   13245      4664451 : cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
   13246              : {
   13247      4664451 :   tree fn1 = c1->fn;
   13248      4664451 :   tree fn2 = c2->fn;
   13249      4664451 :   bool reversed = (match_kind == pmatch::current
   13250      4664451 :                    && c1->reversed () != c2->reversed ());
   13251      4664451 :   if (fn1 == fn2 && !reversed)
   13252              :     return true;
   13253      4664202 :   if (identifier_p (fn1) || identifier_p (fn2))
   13254              :     return false;
   13255      4664185 :   if (match_kind == pmatch::original)
   13256              :     {
   13257              :       /* We don't look at c1->template_decl because that's only set for
   13258              :          primary templates, not e.g. non-template member functions of
   13259              :          class templates.  */
   13260           22 :       tree t1 = most_general_template (fn1);
   13261           22 :       tree t2 = most_general_template (fn2);
   13262           22 :       if (t1 || t2)
   13263              :         {
   13264           15 :           if (!t1 || !t2)
   13265              :             return false;
   13266           15 :           if (t1 == t2)
   13267              :             return true;
   13268            3 :           fn1 = DECL_TEMPLATE_RESULT (t1);
   13269            3 :           fn2 = DECL_TEMPLATE_RESULT (t2);
   13270              :         }
   13271              :     }
   13272              : 
   13273      4664173 :   tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13274      4664173 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2));
   13275              : 
   13276      9121799 :   if (DECL_FUNCTION_MEMBER_P (fn1)
   13277      4664792 :       && DECL_FUNCTION_MEMBER_P (fn2))
   13278              :     {
   13279       207152 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (fn1));
   13280       207152 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (fn2));
   13281       207152 :       if (base1 != base2)
   13282       141340 :         return false;
   13283              : 
   13284       206975 :       if (reversed)
   13285       141163 :         return (reversed_match (c1, c2)
   13286       141163 :                 && reversed_match (c2, c1));
   13287              : 
   13288              :       /* Use object_parms_correspond to simplify comparing iobj/xobj/static
   13289              :          member functions.  */
   13290        65812 :       if (!object_parms_correspond (fn1, fn2, base1))
   13291              :         return false;
   13292              : 
   13293              :       /* We just compared the object parameters, if they don't correspond
   13294              :          we already returned false.  */
   13295       197436 :       auto skip_parms = [] (tree fn, tree parms)
   13296              :         {
   13297       131624 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   13298         1020 :             return TREE_CHAIN (parms);
   13299              :           else
   13300       130604 :             return skip_artificial_parms_for (fn, parms);
   13301              :         };
   13302        65812 :       parms1 = skip_parms (fn1, parms1);
   13303        65812 :       parms2 = skip_parms (fn2, parms2);
   13304              :     }
   13305      4457021 :   else if (reversed)
   13306       126743 :     return (reversed_match (c1, c2)
   13307       126743 :             && reversed_match (c2, c1));
   13308      4396090 :   return compparms (parms1, parms2);
   13309              : }
   13310              : 
   13311              : /* True iff FN is a copy or move constructor or assignment operator.  */
   13312              : 
   13313              : static bool
   13314     19139032 : sfk_copy_or_move (tree fn)
   13315              : {
   13316     19139032 :   if (TREE_CODE (fn) != FUNCTION_DECL)
   13317              :     return false;
   13318     19138942 :   special_function_kind sfk = special_function_p (fn);
   13319     19138942 :   return sfk >= sfk_copy_constructor && sfk <= sfk_move_assignment;
   13320              : }
   13321              : 
   13322              : /* Compare two candidates for overloading as described in
   13323              :    [over.match.best].  Return values:
   13324              : 
   13325              :       1: cand1 is better than cand2
   13326              :      -1: cand2 is better than cand1
   13327              :       0: cand1 and cand2 are indistinguishable */
   13328              : 
   13329              : static int
   13330     72832488 : joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn,
   13331              :        tsubst_flags_t complain)
   13332              : {
   13333     72832488 :   int winner = 0;
   13334     72832488 :   int off1 = 0, off2 = 0;
   13335     72832488 :   size_t i;
   13336     72832488 :   size_t len;
   13337              : 
   13338              :   /* Candidates that involve bad conversions are always worse than those
   13339              :      that don't.  */
   13340     72832488 :   if (cand1->viable > cand2->viable)
   13341              :     return 1;
   13342     58693368 :   if (cand1->viable < cand2->viable)
   13343              :     return -1;
   13344              : 
   13345              :   /* If we have two pseudo-candidates for conversions to the same type,
   13346              :      or two candidates for the same function, arbitrarily pick one.  */
   13347     58693368 :   if (cand1->fn == cand2->fn
   13348      1768934 :       && cand1->reversed () == cand2->reversed ()
   13349     59476845 :       && (IS_TYPE_OR_DECL_P (cand1->fn)))
   13350              :     return 1;
   13351              : 
   13352              :   /* Prefer a non-deleted function over an implicitly deleted move
   13353              :      constructor or assignment operator.  This differs slightly from the
   13354              :      wording for issue 1402 (which says the move op is ignored by overload
   13355              :      resolution), but this way produces better error messages.  */
   13356     58693368 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13357     54574349 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13358    113260108 :       && DECL_DELETED_FN (cand1->fn) != DECL_DELETED_FN (cand2->fn))
   13359              :     {
   13360      2317374 :       if (DECL_DELETED_FN (cand1->fn) && DECL_DEFAULTED_FN (cand1->fn)
   13361      1937082 :           && move_fn_p (cand1->fn))
   13362              :         return -1;
   13363      3486155 :       if (DECL_DELETED_FN (cand2->fn) && DECL_DEFAULTED_FN (cand2->fn)
   13364      2839453 :           && move_fn_p (cand2->fn))
   13365              :         return 1;
   13366              :     }
   13367              : 
   13368              :   /* a viable function F1
   13369              :      is defined to be a better function than another viable function F2  if
   13370              :      for  all arguments i, ICSi(F1) is not a worse conversion sequence than
   13371              :      ICSi(F2), and then */
   13372              : 
   13373              :   /* for some argument j, ICSj(F1) is a better conversion  sequence  than
   13374              :      ICSj(F2) */
   13375              : 
   13376              :   /* For comparing static and non-static member functions, we ignore
   13377              :      the implicit object parameter of the non-static function.  The
   13378              :      standard says to pretend that the static function has an object
   13379              :      parm, but that won't work with operator overloading.  */
   13380     58679738 :   len = cand1->num_convs;
   13381     58679738 :   if (len != cand2->num_convs)
   13382              :     {
   13383          716 :       int static_1 = (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13384          716 :                       && DECL_STATIC_FUNCTION_P (cand1->fn));
   13385          716 :       int static_2 = (TREE_CODE (cand2->fn) == FUNCTION_DECL
   13386          716 :                       && DECL_STATIC_FUNCTION_P (cand2->fn));
   13387              : 
   13388          716 :       if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13389          179 :           && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13390          179 :           && DECL_CONSTRUCTOR_P (cand1->fn)
   13391          722 :           && is_list_ctor (cand1->fn) != is_list_ctor (cand2->fn))
   13392              :         /* We're comparing a near-match list constructor and a near-match
   13393              :            non-list constructor.  Just treat them as unordered.  */
   13394              :         return 0;
   13395              : 
   13396          710 :       gcc_assert (static_1 != static_2);
   13397              : 
   13398          710 :       if (static_1)
   13399              :         {
   13400              :           /* C++23 [over.best.ics.general] says:
   13401              :              When the parameter is the implicit object parameter of a static
   13402              :              member function, the implicit conversion sequence is a standard
   13403              :              conversion sequence that is neither better nor worse than any
   13404              :              other standard conversion sequence.  */
   13405           66 :           if (CONVERSION_RANK (cand2->convs[0]) >= cr_user)
   13406            0 :             winner = 1;
   13407              :           off2 = 1;
   13408              :         }
   13409              :       else
   13410              :         {
   13411          644 :           if (CONVERSION_RANK (cand1->convs[0]) >= cr_user)
   13412          537 :             winner = -1;
   13413          644 :           off1 = 1;
   13414          644 :           --len;
   13415              :         }
   13416              :     }
   13417              : 
   13418    135427244 :   for (i = 0; i < len; ++i)
   13419              :     {
   13420     76748762 :       conversion *t1 = cand1->convs[i + off1];
   13421     76748762 :       conversion *t2 = cand2->convs[i + off2];
   13422     76748762 :       int comp = compare_ics (t1, t2);
   13423              : 
   13424     76748762 :       if (comp != 0)
   13425              :         {
   13426     52948572 :           if ((complain & tf_warning)
   13427     43769990 :               && warn_sign_promo
   13428           82 :               && (CONVERSION_RANK (t1) + CONVERSION_RANK (t2)
   13429              :                   == cr_std + cr_promotion)
   13430           50 :               && t1->kind == ck_std
   13431           31 :               && t2->kind == ck_std
   13432           31 :               && TREE_CODE (t1->type) == INTEGER_TYPE
   13433           31 :               && TREE_CODE (t2->type) == INTEGER_TYPE
   13434           31 :               && (TYPE_PRECISION (t1->type)
   13435           31 :                   == TYPE_PRECISION (t2->type))
   13436     52948603 :               && (TYPE_UNSIGNED (next_conversion (t1)->type)
   13437            0 :                   || (TREE_CODE (next_conversion (t1)->type)
   13438              :                       == ENUMERAL_TYPE)))
   13439              :             {
   13440           31 :               tree type = next_conversion (t1)->type;
   13441           31 :               tree type1, type2;
   13442           31 :               struct z_candidate *w, *l;
   13443           31 :               if (comp > 0)
   13444              :                 type1 = t1->type, type2 = t2->type,
   13445              :                   w = cand1, l = cand2;
   13446              :               else
   13447            8 :                 type1 = t2->type, type2 = t1->type,
   13448            8 :                   w = cand2, l = cand1;
   13449              : 
   13450           31 :               if (warn)
   13451              :                 {
   13452            9 :                   warning (OPT_Wsign_promo, "passing %qT chooses %qT over %qT",
   13453              :                            type, type1, type2);
   13454            9 :                   warning (OPT_Wsign_promo, "  in call to %qD", w->fn);
   13455              :                 }
   13456              :               else
   13457           22 :                 add_warning (w, l);
   13458              :             }
   13459              : 
   13460     52948572 :           if (winner && comp != winner)
   13461              :             {
   13462              :               /* Ambiguity between normal and reversed comparison operators
   13463              :                  with the same parameter types.  P2468 decided not to go with
   13464              :                  this approach to resolving the ambiguity, so pedwarn.  */
   13465         1250 :               if ((complain & tf_warning_or_error)
   13466          690 :                   && (cand1->reversed () != cand2->reversed ())
   13467         1538 :                   && cand_parms_match (cand1, cand2, pmatch::original))
   13468              :                 {
   13469          273 :                   struct z_candidate *w, *l;
   13470          273 :                   if (cand2->reversed ())
   13471              :                     winner = 1, w = cand1, l = cand2;
   13472              :                   else
   13473          251 :                     winner = -1, w = cand2, l = cand1;
   13474          273 :                   if (warn)
   13475              :                     {
   13476           22 :                       auto_diagnostic_group d;
   13477           22 :                       if (pedwarn (input_location, 0,
   13478              :                                    "C++20 says that these are ambiguous, "
   13479              :                                    "even though the second is reversed:"))
   13480              :                         {
   13481           22 :                           print_z_candidate (input_location,
   13482              :                                              N_("candidate 1:"), w);
   13483           22 :                           print_z_candidate (input_location,
   13484              :                                              N_("candidate 2:"), l);
   13485           22 :                           if (w->fn == l->fn
   13486           17 :                               && DECL_IOBJ_MEMBER_FUNCTION_P (w->fn)
   13487           37 :                               && (type_memfn_quals (TREE_TYPE (w->fn))
   13488           15 :                                   & TYPE_QUAL_CONST) == 0)
   13489              :                             {
   13490              :                               /* Suggest adding const to
   13491              :                                  struct A { bool operator==(const A&); }; */
   13492           12 :                               tree parmtype
   13493           12 :                                 = FUNCTION_FIRST_USER_PARMTYPE (w->fn);
   13494           12 :                               parmtype = TREE_VALUE (parmtype);
   13495           12 :                               if (TYPE_REF_P (parmtype)
   13496           12 :                                   && TYPE_READONLY (TREE_TYPE (parmtype))
   13497           24 :                                   && (same_type_ignoring_top_level_qualifiers_p
   13498           12 :                                       (TREE_TYPE (parmtype),
   13499           12 :                                        DECL_CONTEXT (w->fn))))
   13500           12 :                                 inform (DECL_SOURCE_LOCATION (w->fn),
   13501              :                                         "try making the operator a %<const%> "
   13502              :                                         "member function");
   13503              :                             }
   13504              :                         }
   13505           22 :                     }
   13506              :                   else
   13507          251 :                     add_warning (w, l);
   13508          273 :                   return winner;
   13509              :                 }
   13510              : 
   13511          977 :               winner = 0;
   13512          977 :               goto tweak;
   13513              :             }
   13514              :           winner = comp;
   13515              :         }
   13516              :     }
   13517              : 
   13518              :   /* warn about confusing overload resolution for user-defined conversions,
   13519              :      either between a constructor and a conversion op, or between two
   13520              :      conversion ops.  */
   13521     58678482 :   if ((complain & tf_warning)
   13522              :       /* In C++17, the constructor might have been elided, which means that
   13523              :          an originally null ->second_conv could become non-null.  */
   13524     47974329 :       && winner && warn_conversion && cand1->second_conv && cand2->second_conv
   13525           54 :       && (!DECL_CONSTRUCTOR_P (cand1->fn) || !DECL_CONSTRUCTOR_P (cand2->fn))
   13526     58678509 :       && winner != compare_ics (cand1->second_conv, cand2->second_conv))
   13527              :     {
   13528           27 :       struct z_candidate *w, *l;
   13529           27 :       bool give_warning = false;
   13530              : 
   13531           27 :       if (winner == 1)
   13532              :         w = cand1, l = cand2;
   13533              :       else
   13534            6 :         w = cand2, l = cand1;
   13535              : 
   13536              :       /* We don't want to complain about `X::operator T1 ()'
   13537              :          beating `X::operator T2 () const', when T2 is a no less
   13538              :          cv-qualified version of T1.  */
   13539           27 :       if (DECL_CONTEXT (w->fn) == DECL_CONTEXT (l->fn)
   13540           39 :           && !DECL_CONSTRUCTOR_P (w->fn) && !DECL_CONSTRUCTOR_P (l->fn))
   13541              :         {
   13542            6 :           tree t = TREE_TYPE (TREE_TYPE (l->fn));
   13543            6 :           tree f = TREE_TYPE (TREE_TYPE (w->fn));
   13544              : 
   13545            6 :           if (TREE_CODE (t) == TREE_CODE (f) && INDIRECT_TYPE_P (t))
   13546              :             {
   13547            6 :               t = TREE_TYPE (t);
   13548            6 :               f = TREE_TYPE (f);
   13549              :             }
   13550            6 :           if (!comp_ptr_ttypes (t, f))
   13551              :             give_warning = true;
   13552              :         }
   13553              :       else
   13554              :         give_warning = true;
   13555              : 
   13556              :       if (!give_warning)
   13557              :         /*NOP*/;
   13558           21 :       else if (warn)
   13559              :         {
   13560            9 :           tree source = source_type (w->convs[0]);
   13561            9 :           if (INDIRECT_TYPE_P (source))
   13562            6 :             source = TREE_TYPE (source);
   13563            9 :           auto_diagnostic_group d;
   13564            9 :           if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn)
   13565           18 :               && warning (OPT_Wconversion, "  for conversion from %qH to %qI",
   13566            9 :                           source, w->second_conv->type))
   13567              :             {
   13568            9 :               inform (input_location, "  because conversion sequence "
   13569              :                       "for the argument is better");
   13570              :             }
   13571            9 :         }
   13572              :       else
   13573           12 :         add_warning (w, l);
   13574              :     }
   13575              : 
   13576     58678482 :   if (winner)
   13577              :     return winner;
   13578              : 
   13579              :   /* DR 495 moved this tiebreaker above the template ones.  */
   13580              :   /* or, if not that,
   13581              :      the  context  is  an  initialization by user-defined conversion (see
   13582              :      _dcl.init_  and  _over.match.user_)  and  the  standard   conversion
   13583              :      sequence  from  the return type of F1 to the destination type (i.e.,
   13584              :      the type of the entity being initialized)  is  a  better  conversion
   13585              :      sequence  than the standard conversion sequence from the return type
   13586              :      of F2 to the destination type.  */
   13587              : 
   13588      9569662 :   if (cand1->second_conv)
   13589              :     {
   13590        50654 :       winner = compare_ics (cand1->second_conv, cand2->second_conv);
   13591        50654 :       if (winner)
   13592              :         return winner;
   13593              :     }
   13594              : 
   13595              :   /* CWG2735 (PR109247): A copy/move ctor/op= for which its operand uses an
   13596              :      explicit conversion (due to list-initialization) is worse.  */
   13597      9569516 :   {
   13598      9569516 :     z_candidate *sp = nullptr;
   13599      9569516 :     if (sfk_copy_or_move (cand1->fn))
   13600          506 :       sp = cand1;
   13601      9569516 :     if (sfk_copy_or_move (cand2->fn))
   13602       804055 :       sp = sp ? nullptr : cand2;
   13603      9569463 :     if (sp)
   13604              :       {
   13605      1608910 :         conversion *conv = sp->convs[!DECL_CONSTRUCTOR_P (sp->fn)];
   13606       804455 :         if (conv->user_conv_p)
   13607         1262 :           for (; conv; conv = next_conversion (conv))
   13608         1128 :             if (conv->kind == ck_user
   13609          497 :                 && DECL_P (conv->cand->fn)
   13610         1625 :                 && DECL_NONCONVERTING_P (conv->cand->fn))
   13611          369 :               return (sp == cand1) ? -1 : 1;
   13612              :       }
   13613              :   }
   13614              : 
   13615              :   /* DR2327: C++17 copy elision in [over.match.ctor] (direct-init) context.
   13616              :      The standard currently says that only constructors are candidates, but if
   13617              :      one copies a prvalue returned by a conversion function we prefer that.
   13618              : 
   13619              :      Clang does something similar, as discussed at
   13620              :      http://lists.isocpp.org/core/2017/10/3166.php
   13621              :      http://lists.isocpp.org/core/2019/03/5721.php  */
   13622      6354631 :   if (len == 1 && cxx_dialect >= cxx17
   13623      6340484 :       && DECL_P (cand1->fn)
   13624      6340484 :       && DECL_COMPLETE_CONSTRUCTOR_P (cand1->fn)
   13625     10303020 :       && !(cand1->flags & LOOKUP_ONLYCONVERTING))
   13626              :     {
   13627       399429 :       bool elided1 = joust_maybe_elide_copy (cand1);
   13628       399429 :       bool elided2 = joust_maybe_elide_copy (cand2);
   13629       399429 :       winner = elided1 - elided2;
   13630       399429 :       if (winner)
   13631              :         return winner;
   13632              :     }
   13633              : 
   13634              :   /* or, if not that,
   13635              :      F1 is a non-template function and F2 is a template function
   13636              :      specialization.  */
   13637              : 
   13638      9569136 :   if (!cand1->template_decl && cand2->template_decl)
   13639              :     return 1;
   13640      9515496 :   else if (cand1->template_decl && !cand2->template_decl)
   13641              :     return -1;
   13642              : 
   13643              :   /* or, if not that,
   13644              :      F1 and F2 are template functions and the function template for F1 is
   13645              :      more specialized than the template for F2 according to the partial
   13646              :      ordering rules.  */
   13647              : 
   13648      8479821 :   if (cand1->template_decl && cand2->template_decl)
   13649              :     {
   13650      3803483 :       winner = more_specialized_fn
   13651      3803483 :         (TI_TEMPLATE (cand1->template_decl),
   13652      3803483 :          TI_TEMPLATE (cand2->template_decl),
   13653              :          /* [temp.func.order]: The presence of unused ellipsis and default
   13654              :             arguments has no effect on the partial ordering of function
   13655              :             templates.   add_function_candidate() will not have
   13656              :             counted the "this" argument for constructors.  */
   13657      7606966 :          cand1->num_convs + DECL_CONSTRUCTOR_P (cand1->fn));
   13658      3803483 :       if (winner)
   13659              :         return winner;
   13660              :     }
   13661              : 
   13662              :   /* F1 and F2 are non-template functions and
   13663              :      - they have the same non-object-parameter-type-lists ([dcl.fct]), and
   13664              :      - if they are member functions, both are direct members of the same
   13665              :        class, and
   13666              :      - if both are non-static member functions, they have the same types for
   13667              :        their object parameters, and
   13668              :      - F1 is more constrained than F2 according to the partial ordering of
   13669              :        constraints described in [temp.constr.order].  */
   13670      5677090 :   if (flag_concepts && DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13671      5677042 :       && !cand1->template_decl && !cand2->template_decl
   13672     10353741 :       && cand_parms_match (cand1, cand2, pmatch::current))
   13673              :     {
   13674       385032 :       winner = more_constrained (cand1->fn, cand2->fn);
   13675       385032 :       if (winner)
   13676              :         return winner;
   13677              :     }
   13678              : 
   13679              :   /* F2 is a rewritten candidate (12.4.1.2) and F1 is not, or F1 and F2 are
   13680              :      rewritten candidates, and F2 is a synthesized candidate with reversed
   13681              :      order of parameters and F1 is not.  */
   13682      5682539 :   if (cand1->rewritten ())
   13683              :     {
   13684      1173295 :       if (!cand2->rewritten ())
   13685              :         return -1;
   13686       741649 :       if (!cand1->reversed () && cand2->reversed ())
   13687              :         return 1;
   13688       741649 :       if (cand1->reversed () && !cand2->reversed ())
   13689              :         return -1;
   13690              :     }
   13691      4509244 :   else if (cand2->rewritten ())
   13692              :     return 1;
   13693              : 
   13694      4444969 :   if (deduction_guide_p (cand1->fn))
   13695              :     {
   13696         3244 :       gcc_assert (deduction_guide_p (cand2->fn));
   13697              : 
   13698              :       /* F1 and F2 are generated from class template argument deduction for a
   13699              :          class D, and F2 is generated from inheriting constructors from a base
   13700              :          class of D while F1 is not, and for each explicit function argument,
   13701              :          the corresponding parameters of F1 and F2 are either both ellipses or
   13702              :          have the same type.  */
   13703         3244 :       bool inherited1 = inherited_guide_p (cand1->fn);
   13704         3244 :       bool inherited2 = inherited_guide_p (cand2->fn);
   13705         3244 :       if (int diff = inherited2 - inherited1)
   13706              :         {
   13707           68 :           for (i = 0; i < len; ++i)
   13708              :             {
   13709           19 :               conversion *t1 = cand1->convs[i + off1];
   13710           19 :               conversion *t2 = cand2->convs[i + off2];
   13711              :               /* ??? It seems the ellipses part of this tiebreaker isn't
   13712              :                  needed since a mismatch should have broken the tie earlier
   13713              :                  during ICS comparison.  */
   13714           19 :               gcc_checking_assert (t1->ellipsis_p == t2->ellipsis_p);
   13715           19 :               if (!same_type_p (t1->type, t2->type))
   13716              :                 break;
   13717              :             }
   13718           51 :           if (i == len)
   13719              :             return diff;
   13720              :         }
   13721              : 
   13722              :       /* F1 is generated from a deduction-guide (13.3.1.8) and F2 is not */
   13723              :       /* We distinguish between candidates from an explicit deduction guide and
   13724              :          candidates built from a constructor based on DECL_ARTIFICIAL.  */
   13725         3195 :       int art1 = DECL_ARTIFICIAL (cand1->fn);
   13726         3195 :       int art2 = DECL_ARTIFICIAL (cand2->fn);
   13727         3195 :       if (art1 != art2)
   13728         1147 :         return art2 - art1;
   13729              : 
   13730         2048 :       if (art1)
   13731              :         {
   13732              :           /* Prefer the special copy guide over a declared copy/move
   13733              :              constructor.  */
   13734         2045 :           if (copy_guide_p (cand1->fn))
   13735              :             return 1;
   13736           83 :           if (copy_guide_p (cand2->fn))
   13737              :             return -1;
   13738              : 
   13739              :           /* Prefer a candidate generated from a non-template constructor.  */
   13740           28 :           int tg1 = template_guide_p (cand1->fn);
   13741           28 :           int tg2 = template_guide_p (cand2->fn);
   13742           28 :           if (tg1 != tg2)
   13743            6 :             return tg2 - tg1;
   13744              :         }
   13745              :     }
   13746              : 
   13747              :   /* F1 is a constructor for a class D, F2 is a constructor for a base class B
   13748              :      of D, and for all arguments the corresponding parameters of F1 and F2 have
   13749              :      the same type (CWG 2273/2277).  */
   13750     13325095 :   if (DECL_INHERITED_CTOR (cand1->fn) || DECL_INHERITED_CTOR (cand2->fn))
   13751              :     {
   13752           87 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (cand1->fn));
   13753           87 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (cand2->fn));
   13754              : 
   13755           87 :       bool used1 = false;
   13756           87 :       bool used2 = false;
   13757           87 :       if (base1 == base2)
   13758              :         /* No difference.  */;
   13759           87 :       else if (DERIVED_FROM_P (base1, base2))
   13760              :         used1 = true;
   13761           18 :       else if (DERIVED_FROM_P (base2, base1))
   13762              :         used2 = true;
   13763              : 
   13764           78 :       if (int diff = used2 - used1)
   13765              :         {
   13766          105 :           for (i = 0; i < len; ++i)
   13767              :             {
   13768           36 :               conversion *t1 = cand1->convs[i + off1];
   13769           36 :               conversion *t2 = cand2->convs[i + off2];
   13770           36 :               if (!same_type_p (t1->type, t2->type))
   13771              :                 break;
   13772              :             }
   13773           78 :           if (i == len)
   13774              :             return diff;
   13775              :         }
   13776              :     }
   13777              : 
   13778              :   /* Check whether we can discard a builtin candidate, either because we
   13779              :      have two identical ones or matching builtin and non-builtin candidates.
   13780              : 
   13781              :      (Pedantically in the latter case the builtin which matched the user
   13782              :      function should not be added to the overload set, but we spot it here.
   13783              : 
   13784              :      [over.match.oper]
   13785              :      ... the builtin candidates include ...
   13786              :      - do not have the same parameter type list as any non-template
   13787              :        non-member candidate.  */
   13788              : 
   13789      4441681 :   if (identifier_p (cand1->fn) || identifier_p (cand2->fn))
   13790              :     {
   13791           93 :       for (i = 0; i < len; ++i)
   13792           69 :         if (!same_type_p (cand1->convs[i]->type,
   13793              :                           cand2->convs[i]->type))
   13794              :           break;
   13795           43 :       if (i == cand1->num_convs)
   13796              :         {
   13797           24 :           if (cand1->fn == cand2->fn)
   13798              :             /* Two built-in candidates; arbitrarily pick one.  */
   13799              :             return 1;
   13800     16482649 :           else if (identifier_p (cand1->fn))
   13801              :             /* cand1 is built-in; prefer cand2.  */
   13802              :             return -1;
   13803              :           else
   13804              :             /* cand2 is built-in; prefer cand1.  */
   13805              :             return 1;
   13806              :         }
   13807              :     }
   13808              : 
   13809              :   /* For candidates of a multi-versioned function,  make the version with
   13810              :      the highest priority win.  This version will be checked for dispatching
   13811              :      first.  If this version can be inlined into the caller, the front-end
   13812              :      will simply make a direct call to this function.  */
   13813              : 
   13814      4441657 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13815      4441635 :       && DECL_FUNCTION_VERSIONED (cand1->fn)
   13816          938 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13817      4442595 :       && DECL_FUNCTION_VERSIONED (cand2->fn))
   13818              :     {
   13819          938 :       tree f1 = TREE_TYPE (cand1->fn);
   13820          938 :       tree f2 = TREE_TYPE (cand2->fn);
   13821          938 :       tree p1 = TYPE_ARG_TYPES (f1);
   13822          938 :       tree p2 = TYPE_ARG_TYPES (f2);
   13823              : 
   13824              :       /* Check if cand1->fn and cand2->fn are versions of the same function.  It
   13825              :          is possible that cand1->fn and cand2->fn are function versions but of
   13826              :          different functions.  Check types to see if they are versions of the same
   13827              :          function.  */
   13828          938 :       if (compparms (p1, p2)
   13829          938 :           && same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
   13830              :         {
   13831              :           /* Always make the version with the higher priority, more
   13832              :              specialized, win.  */
   13833          938 :           gcc_assert (targetm.compare_version_priority);
   13834          938 :           if (targetm.compare_version_priority (cand1->fn, cand2->fn) >= 0)
   13835              :             return 1;
   13836              :           else
   13837              :             return -1;
   13838              :         }
   13839              :     }
   13840              : 
   13841              :   /* If the two function declarations represent the same function (this can
   13842              :      happen with declarations in multiple scopes and arg-dependent lookup),
   13843              :      arbitrarily choose one.  But first make sure the default args we're
   13844              :      using match.  */
   13845      4440697 :   if (DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13846      8881416 :       && equal_functions (cand1->fn, cand2->fn))
   13847              :     {
   13848           35 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (cand1->fn));
   13849           35 :       tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (cand2->fn));
   13850              : 
   13851           70 :       gcc_assert (!DECL_CONSTRUCTOR_P (cand1->fn));
   13852              : 
   13853           50 :       for (i = 0; i < len; ++i)
   13854              :         {
   13855              :           /* Don't crash if the fn is variadic.  */
   13856           15 :           if (!parms1)
   13857              :             break;
   13858           15 :           parms1 = TREE_CHAIN (parms1);
   13859           15 :           parms2 = TREE_CHAIN (parms2);
   13860              :         }
   13861              : 
   13862           35 :       if (off1)
   13863            0 :         parms1 = TREE_CHAIN (parms1);
   13864           35 :       else if (off2)
   13865            0 :         parms2 = TREE_CHAIN (parms2);
   13866              : 
   13867           69 :       for (; parms1; ++i)
   13868              :         {
   13869           80 :           if (!cp_tree_equal (TREE_PURPOSE (parms1),
   13870           40 :                               TREE_PURPOSE (parms2)))
   13871              :             {
   13872            6 :               if (warn)
   13873              :                 {
   13874            3 :                   if (complain & tf_error)
   13875              :                     {
   13876            3 :                       auto_diagnostic_group d;
   13877            3 :                       if (permerror (input_location,
   13878              :                                      "default argument mismatch in "
   13879              :                                      "overload resolution"))
   13880              :                         {
   13881            3 :                           inform (DECL_SOURCE_LOCATION (cand1->fn),
   13882              :                                   " candidate 1: %q#F", cand1->fn);
   13883            3 :                           inform (DECL_SOURCE_LOCATION (cand2->fn),
   13884              :                                   " candidate 2: %q#F", cand2->fn);
   13885              :                         }
   13886            3 :                     }
   13887              :                   else
   13888              :                     return 0;
   13889              :                 }
   13890              :               else
   13891            3 :                 add_warning (cand1, cand2);
   13892              :               break;
   13893              :             }
   13894           34 :           parms1 = TREE_CHAIN (parms1);
   13895           34 :           parms2 = TREE_CHAIN (parms2);
   13896              :         }
   13897              : 
   13898           35 :       return 1;
   13899              :     }
   13900              : 
   13901      4441661 : tweak:
   13902              : 
   13903              :   /* Extension: If the worst conversion for one candidate is better than the
   13904              :      worst conversion for the other, take the first.  */
   13905      4441661 :   if (!pedantic && (complain & tf_warning_or_error))
   13906              :     {
   13907              :       conversion_rank rank1 = cr_identity, rank2 = cr_identity;
   13908      9388752 :       struct z_candidate *w = 0, *l = 0;
   13909              : 
   13910      9388752 :       for (i = 0; i < len; ++i)
   13911              :         {
   13912      5170739 :           if (CONVERSION_RANK (cand1->convs[i+off1]) > rank1)
   13913      4145081 :             rank1 = CONVERSION_RANK (cand1->convs[i+off1]);
   13914      5170739 :           if (CONVERSION_RANK (cand2->convs[i + off2]) > rank2)
   13915      4145098 :             rank2 = CONVERSION_RANK (cand2->convs[i + off2]);
   13916              :         }
   13917      4218013 :       if (rank1 < rank2)
   13918           56 :         winner = 1, w = cand1, l = cand2;
   13919      4218013 :       if (rank1 > rank2)
   13920              :         winner = -1, w = cand2, l = cand1;
   13921      4217905 :       if (winner)
   13922              :         {
   13923              :           /* Don't choose a deleted function over ambiguity.  */
   13924          164 :           if (DECL_P (w->fn) && DECL_DELETED_FN (w->fn))
   13925              :             return 0;
   13926          164 :           if (warn)
   13927              :             {
   13928            6 :               auto_diagnostic_group d;
   13929            6 :               if (pedwarn (input_location, 0,
   13930              :                            "ISO C++ says that these are ambiguous, even "
   13931              :                            "though the worst conversion for the first is "
   13932              :                            "better than the worst conversion for the second:"))
   13933              :                 {
   13934            3 :                   print_z_candidate (input_location, N_("candidate 1:"), w);
   13935            3 :                   print_z_candidate (input_location, N_("candidate 2:"), l);
   13936              :                 }
   13937            6 :             }
   13938              :           else
   13939          158 :             add_warning (w, l);
   13940          164 :           return winner;
   13941              :         }
   13942              :     }
   13943              : 
   13944              :   gcc_assert (!winner);
   13945              :   return 0;
   13946              : }
   13947              : 
   13948              : /* Given a list of candidates for overloading, find the best one, if any.
   13949              :    This algorithm has a worst case of O(2n) (winner is last), and a best
   13950              :    case of O(n/2) (totally ambiguous); much better than a sorting
   13951              :    algorithm.  The candidates list is assumed to be sorted according
   13952              :    to viability (via splice_viable).  */
   13953              : 
   13954              : static struct z_candidate *
   13955    225024573 : tourney (struct z_candidate *candidates, tsubst_flags_t complain)
   13956              : {
   13957    225024573 :   struct z_candidate **champ = &candidates, **challenger;
   13958    225024573 :   int fate;
   13959    225024573 :   struct z_candidate *previous_worse_champ = nullptr;
   13960              : 
   13961              :   /* Walk through the list once, comparing each current champ to the next
   13962              :      candidate, knocking out a candidate or two with each comparison.  */
   13963              : 
   13964    287600910 :   for (challenger = &candidates->next; *challenger && (*challenger)->viable; )
   13965              :     {
   13966     62586808 :       fate = joust (*champ, *challenger, 0, complain);
   13967     62586808 :       if (fate == 1)
   13968     40413350 :         challenger = &(*challenger)->next;
   13969     22173458 :       else if (fate == -1)
   13970              :         {
   13971     17733667 :           previous_worse_champ = *champ;
   13972     17733667 :           champ = challenger;
   13973     17733667 :           challenger = &(*challenger)->next;
   13974              :         }
   13975              :       else
   13976              :         {
   13977      4439791 :           previous_worse_champ = nullptr;
   13978      4439791 :           champ = &(*challenger)->next;
   13979      4439791 :           if (!*champ || !(*champ)->viable
   13980      4429414 :               || (*champ)->viable < (*challenger)->viable)
   13981              :             {
   13982              :               champ = nullptr;
   13983              :               break;
   13984              :             }
   13985      4429320 :           challenger = &(*champ)->next;
   13986              :         }
   13987              :     }
   13988              : 
   13989              :   /* Make sure the champ is better than all the candidates it hasn't yet
   13990              :      been compared to.  */
   13991              : 
   13992    225024573 :   if (champ)
   13993     26848034 :     for (challenger = &candidates;
   13994    251862136 :          challenger != champ;
   13995     26848034 :          challenger = &(*challenger)->next)
   13996              :       {
   13997     26849940 :         if (*challenger == previous_worse_champ)
   13998              :           /* We already know this candidate is worse than the champ.  */
   13999     16604309 :           continue;
   14000     10245631 :         fate = joust (*champ, *challenger, 0, complain);
   14001     10245631 :         if (fate != 1)
   14002              :           {
   14003              :             champ = nullptr;
   14004              :             break;
   14005              :           }
   14006              :       }
   14007              : 
   14008    225014102 :   if (!champ)
   14009        12377 :     return nullptr;
   14010              : 
   14011              :   /* Move the champ to the front of the candidate list.  */
   14012              : 
   14013    225012196 :   if (champ != &candidates)
   14014              :     {
   14015     18182775 :       z_candidate *saved_champ = *champ;
   14016     18182775 :       *champ = saved_champ->next;
   14017     18182775 :       saved_champ->next = candidates;
   14018     18182775 :       candidates = saved_champ;
   14019              :     }
   14020              : 
   14021    225012196 :   return candidates;
   14022              : }
   14023              : 
   14024              : /* Returns nonzero if things of type FROM can be converted to TO.  */
   14025              : 
   14026              : bool
   14027      4239150 : can_convert (tree to, tree from, tsubst_flags_t complain)
   14028              : {
   14029      4239150 :   tree arg = NULL_TREE;
   14030              :   /* implicit_conversion only considers user-defined conversions
   14031              :      if it has an expression for the call argument list.  */
   14032      4239150 :   if (CLASS_TYPE_P (from) || CLASS_TYPE_P (to))
   14033          109 :     arg = build_stub_object (from);
   14034      4239150 :   return can_convert_arg (to, from, arg, LOOKUP_IMPLICIT, complain);
   14035              : }
   14036              : 
   14037              : /* Returns nonzero if things of type FROM can be converted to TO with a
   14038              :    standard conversion.  */
   14039              : 
   14040              : bool
   14041          257 : can_convert_standard (tree to, tree from, tsubst_flags_t complain)
   14042              : {
   14043          257 :   return can_convert_arg (to, from, NULL_TREE, LOOKUP_IMPLICIT, complain);
   14044              : }
   14045              : 
   14046              : /* Returns nonzero if ARG (of type FROM) can be converted to TO.  */
   14047              : 
   14048              : bool
   14049      5138293 : can_convert_arg (tree to, tree from, tree arg, int flags,
   14050              :                  tsubst_flags_t complain)
   14051              : {
   14052      5138293 :   conversion *t;
   14053      5138293 :   bool ok_p;
   14054              : 
   14055      5138293 :   conversion_obstack_sentinel cos;
   14056              :   /* We want to discard any access checks done for this test,
   14057              :      as we might not be in the appropriate access context and
   14058              :      we'll do the check again when we actually perform the
   14059              :      conversion.  */
   14060      5138293 :   push_deferring_access_checks (dk_deferred);
   14061              : 
   14062              :   /* Handle callers like check_local_shadow forgetting to
   14063              :      convert_from_reference.  */
   14064      5138293 :   if (TYPE_REF_P (from) && arg)
   14065              :     {
   14066           55 :       arg = convert_from_reference (arg);
   14067           55 :       from = TREE_TYPE (arg);
   14068              :     }
   14069              : 
   14070      5138293 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   14071              :                             flags, complain);
   14072      5138293 :   ok_p = (t && !t->bad_p);
   14073              : 
   14074              :   /* Discard the access checks now.  */
   14075      5138293 :   pop_deferring_access_checks ();
   14076              : 
   14077     10276586 :   return ok_p;
   14078      5138293 : }
   14079              : 
   14080              : /* Like can_convert_arg, but allows dubious conversions as well.  */
   14081              : 
   14082              : bool
   14083    173506880 : can_convert_arg_bad (tree to, tree from, tree arg, int flags,
   14084              :                      tsubst_flags_t complain)
   14085              : {
   14086    173506880 :   conversion *t;
   14087              : 
   14088    173506880 :   conversion_obstack_sentinel cos;
   14089              :   /* Try to perform the conversion.  */
   14090    173506880 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   14091              :                             flags, complain);
   14092              : 
   14093    347013760 :   return t != NULL;
   14094    173506880 : }
   14095              : 
   14096              : /* Return an IMPLICIT_CONV_EXPR from EXPR to TYPE with bits set from overload
   14097              :    resolution FLAGS.  */
   14098              : 
   14099              : tree
   14100     13796081 : build_implicit_conv_flags (tree type, tree expr, int flags)
   14101              : {
   14102              :   /* In a template, we are only concerned about determining the
   14103              :      type of non-dependent expressions, so we do not have to
   14104              :      perform the actual conversion.  But for initializers, we
   14105              :      need to be able to perform it at instantiation
   14106              :      (or instantiate_non_dependent_expr) time.  */
   14107     13796081 :   expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14108     13796081 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   14109      6307924 :     IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14110     13796081 :   if (flags & LOOKUP_NO_NARROWING)
   14111        22228 :     IMPLICIT_CONV_EXPR_BRACED_INIT (expr) = true;
   14112     13796081 :   return expr;
   14113              : }
   14114              : 
   14115              : /* Convert EXPR to TYPE.  Return the converted expression.
   14116              : 
   14117              :    Note that we allow bad conversions here because by the time we get to
   14118              :    this point we are committed to doing the conversion.  If we end up
   14119              :    doing a bad conversion, convert_like will complain.  */
   14120              : 
   14121              : tree
   14122    281122051 : perform_implicit_conversion_flags (tree type, tree expr,
   14123              :                                    tsubst_flags_t complain, int flags)
   14124              : {
   14125    281122051 :   conversion *conv;
   14126    281122051 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14127              : 
   14128    281122051 :   if (error_operand_p (expr))
   14129          450 :     return error_mark_node;
   14130              : 
   14131    281121601 :   conversion_obstack_sentinel cos;
   14132              : 
   14133    281121601 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14134              :                               /*c_cast_p=*/false,
   14135              :                               flags, complain);
   14136              : 
   14137    281121601 :   if (!conv)
   14138              :     {
   14139       237650 :       if (complain & tf_error)
   14140          486 :         implicit_conversion_error (loc, type, expr, flags);
   14141       237650 :       expr = error_mark_node;
   14142              :     }
   14143    280883951 :   else if (processing_template_decl && conv->kind != ck_identity)
   14144     13796081 :     expr = build_implicit_conv_flags (type, expr, flags);
   14145              :   else
   14146              :     {
   14147              :       /* Give a conversion call the same location as expr.  */
   14148    267087870 :       iloc_sentinel il (loc);
   14149    267087870 :       expr = convert_like (conv, expr, complain);
   14150    267087870 :     }
   14151              : 
   14152    281121601 :   return expr;
   14153    281121601 : }
   14154              : 
   14155              : tree
   14156     12278537 : perform_implicit_conversion (tree type, tree expr, tsubst_flags_t complain)
   14157              : {
   14158     12278537 :   return perform_implicit_conversion_flags (type, expr, complain,
   14159     12278537 :                                             LOOKUP_IMPLICIT);
   14160              : }
   14161              : 
   14162              : /* Convert EXPR to TYPE (as a direct-initialization) if that is
   14163              :    permitted.  If the conversion is valid, the converted expression is
   14164              :    returned.  Otherwise, NULL_TREE is returned, except in the case
   14165              :    that TYPE is a class type; in that case, an error is issued.  If
   14166              :    C_CAST_P is true, then this direct-initialization is taking
   14167              :    place as part of a static_cast being attempted as part of a C-style
   14168              :    cast.  */
   14169              : 
   14170              : tree
   14171     46524770 : perform_direct_initialization_if_possible (tree type,
   14172              :                                            tree expr,
   14173              :                                            bool c_cast_p,
   14174              :                                            tsubst_flags_t complain)
   14175              : {
   14176     46524770 :   conversion *conv;
   14177              : 
   14178     46524770 :   if (type == error_mark_node || error_operand_p (expr))
   14179              :     return error_mark_node;
   14180              :   /* [dcl.init]
   14181              : 
   14182              :      If the destination type is a (possibly cv-qualified) class type:
   14183              : 
   14184              :      -- If the initialization is direct-initialization ...,
   14185              :      constructors are considered.
   14186              : 
   14187              :        -- If overload resolution is successful, the selected constructor
   14188              :        is called to initialize the object, with the initializer expression
   14189              :        or expression-list as its argument(s).
   14190              : 
   14191              :        -- Otherwise, if no constructor is viable, the destination type is
   14192              :        a (possibly cv-qualified) aggregate class A, and the initializer is
   14193              :        a parenthesized expression-list, the object is initialized as
   14194              :        follows...  */
   14195     46524770 :   if (CLASS_TYPE_P (type))
   14196              :     {
   14197      3015987 :       releasing_vec args (make_tree_vector_single (expr));
   14198      3015987 :       expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
   14199              :                                         &args, type, LOOKUP_NORMAL, complain);
   14200      3015987 :       return build_cplus_new (type, expr, complain);
   14201      3015987 :     }
   14202              : 
   14203     43508783 :   conversion_obstack_sentinel cos;
   14204              : 
   14205     43508783 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14206              :                               c_cast_p,
   14207              :                               LOOKUP_NORMAL, complain);
   14208     43508783 :   if (!conv || conv->bad_p)
   14209              :     expr = NULL_TREE;
   14210     38943986 :   else if (processing_template_decl && conv->kind != ck_identity)
   14211              :     {
   14212              :       /* In a template, we are only concerned about determining the
   14213              :          type of non-dependent expressions, so we do not have to
   14214              :          perform the actual conversion.  But for initializers, we
   14215              :          need to be able to perform it at instantiation
   14216              :          (or instantiate_non_dependent_expr) time.  */
   14217       668419 :       expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14218       668419 :       IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14219              :     }
   14220              :   else
   14221     38275567 :     expr = convert_like (conv, expr, NULL_TREE, 0,
   14222              :                          /*issue_conversion_warnings=*/false,
   14223              :                          c_cast_p, /*nested_p=*/false, complain);
   14224              : 
   14225     43508783 :   return expr;
   14226     43508783 : }
   14227              : 
   14228              : /* When initializing a reference that lasts longer than a full-expression,
   14229              :    this special rule applies:
   14230              : 
   14231              :      [class.temporary]
   14232              : 
   14233              :      The temporary to which the reference is bound or the temporary
   14234              :      that is the complete object to which the reference is bound
   14235              :      persists for the lifetime of the reference.
   14236              : 
   14237              :      The temporaries created during the evaluation of the expression
   14238              :      initializing the reference, except the temporary to which the
   14239              :      reference is bound, are destroyed at the end of the
   14240              :      full-expression in which they are created.
   14241              : 
   14242              :    In that case, we store the converted expression into a new
   14243              :    VAR_DECL in a new scope.
   14244              : 
   14245              :    However, we want to be careful not to create temporaries when
   14246              :    they are not required.  For example, given:
   14247              : 
   14248              :      struct B {};
   14249              :      struct D : public B {};
   14250              :      D f();
   14251              :      const B& b = f();
   14252              : 
   14253              :    there is no need to copy the return value from "f"; we can just
   14254              :    extend its lifetime.  Similarly, given:
   14255              : 
   14256              :      struct S {};
   14257              :      struct T { operator S(); };
   14258              :      T t;
   14259              :      const S& s = t;
   14260              : 
   14261              :   we can extend the lifetime of the return value of the conversion
   14262              :   operator.
   14263              : 
   14264              :   The next several functions are involved in this lifetime extension.  */
   14265              : 
   14266              : /* DECL is a VAR_DECL or FIELD_DECL whose type is a REFERENCE_TYPE.  The
   14267              :    reference is being bound to a temporary.  Create and return a new
   14268              :    VAR_DECL with the indicated TYPE; this variable will store the value to
   14269              :    which the reference is bound.  */
   14270              : 
   14271              : tree
   14272         7774 : make_temporary_var_for_ref_to_temp (tree decl, tree type)
   14273              : {
   14274         7774 :   tree var = create_temporary_var (type);
   14275              : 
   14276              :   /* Register the variable.  */
   14277         7774 :   if (VAR_P (decl)
   14278         7774 :       && (TREE_STATIC (decl) || CP_DECL_THREAD_LOCAL_P (decl)))
   14279              :     {
   14280              :       /* Namespace-scope or local static; give it a mangled name.  */
   14281              : 
   14282              :       /* If an initializer is visible to multiple translation units, those
   14283              :          translation units must agree on the addresses of the
   14284              :          temporaries. Therefore the temporaries must be given a consistent name
   14285              :          and vague linkage. The mangled name of a temporary is the name of the
   14286              :          non-temporary object in whose initializer they appear, prefixed with
   14287              :          GR and suffixed with a sequence number mangled using the usual rules
   14288              :          for a seq-id. Temporaries are numbered with a pre-order, depth-first,
   14289              :          left-to-right walk of the complete initializer.  */
   14290          812 :       copy_linkage (var, decl);
   14291              : 
   14292          812 :       tree name = mangle_ref_init_variable (decl);
   14293          812 :       DECL_NAME (var) = name;
   14294          812 :       SET_DECL_ASSEMBLER_NAME (var, name);
   14295              : 
   14296              :       /* Set the context to make the variable mergeable in modules.  */
   14297          812 :       DECL_CONTEXT (var) = current_scope ();
   14298              :     }
   14299              :   else
   14300              :     /* Create a new cleanup level if necessary.  */
   14301         6962 :     maybe_push_cleanup_level (type);
   14302              : 
   14303         7774 :   return pushdecl (var);
   14304              : }
   14305              : 
   14306              : static tree extend_temps_r (tree *, int *, void *);
   14307              : 
   14308              : /* EXPR is the initializer for a variable DECL of reference or
   14309              :    std::initializer_list type.  Create, push and return a new VAR_DECL
   14310              :    for the initializer so that it will live as long as DECL.  Any
   14311              :    cleanup for the new variable is returned through CLEANUP, and the
   14312              :    code to initialize the new variable is returned through INITP.  */
   14313              : 
   14314              : static tree
   14315         7774 : set_up_extended_ref_temp (tree decl, tree expr, vec<tree, va_gc> **cleanups,
   14316              :                           tree *initp, tree *cond_guard,
   14317              :                           void *walk_data)
   14318              : {
   14319         7774 :   tree init;
   14320         7774 :   tree type;
   14321         7774 :   tree var;
   14322              : 
   14323              :   /* Create the temporary variable.  */
   14324         7774 :   type = TREE_TYPE (expr);
   14325         7774 :   var = make_temporary_var_for_ref_to_temp (decl, type);
   14326         7774 :   layout_decl (var, 0);
   14327              :   /* If the rvalue is the result of a function call it will be
   14328              :      a TARGET_EXPR.  If it is some other construct (such as a
   14329              :      member access expression where the underlying object is
   14330              :      itself the result of a function call), turn it into a
   14331              :      TARGET_EXPR here.  It is important that EXPR be a
   14332              :      TARGET_EXPR below since otherwise the INIT_EXPR will
   14333              :      attempt to make a bitwise copy of EXPR to initialize
   14334              :      VAR.  */
   14335         7774 :   if (TREE_CODE (expr) != TARGET_EXPR)
   14336            0 :     expr = get_target_expr (expr);
   14337              :   else
   14338              :     {
   14339         7774 :       if (TREE_ADDRESSABLE (expr))
   14340         7691 :         TREE_ADDRESSABLE (var) = 1;
   14341         7774 :       if (DECL_MERGEABLE (TARGET_EXPR_SLOT (expr)))
   14342          551 :         DECL_MERGEABLE (var) = true;
   14343              :     }
   14344              : 
   14345         7774 :   if (TREE_CODE (decl) == FIELD_DECL
   14346         7774 :       && extra_warnings && !warning_suppressed_p (decl))
   14347              :     {
   14348            3 :       warning (OPT_Wextra, "a temporary bound to %qD only persists "
   14349              :                "until the constructor exits", decl);
   14350            3 :       suppress_warning (decl);
   14351              :     }
   14352              : 
   14353              :   /* Recursively extend temps in this initializer.  The recursion needs to come
   14354              :      after creating the variable to conform to the mangling ABI, and before
   14355              :      maybe_constant_init because the extension might change its result.  */
   14356         7774 :   if (walk_data)
   14357         1509 :     cp_walk_tree (&TARGET_EXPR_INITIAL (expr), extend_temps_r,
   14358              :                   walk_data, nullptr);
   14359              :   else
   14360         6265 :     TARGET_EXPR_INITIAL (expr)
   14361        12530 :       = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups,
   14362              :                                cond_guard);
   14363              : 
   14364              :   /* Any reference temp has a non-trivial initializer.  */
   14365         7774 :   DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
   14366              : 
   14367              :   /* If the initializer is constant, put it in DECL_INITIAL so we get
   14368              :      static initialization and use in constant expressions.  */
   14369         7774 :   init = maybe_constant_init (expr, var, /*manifestly_const_eval=*/true);
   14370              :   /* As in store_init_value.  */
   14371         7774 :   init = cp_fully_fold (init);
   14372         7774 :   if (TREE_CONSTANT (init))
   14373              :     {
   14374         1186 :       if (literal_type_p (type)
   14375         1160 :           && CP_TYPE_CONST_NON_VOLATILE_P (type)
   14376         1860 :           && !TYPE_HAS_MUTABLE_P (type))
   14377              :         {
   14378              :           /* 5.19 says that a constant expression can include an
   14379              :              lvalue-rvalue conversion applied to "a glvalue of literal type
   14380              :              that refers to a non-volatile temporary object initialized
   14381              :              with a constant expression".  Rather than try to communicate
   14382              :              that this VAR_DECL is a temporary, just mark it constexpr.  */
   14383          671 :           DECL_DECLARED_CONSTEXPR_P (var) = true;
   14384          671 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = true;
   14385          671 :           TREE_CONSTANT (var) = true;
   14386          671 :           TREE_READONLY (var) = true;
   14387              :         }
   14388         1186 :       DECL_INITIAL (var) = init;
   14389         1186 :       init = NULL_TREE;
   14390              :     }
   14391              :   else
   14392              :     /* Create the INIT_EXPR that will initialize the temporary
   14393              :        variable.  */
   14394         6588 :     init = split_nonconstant_init (var, expr);
   14395         7774 :   if (at_function_scope_p ())
   14396              :     {
   14397         7052 :       add_decl_expr (var);
   14398              : 
   14399         7052 :       if (TREE_STATIC (var))
   14400           90 :         init = add_stmt_to_compound (init, register_dtor_fn (var));
   14401              :       else
   14402              :         {
   14403              :           /* ??? Instead of rebuilding the cleanup, we could replace the slot
   14404              :              with var in TARGET_EXPR_CLEANUP (expr).  */
   14405         6962 :           tree cleanup = cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14406         6962 :           if (cleanup)
   14407              :             {
   14408         2879 :               if (cond_guard && cleanup != error_mark_node)
   14409              :                 {
   14410           23 :                   if (*cond_guard == NULL_TREE)
   14411              :                     {
   14412           23 :                       *cond_guard = build_local_temp (boolean_type_node);
   14413           23 :                       add_decl_expr (*cond_guard);
   14414           23 :                       tree set = cp_build_modify_expr (UNKNOWN_LOCATION,
   14415              :                                                        *cond_guard, NOP_EXPR,
   14416              :                                                        boolean_false_node,
   14417              :                                                        tf_warning_or_error);
   14418           23 :                       finish_expr_stmt (set);
   14419              :                     }
   14420           23 :                   cleanup = build3 (COND_EXPR, void_type_node,
   14421              :                                     *cond_guard, cleanup, NULL_TREE);
   14422              :                 }
   14423         2879 :               if (flag_exceptions && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE)
   14424              :                 {
   14425              :                   /* The normal cleanup for this extended variable isn't pushed
   14426              :                      until cp_finish_decl, so we need to retain a TARGET_EXPR
   14427              :                      to clean it up in case a later initializer throws
   14428              :                      (g++.dg/eh/ref-temp3.C).
   14429              : 
   14430              :                      We don't do this for array temporaries because they have
   14431              :                      the array cleanup region from build_vec_init.
   14432              : 
   14433              :                      Unlike maybe_push_temp_cleanup, we don't actually need a
   14434              :                      flag, but a TARGET_EXPR needs a TARGET_EXPR_SLOT.
   14435              :                      Perhaps this could use WITH_CLEANUP_EXPR instead, but
   14436              :                      gimplify.cc doesn't handle that, and front-end handling
   14437              :                      was removed in r8-1725 and r8-1818.
   14438              : 
   14439              :                      Alternately it might be preferable to flatten an
   14440              :                      initialization with extended temps into a sequence of
   14441              :                      (non-full-expression) statements, so we could immediately
   14442              :                      push_cleanup here for only a single cleanup region, but we
   14443              :                      don't have a mechanism for that in the front-end, only the
   14444              :                      gimplifier.  */
   14445         2771 :                   tree targ = get_internal_target_expr (boolean_true_node);
   14446         2771 :                   TARGET_EXPR_CLEANUP (targ) = cleanup;
   14447         2771 :                   CLEANUP_EH_ONLY (targ) = true;
   14448              :                   /* Don't actually initialize the bool.  */
   14449         2771 :                   init = (!init ? void_node
   14450         2745 :                           : convert_to_void (init, ICV_STATEMENT, tf_none));
   14451         2771 :                   TARGET_EXPR_INITIAL (targ) = init;
   14452         2771 :                   init = targ;
   14453              :                 }
   14454         2879 :               vec_safe_push (*cleanups, cleanup);
   14455              :             }
   14456              :         }
   14457              : 
   14458              :       /* We must be careful to destroy the temporary only
   14459              :          after its initialization has taken place.  If the
   14460              :          initialization throws an exception, then the
   14461              :          destructor should not be run.  We cannot simply
   14462              :          transform INIT into something like:
   14463              : 
   14464              :          (INIT, ({ CLEANUP_STMT; }))
   14465              : 
   14466              :          because emit_local_var always treats the
   14467              :          initializer as a full-expression.  Thus, the
   14468              :          destructor would run too early; it would run at the
   14469              :          end of initializing the reference variable, rather
   14470              :          than at the end of the block enclosing the
   14471              :          reference variable.
   14472              : 
   14473              :          The solution is to pass back a cleanup expression
   14474              :          which the caller is responsible for attaching to
   14475              :          the statement tree.  */
   14476              :     }
   14477              :   else
   14478              :     {
   14479              :       /* Don't output reflection variables.  */
   14480          722 :       if (consteval_only_p (var))
   14481            2 :         DECL_EXTERNAL (var) = true;
   14482              : 
   14483          722 :       rest_of_decl_compilation (var, /*toplev=*/1, at_eof);
   14484          722 :       if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
   14485              :         {
   14486           40 :           if (CP_DECL_THREAD_LOCAL_P (var))
   14487           12 :             tls_aggregates = tree_cons (NULL_TREE, var,
   14488              :                                         tls_aggregates);
   14489              :           else
   14490           28 :             static_aggregates = tree_cons (NULL_TREE, var,
   14491              :                                            static_aggregates);
   14492              :         }
   14493              :       else
   14494              :         /* Check whether the dtor is callable.  */
   14495          682 :         cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14496              :     }
   14497              :   /* Avoid -Wunused-variable warning (c++/38958).  */
   14498         7774 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   14499         7774 :       && VAR_P (decl))
   14500         2850 :     TREE_USED (decl) = DECL_READ_P (decl) = true;
   14501              : 
   14502         7774 :   *initp = init;
   14503         7774 :   return var;
   14504              : }
   14505              : 
   14506              : /* Convert EXPR to the indicated reference TYPE, in a way suitable for
   14507              :    initializing a variable of that TYPE.  */
   14508              : 
   14509              : tree
   14510      6071648 : initialize_reference (tree type, tree expr,
   14511              :                       int flags, tsubst_flags_t complain)
   14512              : {
   14513      6071648 :   conversion *conv;
   14514      6071648 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14515              : 
   14516      6071648 :   if (type == error_mark_node || error_operand_p (expr))
   14517              :     return error_mark_node;
   14518              : 
   14519      6071574 :   conversion_obstack_sentinel cos;
   14520              : 
   14521      6071574 :   conv = reference_binding (type, TREE_TYPE (expr), expr, /*c_cast_p=*/false,
   14522              :                             flags, complain);
   14523              :   /* If this conversion failed, we're in C++20, and we have something like
   14524              :      A& a(b) where A is an aggregate, try again, this time as A& a{b}.  */
   14525      6071574 :   if ((!conv || conv->bad_p)
   14526          702 :       && (flags & LOOKUP_AGGREGATE_PAREN_INIT))
   14527              :     {
   14528            4 :       tree e = build_constructor_single (init_list_type_node, NULL_TREE, expr);
   14529            4 :       CONSTRUCTOR_IS_DIRECT_INIT (e) = true;
   14530            4 :       CONSTRUCTOR_IS_PAREN_INIT (e) = true;
   14531            4 :       conversion *c = reference_binding (type, TREE_TYPE (e), e,
   14532              :                                          /*c_cast_p=*/false, flags, complain);
   14533              :       /* If this worked, use it.  */
   14534            4 :       if (c && !c->bad_p)
   14535              :         expr = e, conv = c;
   14536              :     }
   14537      6072189 :   if (!conv || conv->bad_p)
   14538              :     {
   14539          699 :       if (complain & tf_error)
   14540              :         {
   14541          366 :           if (conv)
   14542          313 :             convert_like (conv, expr, complain);
   14543           53 :           else if (!CP_TYPE_CONST_P (TREE_TYPE (type))
   14544           21 :                    && !TYPE_REF_IS_RVALUE (type)
   14545           74 :                    && !lvalue_p (expr))
   14546            6 :             error_at (loc, "invalid initialization of non-const reference of "
   14547              :                       "type %qH from an rvalue of type %qI",
   14548            6 :                       type, TREE_TYPE (expr));
   14549              :           else
   14550           47 :             error_at (loc, "invalid initialization of reference of type "
   14551              :                       "%qH from expression of type %qI", type,
   14552           47 :                       TREE_TYPE (expr));
   14553              :         }
   14554          699 :       return error_mark_node;
   14555              :     }
   14556              : 
   14557      6070875 :   if (conv->kind == ck_ref_bind)
   14558              :     /* Perform the conversion.  */
   14559      6070872 :     expr = convert_like (conv, expr, complain);
   14560            3 :   else if (conv->kind == ck_ambig)
   14561              :     /* We gave an error in build_user_type_conversion_1.  */
   14562            3 :     expr = error_mark_node;
   14563              :   else
   14564            0 :     gcc_unreachable ();
   14565              : 
   14566              :   return expr;
   14567      6071574 : }
   14568              : 
   14569              : /* Return true if T is std::pair<const T&, const T&>.  */
   14570              : 
   14571              : static bool
   14572       614724 : std_pair_ref_ref_p (tree t)
   14573              : {
   14574              :   /* First, check if we have std::pair.  */
   14575        57375 :   if (!NON_UNION_CLASS_TYPE_P (t)
   14576       671639 :       || !CLASSTYPE_TEMPLATE_INSTANTIATION (t))
   14577              :     return false;
   14578        20695 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (t));
   14579        20695 :   if (!decl_in_std_namespace_p (tdecl))
   14580              :     return false;
   14581        15506 :   tree name = DECL_NAME (tdecl);
   14582        15506 :   if (!name || !id_equal (name, "pair"))
   14583              :     return false;
   14584              : 
   14585              :   /* Now see if the template arguments are both const T&.  */
   14586          363 :   tree args = CLASSTYPE_TI_ARGS (t);
   14587          363 :   if (TREE_VEC_LENGTH (args) != 2)
   14588              :     return false;
   14589          423 :   for (int i = 0; i < 2; i++)
   14590          453 :     if (!TYPE_REF_OBJ_P (TREE_VEC_ELT (args, i))
   14591          453 :         || !CP_TYPE_CONST_P (TREE_TYPE (TREE_VEC_ELT (args, i))))
   14592          333 :       return false;
   14593              : 
   14594              :   return true;
   14595              : }
   14596              : 
   14597              : /* Return true if a class T has a reference member.  */
   14598              : 
   14599              : static bool
   14600          216 : class_has_reference_member_p (tree t)
   14601              : {
   14602          216 :   for (tree fields = TYPE_FIELDS (t);
   14603         3380 :        fields;
   14604         3164 :        fields = DECL_CHAIN (fields))
   14605         3227 :     if (TREE_CODE (fields) == FIELD_DECL
   14606          196 :         && !DECL_ARTIFICIAL (fields)
   14607         3394 :         && TYPE_REF_P (TREE_TYPE (fields)))
   14608              :       return true;
   14609              :   return false;
   14610              : }
   14611              : 
   14612              : /* A wrapper for the above suitable as a callback for dfs_walk_once.  */
   14613              : 
   14614              : static tree
   14615          216 : class_has_reference_member_p_r (tree binfo, void *)
   14616              : {
   14617          216 :   return (class_has_reference_member_p (BINFO_TYPE (binfo))
   14618          216 :           ? integer_one_node : NULL_TREE);
   14619              : }
   14620              : 
   14621              : 
   14622              : /* Return true if T (either a class or a function) has been marked as
   14623              :    not-dangling.  */
   14624              : 
   14625              : static bool
   14626         1557 : no_dangling_p (tree t)
   14627              : {
   14628         1557 :   t = lookup_attribute ("no_dangling", TYPE_ATTRIBUTES (t));
   14629         1557 :   if (!t)
   14630              :     return false;
   14631              : 
   14632           75 :   t = TREE_VALUE (t);
   14633           75 :   if (!t)
   14634              :     return true;
   14635              : 
   14636           51 :   t = build_converted_constant_bool_expr (TREE_VALUE (t), tf_warning_or_error);
   14637           51 :   t = cxx_constant_value (t);
   14638           51 :   return t == boolean_true_node;
   14639              : }
   14640              : 
   14641              : /* Return true if a class CTYPE is either std::reference_wrapper or
   14642              :    std::ref_view, or a reference wrapper class.  We consider a class
   14643              :    a reference wrapper class if it has a reference member.  We no
   14644              :    longer check that it has a constructor taking the same reference type
   14645              :    since that approach still generated too many false positives.  */
   14646              : 
   14647              : static bool
   14648          447 : reference_like_class_p (tree ctype)
   14649              : {
   14650          447 :   if (!CLASS_TYPE_P (ctype))
   14651              :     return false;
   14652              : 
   14653          314 :   if (no_dangling_p (ctype))
   14654              :     return true;
   14655              : 
   14656              :   /* Also accept a std::pair<const T&, const T&>.  */
   14657          290 :   if (std_pair_ref_ref_p (ctype))
   14658              :     return true;
   14659              : 
   14660          275 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (ctype));
   14661          275 :   if (decl_in_std_namespace_p (tdecl))
   14662              :     {
   14663           38 :       tree name = DECL_NAME (tdecl);
   14664           38 :       if (name
   14665           38 :           && (id_equal (name, "reference_wrapper")
   14666           26 :               || id_equal (name, "span")
   14667           11 :               || id_equal (name, "ref_view")))
   14668              :         return true;
   14669              :     }
   14670              : 
   14671              :   /* Avoid warning if CTYPE looks like std::span: it has a T* member and
   14672              :      a trivial destructor.  For example,
   14673              : 
   14674              :       template<typename T>
   14675              :       struct Span {
   14676              :         T* data_;
   14677              :         std::size len_;
   14678              :       };
   14679              : 
   14680              :      is considered std::span-like.  */
   14681          248 :   if (NON_UNION_CLASS_TYPE_P (ctype) && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
   14682          228 :     for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
   14683          367 :          field; field = next_aggregate_field (DECL_CHAIN (field)))
   14684          199 :       if (TYPE_PTR_P (TREE_TYPE (field)))
   14685              :         return true;
   14686              : 
   14687              :   /* Some classes, such as std::tuple, have the reference member in its
   14688              :      (non-direct) base class.  */
   14689          188 :   if (dfs_walk_once (TYPE_BINFO (ctype), class_has_reference_member_p_r,
   14690              :                      nullptr, nullptr))
   14691              :     return true;
   14692              : 
   14693              :   return false;
   14694              : }
   14695              : 
   14696              : /* Helper for maybe_warn_dangling_reference to find a problematic temporary
   14697              :    in EXPR (as outlined in maybe_warn_dangling_reference), or NULL_TREE
   14698              :    if none found.  For instance:
   14699              : 
   14700              :      const S& s = S().self(); // S()
   14701              :      const int& r = (42, f(1)); // temporary for passing 1 to f
   14702              :      const int& t = b ? f(1) : f(2); // temporary for 1
   14703              :      const int& u = b ? f(1) : f(g); // temporary for 1
   14704              :      const int& v = b ? f(g) : f(2); // temporary for 2
   14705              :      const int& w = b ? f(g) : f(g); // NULL_TREE
   14706              :      const int& y = (f(1), 42); // NULL_TREE
   14707              :      const int& z = f(f(1)); // temporary for 1
   14708              : 
   14709              :    EXPR is the initializer.  If ARG_P is true, we're processing an argument
   14710              :    to a function; the point is to distinguish between, for example,
   14711              : 
   14712              :      Ref::inner (&TARGET_EXPR <D.2839, F::foo (fm)>)
   14713              : 
   14714              :    where we shouldn't warn, and
   14715              : 
   14716              :      Ref::inner (&TARGET_EXPR <D.2908, F::foo (&TARGET_EXPR <...>)>)
   14717              : 
   14718              :    where we should warn (Ref is a reference_like_class_p so we see through
   14719              :    it.  */
   14720              : 
   14721              : static tree
   14722         3875 : do_warn_dangling_reference (tree expr, bool arg_p)
   14723              : {
   14724         3875 :   STRIP_NOPS (expr);
   14725              : 
   14726         3875 :   if (arg_p && expr_represents_temporary_p (expr))
   14727              :     {
   14728              :       /* An attempt to reduce the number of -Wdangling-reference
   14729              :          false positives concerning reference wrappers (c++/107532).
   14730              :          When we encounter a reference_like_class_p, we don't warn
   14731              :          just yet; instead, we keep recursing to see if there were
   14732              :          any temporaries behind the reference-wrapper class.  */
   14733              :       tree e = expr;
   14734          355 :       while (handled_component_p (e))
   14735           15 :         e = TREE_OPERAND (e, 0);
   14736          340 :       tree type = TREE_TYPE (e);
   14737              :       /* If the temporary represents a lambda, we don't really know
   14738              :          what's going on here.  */
   14739          462 :       if (!reference_like_class_p (type) && !LAMBDA_TYPE_P (type))
   14740              :         return expr;
   14741              :     }
   14742              : 
   14743         3642 :   switch (TREE_CODE (expr))
   14744              :     {
   14745         1820 :     case CALL_EXPR:
   14746         1820 :       {
   14747         1820 :         tree fndecl = cp_get_callee_fndecl_nofold (expr);
   14748         1820 :         if (!fndecl
   14749         1820 :             || warning_suppressed_p (fndecl, OPT_Wdangling_reference)
   14750         1809 :             || !warning_enabled_at (DECL_SOURCE_LOCATION (fndecl),
   14751         1809 :                                     OPT_Wdangling_reference)
   14752              :             /* Don't emit a false positive for:
   14753              :                 std::vector<int> v = ...;
   14754              :                 std::vector<int>::const_iterator it = v.begin();
   14755              :                 const int &r = *it++;
   14756              :                because R refers to one of the int elements of V, not to
   14757              :                a temporary object.  Member operator* may return a reference
   14758              :                but probably not to one of its arguments.  */
   14759         1450 :             || (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   14760          850 :                 && DECL_OVERLOADED_OPERATOR_P (fndecl)
   14761          317 :                 && DECL_OVERLOADED_OPERATOR_IS (fndecl, INDIRECT_REF))
   14762         3063 :             || no_dangling_p (TREE_TYPE (fndecl)))
   14763          601 :           return NULL_TREE;
   14764              : 
   14765         1219 :         tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
   14766              :         /* If the function doesn't return a reference, don't warn.  This
   14767              :            can be e.g.
   14768              :              const int& z = std::min({1, 2, 3, 4, 5, 6, 7});
   14769              :            which doesn't dangle: std::min here returns an int.
   14770              : 
   14771              :            If the function returns a std::pair<const T&, const T&>, we
   14772              :            warn, to detect e.g.
   14773              :              std::pair<const int&, const int&> v = std::minmax(1, 2);
   14774              :            which also creates a dangling reference, because std::minmax
   14775              :            returns std::pair<const T&, const T&>(b, a).  */
   14776         1219 :         if (!(TYPE_REF_OBJ_P (rettype) || reference_like_class_p (rettype)))
   14777              :           return NULL_TREE;
   14778              : 
   14779              :         /* Here we're looking to see if any of the arguments is a temporary
   14780              :            initializing a reference parameter.  */
   14781         1647 :         for (int i = 0; i < call_expr_nargs (expr); ++i)
   14782              :           {
   14783         1240 :             tree arg = CALL_EXPR_ARG (expr, i);
   14784              :             /* Check that this argument initializes a reference, except for
   14785              :                the argument initializing the object of a member function.  */
   14786         1240 :             if (!DECL_IOBJ_MEMBER_FUNCTION_P (fndecl)
   14787         1240 :                 && !TYPE_REF_P (TREE_TYPE (arg)))
   14788          130 :               continue;
   14789         1110 :             STRIP_NOPS (arg);
   14790         1110 :             if (TREE_CODE (arg) == ADDR_EXPR)
   14791          725 :               arg = TREE_OPERAND (arg, 0);
   14792              :             /* Recurse to see if the argument is a temporary.  It could also
   14793              :                be another call taking a temporary and returning it and
   14794              :                initializing this reference parameter.  */
   14795         1110 :             if ((arg = do_warn_dangling_reference (arg, /*arg_p=*/true)))
   14796              :               {
   14797              :                 /* If we know the temporary could not bind to the return type,
   14798              :                    don't warn.  This is for scalars and empty classes only
   14799              :                    because for other classes we can't be sure we are not
   14800              :                    returning its sub-object.  */
   14801          278 :                 if ((SCALAR_TYPE_P (TREE_TYPE (arg))
   14802          152 :                      || is_empty_class (TREE_TYPE (arg)))
   14803          153 :                     && TYPE_REF_P (rettype)
   14804          138 :                     && !reference_related_p (TREE_TYPE (rettype),
   14805          138 :                                              TREE_TYPE (arg)))
   14806           21 :                   continue;
   14807          257 :                 return arg;
   14808              :               }
   14809              :           /* Don't warn about member functions like:
   14810              :               std::any a(...);
   14811              :               S& s = a.emplace<S>({0}, 0);
   14812              :              which construct a new object and return a reference to it, but
   14813              :              we still want to detect:
   14814              :                struct S { const S& self () { return *this; } };
   14815              :                const S& s = S().self();
   14816              :              where 's' dangles.  If we've gotten here, the object this function
   14817              :              is invoked on is not a temporary.  */
   14818          832 :             if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl))
   14819              :               break;
   14820              :           }
   14821              :         return NULL_TREE;
   14822              :       }
   14823           28 :     case COMPOUND_EXPR:
   14824           28 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 1), arg_p);
   14825           31 :     case COND_EXPR:
   14826           31 :       if (tree t = do_warn_dangling_reference (TREE_OPERAND (expr, 1), arg_p))
   14827              :         return t;
   14828           16 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 2), arg_p);
   14829            0 :     case PAREN_EXPR:
   14830            0 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 0), arg_p);
   14831          122 :     case TARGET_EXPR:
   14832          122 :       return do_warn_dangling_reference (TARGET_EXPR_INITIAL (expr), arg_p);
   14833              :     default:
   14834              :       return NULL_TREE;
   14835              :     }
   14836              : }
   14837              : 
   14838              : /* Implement -Wdangling-reference, to detect cases like
   14839              : 
   14840              :      int n = 1;
   14841              :      const int& r = std::max(n - 1, n + 1); // r is dangling
   14842              : 
   14843              :    This creates temporaries from the arguments, returns a reference to
   14844              :    one of the temporaries, but both temporaries are destroyed at the end
   14845              :    of the full expression.
   14846              : 
   14847              :    This works by checking if a reference is initialized with a function
   14848              :    that returns a reference, and at least one parameter of the function
   14849              :    is a reference that is bound to a temporary.  It assumes that such a
   14850              :    function actually returns one of its arguments.
   14851              : 
   14852              :    DECL is the reference being initialized, INIT is the initializer.  */
   14853              : 
   14854              : static void
   14855    102824443 : maybe_warn_dangling_reference (const_tree decl, tree init)
   14856              : {
   14857    102824443 :   if (!warn_dangling_reference)
   14858              :     return;
   14859       616987 :   tree type = TREE_TYPE (decl);
   14860              :   /* Only warn if what we're initializing has type T&& or const T&, or
   14861              :      std::pair<const T&, const T&>.  (A non-const lvalue reference can't
   14862              :      bind to a temporary.)  */
   14863      1231421 :   if (!((TYPE_REF_OBJ_P (type)
   14864         5428 :          && (TYPE_REF_IS_RVALUE (type)
   14865         4992 :              || CP_TYPE_CONST_P (TREE_TYPE (type))))
   14866       614434 :         || std_pair_ref_ref_p (type)))
   14867              :     return;
   14868              :   /* Don't suppress the diagnostic just because the call comes from
   14869              :      a system header.  If the DECL is not in a system header, or if
   14870              :      -Wsystem-headers was provided, warn.  */
   14871         2568 :   auto wsh
   14872         2568 :     = make_temp_override (global_dc->m_warn_system_headers,
   14873         2568 :                           (!in_system_header_at (DECL_SOURCE_LOCATION (decl))
   14874         2568 :                            || global_dc->m_warn_system_headers));
   14875         2568 :   if (tree call = do_warn_dangling_reference (init, /*arg_p=*/false))
   14876              :     {
   14877          212 :       auto_diagnostic_group d;
   14878          212 :       if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wdangling_reference,
   14879              :                       "possibly dangling reference to a temporary"))
   14880          212 :         inform (EXPR_LOCATION (call), "%qT temporary created here",
   14881          212 :                 TREE_TYPE (call));
   14882          212 :     }
   14883         2568 : }
   14884              : 
   14885              : /* If *P is an xvalue expression, prevent temporary lifetime extension if it
   14886              :    gets used to initialize a reference.  */
   14887              : 
   14888              : static tree
   14889           95 : prevent_lifetime_extension (tree t)
   14890              : {
   14891           95 :   tree *p = &t;
   14892           95 :   while (TREE_CODE (*p) == COMPOUND_EXPR)
   14893            0 :     p = &TREE_OPERAND (*p, 1);
   14894          104 :   while (handled_component_p (*p))
   14895            9 :     p = &TREE_OPERAND (*p, 0);
   14896              :   /* Change a TARGET_EXPR from prvalue to xvalue.  */
   14897           95 :   if (TREE_CODE (*p) == TARGET_EXPR)
   14898            3 :     *p = build2 (COMPOUND_EXPR, TREE_TYPE (*p), *p,
   14899            3 :                  move (TARGET_EXPR_SLOT (*p)));
   14900           95 :   return t;
   14901              : }
   14902              : 
   14903              : /* Subroutine of extend_ref_init_temps.  Possibly extend one initializer,
   14904              :    which is bound either to a reference or a std::initializer_list.  */
   14905              : 
   14906              : static tree
   14907       663375 : extend_ref_init_temps_1 (tree decl, tree init, vec<tree, va_gc> **cleanups,
   14908              :                          tree *cond_guard)
   14909              : {
   14910              :   /* CWG1299 (C++20): The temporary object to which the reference is bound or
   14911              :      the temporary object that is the complete object of a subobject to which
   14912              :      the reference is bound persists for the lifetime of the reference if the
   14913              :      glvalue to which the reference is bound was obtained through one of the
   14914              :      following:
   14915              :      - a temporary materialization conversion ([conv.rval]),
   14916              :      - ( expression ), where expression is one of these expressions,
   14917              :      - subscripting ([expr.sub]) of an array operand, where that operand is one
   14918              :        of these expressions,
   14919              :      - a class member access ([expr.ref]) using the . operator where the left
   14920              :        operand is one of these expressions and the right operand designates a
   14921              :        non-static data member of non-reference type,
   14922              :      - a pointer-to-member operation ([expr.mptr.oper]) using the .* operator
   14923              :        where the left operand is one of these expressions and the right operand
   14924              :        is a pointer to data member of non-reference type,
   14925              :      - a const_cast ([expr.const.cast]), static_cast ([expr.static.cast]),
   14926              :        dynamic_cast ([expr.dynamic.cast]), or reinterpret_cast
   14927              :        ([expr.reinterpret.cast]) converting, without a user-defined conversion,
   14928              :        a glvalue operand that is one of these expressions to a glvalue that
   14929              :        refers to the object designated by the operand, or to its complete
   14930              :        object or a subobject thereof,
   14931              :      - a conditional expression ([expr.cond]) that is a glvalue where the
   14932              :        second or third operand is one of these expressions, or
   14933              :      - a comma expression ([expr.comma]) that is a glvalue where the right
   14934              :        operand is one of these expressions.  */
   14935              : 
   14936              :   /* FIXME several cases are still handled wrong (101572, 81420).  */
   14937              : 
   14938       663375 :   tree sub = init;
   14939       663375 :   tree *p;
   14940       663375 :   STRIP_NOPS (sub);
   14941       663375 :   if (TREE_CODE (sub) == COMPOUND_EXPR)
   14942              :     {
   14943          242 :       TREE_OPERAND (sub, 1)
   14944          242 :         = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   14945              :                                    cond_guard);
   14946          242 :       return init;
   14947              :     }
   14948       663133 :   if (TREE_CODE (sub) == POINTER_PLUS_EXPR
   14949       663133 :       && TYPE_PTRDATAMEM_P (TREE_TYPE (tree_strip_nop_conversions
   14950              :                                        (TREE_OPERAND (sub, 1)))))
   14951              :     {
   14952              :       /* A pointer-to-member operation.  */
   14953            6 :       TREE_OPERAND (sub, 0)
   14954            6 :         = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 0), cleanups,
   14955              :                                    cond_guard);
   14956            6 :       return init;
   14957              :     }
   14958       663127 :   if (TREE_CODE (sub) == COND_EXPR)
   14959              :     {
   14960        21977 :       tree cur_cond_guard = NULL_TREE;
   14961        21977 :       if (TREE_OPERAND (sub, 1))
   14962        21977 :         TREE_OPERAND (sub, 1)
   14963        43954 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   14964              :                                      &cur_cond_guard);
   14965        21977 :       if (cur_cond_guard)
   14966              :         {
   14967            9 :           tree set = cp_build_modify_expr (UNKNOWN_LOCATION, cur_cond_guard,
   14968              :                                            NOP_EXPR, boolean_true_node,
   14969              :                                            tf_warning_or_error);
   14970            9 :           TREE_OPERAND (sub, 1)
   14971           18 :             = cp_build_compound_expr (set, TREE_OPERAND (sub, 1),
   14972              :                                       tf_warning_or_error);
   14973              :         }
   14974        21977 :       cur_cond_guard = NULL_TREE;
   14975        21977 :       if (TREE_OPERAND (sub, 2))
   14976        21977 :         TREE_OPERAND (sub, 2)
   14977        43954 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 2), cleanups,
   14978              :                                      &cur_cond_guard);
   14979        21977 :       if (cur_cond_guard)
   14980              :         {
   14981           12 :           tree set = cp_build_modify_expr (UNKNOWN_LOCATION, cur_cond_guard,
   14982              :                                            NOP_EXPR, boolean_true_node,
   14983              :                                            tf_warning_or_error);
   14984           12 :           TREE_OPERAND (sub, 2)
   14985           24 :             = cp_build_compound_expr (set, TREE_OPERAND (sub, 2),
   14986              :                                       tf_warning_or_error);
   14987              :         }
   14988        21977 :       return init;
   14989              :     }
   14990       641150 :   if (TREE_CODE (sub) != ADDR_EXPR)
   14991              :     return init;
   14992              :   /* Deal with binding to a subobject.  */
   14993       198295 :   for (p = &TREE_OPERAND (sub, 0);
   14994       211497 :        TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   14995        13202 :     p = &TREE_OPERAND (*p, 0);
   14996       198295 :   if (TREE_CODE (*p) == TARGET_EXPR)
   14997              :     {
   14998         6265 :       tree subinit = NULL_TREE;
   14999         6265 :       *p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit,
   15000              :                                      cond_guard, nullptr);
   15001         6265 :       recompute_tree_invariant_for_addr_expr (sub);
   15002         6265 :       if (init != sub)
   15003         6247 :         init = fold_convert (TREE_TYPE (init), sub);
   15004         6265 :       if (subinit)
   15005         5217 :         init = build2 (COMPOUND_EXPR, TREE_TYPE (init), subinit, init);
   15006              :     }
   15007              :   return init;
   15008              : }
   15009              : 
   15010              : /* Data for extend_temps_r, mostly matching the parameters of
   15011              :    extend_ref_init_temps.  */
   15012              : 
   15013              : struct extend_temps_data
   15014              : {
   15015              :   tree decl;
   15016              :   tree init;
   15017              :   vec<tree, va_gc> **cleanups;
   15018              :   tree* cond_guard;
   15019              :   hash_set<tree> *pset;            // For avoiding redundant walk_tree.
   15020              :   hash_map<tree, tree> *var_map; // For remapping extended temps.
   15021              : };
   15022              : 
   15023              : /* Tree walk function for extend_all_temps.  Generally parallel to
   15024              :    extend_ref_init_temps_1, but adapted for walk_tree.  */
   15025              : 
   15026              : tree
   15027        72478 : extend_temps_r (tree *tp, int *walk_subtrees, void *data)
   15028              : {
   15029        72478 :   extend_temps_data *d = (extend_temps_data *)data;
   15030              : 
   15031        72478 :   if (TREE_CODE (*tp) == VAR_DECL)
   15032              :     {
   15033         9252 :       if (tree *r = d->var_map->get (*tp))
   15034            0 :         *tp = *r;
   15035         9252 :       return NULL_TREE;
   15036              :     }
   15037              : 
   15038        63207 :   if (TYPE_P (*tp) || TREE_CODE (*tp) == CLEANUP_POINT_EXPR
   15039       126432 :       || d->pset->add (*tp))
   15040              :     {
   15041         3660 :       *walk_subtrees = 0;
   15042         3660 :       return NULL_TREE;
   15043              :     }
   15044              : 
   15045        59566 :   if (TREE_CODE (*tp) == COND_EXPR)
   15046              :     {
   15047            8 :       cp_walk_tree (&TREE_OPERAND (*tp, 0), extend_temps_r, d, nullptr);
   15048              : 
   15049           24 :       auto walk_arm = [d](tree &op)
   15050              :       {
   15051           16 :         tree cur_cond_guard = NULL_TREE;
   15052           16 :         auto ov = make_temp_override (d->cond_guard, &cur_cond_guard);
   15053           16 :         cp_walk_tree (&op, extend_temps_r, d, nullptr);
   15054           16 :         if (cur_cond_guard)
   15055              :           {
   15056            2 :             tree set = build2 (MODIFY_EXPR, boolean_type_node,
   15057              :                                cur_cond_guard, boolean_true_node);
   15058            2 :             op = cp_build_compound_expr (set, op, tf_none);
   15059              :           }
   15060           24 :       };
   15061            8 :       walk_arm (TREE_OPERAND (*tp, 1));
   15062            8 :       walk_arm (TREE_OPERAND (*tp, 2));
   15063              : 
   15064            8 :       *walk_subtrees = 0;
   15065            8 :       return NULL_TREE;
   15066              :     }
   15067              : 
   15068        59558 :   tree *p = tp;
   15069              : 
   15070        59558 :   if (TREE_CODE (*tp) == ADDR_EXPR)
   15071        13588 :     for (p = &TREE_OPERAND (*tp, 0);
   15072        14757 :          TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   15073         1169 :       p = &TREE_OPERAND (*p, 0);
   15074              : 
   15075        59558 :   if (TREE_CODE (*p) == TARGET_EXPR
   15076              :       /* An eliding TARGET_EXPR isn't a temporary at all.  */
   15077         2443 :       && !TARGET_EXPR_ELIDING_P (*p)
   15078              :       /* A TARGET_EXPR with TARGET_EXPR_INTERNAL_P is an artificial variable
   15079              :          used during initialization that need not be extended.  */
   15080        61399 :       && !TARGET_EXPR_INTERNAL_P (*p))
   15081              :     {
   15082              :       /* A CLEANUP_EH_ONLY expr should also have TARGET_EXPR_INTERNAL_P.  */
   15083         1509 :       gcc_checking_assert (!CLEANUP_EH_ONLY (*p));
   15084              : 
   15085         1509 :       tree subinit = NULL_TREE;
   15086         1509 :       tree slot = TARGET_EXPR_SLOT (*p);
   15087         1509 :       *p = set_up_extended_ref_temp (d->decl, *p, d->cleanups, &subinit,
   15088              :                                      d->cond_guard, d);
   15089         1509 :       if (TREE_CODE (*tp) == ADDR_EXPR)
   15090         1495 :         recompute_tree_invariant_for_addr_expr (*tp);
   15091         1509 :       if (subinit)
   15092         1397 :         *tp = cp_build_compound_expr (subinit, *tp, tf_none);
   15093         1509 :       d->var_map->put (slot, *p);
   15094              :     }
   15095              : 
   15096              :   return NULL_TREE;
   15097              : }
   15098              : 
   15099              : /* Extend all the temporaries in a for-range-initializer.  */
   15100              : 
   15101              : static tree
   15102        14574 : extend_all_temps (tree decl, tree init, vec<tree, va_gc> **cleanups)
   15103              : {
   15104        14574 :   hash_set<tree> pset;
   15105        14574 :   hash_map<tree, tree> map;
   15106        14574 :   gcc_assert (!TREE_STATIC (decl));
   15107        14574 :   extend_temps_data d = { decl, init, cleanups, nullptr, &pset, &map };
   15108        14574 :   cp_walk_tree (&init, extend_temps_r, &d, nullptr);
   15109        14574 :   return init;
   15110        14574 : }
   15111              : 
   15112              : /* INIT is part of the initializer for DECL.  If there are any
   15113              :    reference or initializer lists being initialized, extend their
   15114              :    lifetime to match that of DECL.  */
   15115              : 
   15116              : tree
   15117    105150757 : extend_ref_init_temps (tree decl, tree init, vec<tree, va_gc> **cleanups,
   15118              :                        tree *cond_guard)
   15119              : {
   15120    105150757 :   tree type = TREE_TYPE (init);
   15121    105150757 :   if (processing_template_decl)
   15122              :     return init;
   15123              : 
   15124              :   /* P2718R0 - in C++23 for-range-initializer, extend all temps.  */
   15125    102839017 :   if (DECL_NAME (decl) == for_range__identifier
   15126        88327 :       && flag_range_for_ext_temps
   15127              :       /* Iterating expansion statement decl is static right now, but that
   15128              :          could change depending on CWG3044 and CWG3043.  */
   15129    102853647 :       && !TREE_STATIC (decl))
   15130              :     {
   15131        14574 :       gcc_checking_assert (!cond_guard);
   15132        14574 :       return extend_all_temps (decl, init, cleanups);
   15133              :     }
   15134              : 
   15135    102824443 :   maybe_warn_dangling_reference (decl, init);
   15136              : 
   15137    102824443 :   if (TYPE_REF_P (type))
   15138       618578 :     init = extend_ref_init_temps_1 (decl, init, cleanups, cond_guard);
   15139              :   else
   15140              :     {
   15141    102205865 :       tree ctor = init;
   15142    102205865 :       if (TREE_CODE (ctor) == TARGET_EXPR)
   15143      1406970 :         ctor = TARGET_EXPR_INITIAL (ctor);
   15144    102205865 :       if (TREE_CODE (ctor) == CONSTRUCTOR)
   15145              :         {
   15146              :           /* [dcl.init] When initializing an aggregate from a parenthesized list
   15147              :              of values... a temporary object bound to a reference does not have
   15148              :              its lifetime extended.  */
   15149      5116664 :           if (CONSTRUCTOR_IS_PAREN_INIT (ctor))
   15150              :             return init;
   15151              : 
   15152      5116281 :           if (is_std_init_list (type))
   15153              :             {
   15154              :               /* The temporary array underlying a std::initializer_list
   15155              :                  is handled like a reference temporary.  */
   15156          595 :               tree array = CONSTRUCTOR_ELT (ctor, 0)->value;
   15157          595 :               array = extend_ref_init_temps_1 (decl, array, cleanups,
   15158              :                                                cond_guard);
   15159          595 :               CONSTRUCTOR_ELT (ctor, 0)->value = array;
   15160              :             }
   15161              :           else
   15162              :             {
   15163      5115686 :               unsigned i;
   15164      5115686 :               constructor_elt *p;
   15165      5115686 :               vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (ctor);
   15166     59311187 :               FOR_EACH_VEC_SAFE_ELT (elts, i, p)
   15167     54195501 :                 p->value = extend_ref_init_temps (decl, p->value, cleanups,
   15168              :                                                   cond_guard);
   15169              :             }
   15170      5116281 :           recompute_constructor_flags (ctor);
   15171      5116281 :           if (decl_maybe_constant_var_p (decl) && TREE_CONSTANT (ctor))
   15172      2798599 :             DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
   15173              :         }
   15174              :     }
   15175              : 
   15176              :   return init;
   15177              : }
   15178              : 
   15179              : /* Returns true iff an initializer for TYPE could contain temporaries that
   15180              :    need to be extended because they are bound to references or
   15181              :    std::initializer_list.  */
   15182              : 
   15183              : bool
   15184            0 : type_has_extended_temps (tree type)
   15185              : {
   15186            0 :   type = strip_array_types (type);
   15187            0 :   if (TYPE_REF_P (type))
   15188              :     return true;
   15189            0 :   if (CLASS_TYPE_P (type))
   15190              :     {
   15191            0 :       if (is_std_init_list (type))
   15192              :         return true;
   15193            0 :       for (tree f = next_aggregate_field (TYPE_FIELDS (type));
   15194            0 :            f; f = next_aggregate_field (DECL_CHAIN (f)))
   15195            0 :         if (type_has_extended_temps (TREE_TYPE (f)))
   15196              :           return true;
   15197              :     }
   15198              :   return false;
   15199              : }
   15200              : 
   15201              : /* Returns true iff TYPE is some variant of std::initializer_list.  */
   15202              : 
   15203              : bool
   15204    172472500 : is_std_init_list (tree type)
   15205              : {
   15206    172472500 :   if (!TYPE_P (type))
   15207              :     return false;
   15208    172472477 :   if (cxx_dialect == cxx98)
   15209              :     return false;
   15210              :   /* Look through typedefs.  */
   15211    172111109 :   type = TYPE_MAIN_VARIANT (type);
   15212    137867937 :   return (CLASS_TYPE_P (type)
   15213    137728670 :           && CP_TYPE_CONTEXT (type) == std_node
   15214    249208358 :           && init_list_identifier == DECL_NAME (TYPE_NAME (type)));
   15215              : }
   15216              : 
   15217              : /* Returns true iff DECL is a list constructor: i.e. a constructor which
   15218              :    will accept an argument list of a single std::initializer_list<T>.  */
   15219              : 
   15220              : bool
   15221    150123028 : is_list_ctor (tree decl)
   15222              : {
   15223    150123028 :   tree args = FUNCTION_FIRST_USER_PARMTYPE (decl);
   15224    150123028 :   tree arg;
   15225              : 
   15226    150123028 :   if (!args || args == void_list_node)
   15227              :     return false;
   15228              : 
   15229    120854892 :   arg = non_reference (TREE_VALUE (args));
   15230    120854892 :   if (!is_std_init_list (arg))
   15231              :     return false;
   15232              : 
   15233      2191644 :   args = TREE_CHAIN (args);
   15234              : 
   15235      3733887 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   15236              :     /* There are more non-defaulted parms.  */
   15237              :     return false;
   15238              : 
   15239              :   return true;
   15240              : }
   15241              : 
   15242              : /* We know that can_convert_arg_bad already said "no" when trying to convert
   15243              :    FROM to TO with ARG and FLAGS.  Try to figure out if it was because
   15244              :    an explicit conversion function was skipped when looking for a way to
   15245              :    perform the conversion.  At this point we've already printed an error.  */
   15246              : 
   15247              : void
   15248         2122 : maybe_show_nonconverting_candidate (tree to, tree from, tree arg, int flags)
   15249              : {
   15250         2122 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   15251          293 :     return;
   15252              : 
   15253         1829 :   conversion_obstack_sentinel cos;
   15254         1829 :   conversion *c = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   15255              :                                        flags & ~LOOKUP_ONLYCONVERTING, tf_none);
   15256         1829 :   if (c && !c->bad_p && c->user_conv_p)
   15257              :     /* Ay, the conversion would have worked in direct-init context.  */
   15258          859 :     for (; c; c = next_conversion (c))
   15259          575 :       if (c->kind == ck_user
   15260          281 :           && DECL_P (c->cand->fn)
   15261          856 :           && DECL_NONCONVERTING_P (c->cand->fn))
   15262          277 :         inform (DECL_SOURCE_LOCATION (c->cand->fn), "explicit conversion "
   15263              :                 "function was not considered");
   15264         1829 : }
   15265              : 
   15266              : /* We're converting EXPR to TYPE.  If that conversion involves a conversion
   15267              :    function and we're binding EXPR to a reference parameter of that function,
   15268              :    return true.  */
   15269              : 
   15270              : bool
   15271          171 : conv_binds_to_reference_parm_p (tree type, tree expr)
   15272              : {
   15273          171 :   conversion_obstack_sentinel cos;
   15274          171 :   conversion *c = implicit_conversion (type, TREE_TYPE (expr), expr,
   15275              :                                        /*c_cast_p=*/false, LOOKUP_NORMAL,
   15276              :                                        tf_none);
   15277          171 :   if (c && !c->bad_p && c->user_conv_p)
   15278          117 :     for (; c; c = next_conversion (c))
   15279           81 :       if (c->kind == ck_user)
   15280          244 :         for (z_candidate *cand = c->cand; cand; cand = cand->next)
   15281          208 :           if (cand->viable == 1)
   15282           81 :             for (size_t i = 0; i < cand->num_convs; ++i)
   15283           45 :               if (cand->convs[i]->kind == ck_ref_bind
   15284           45 :                   && conv_get_original_expr (cand->convs[i]) == expr)
   15285              :                 return true;
   15286              : 
   15287              :   return false;
   15288          171 : }
   15289              : 
   15290              : #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.